Hello, I'm having trouble to figure out how I can test this, I have a UserFundsController, one of the actions is addPayment which is for charging the user's funds account (User has one UserFunds model related $user->funds). After some validation I call the function addCharge which is defined in the UserFunds model, this function among other things, performs the subtraction from the user's balance account, in the end this returns false if charge didn't happen, true otherwise.
Here is the code to explain better:
$updated = $user->funds->addCharge($request->input('amount'));
if (!$updated) {
return reponse()->json([
'error' => 'aborted_charge',
'message' => 'Payment transaction could not be completed.',
], 403);
}
These lines are the only red lines in my coverage for that controller, so to test them I thought I could mock addCharge to simply return false so then I test response equality and coverage will be green, the only problem is that I can't mock it!, I've tried many combinations and search online without any success.
So the question is, how to properly mock that function?, or how would you test this?
Thanks guys!