I want getNumber to return 200 in the test case, but when I run the test and inspect the result with $response->dump() I can see that the mock is not overriding the method as it is showing array:1 [0 => 100]. What am I missing? Controller: Model: Test: I am using Laravel 8 and referencing this documentation: https://laravel.com/docs/8.x/mocking#mocking-objects Answer In
Tag: mockery
How to mock Eloquent Model in Laravel 8 when calling a route in PHPUnit
I’m trying to mock a method in the Model so that I am able to test the controller api endpoint with different scenarios. I am currently using Laravel 8 with PhpUnit and Mockery package. In the route I am using Route model binding. api.php ProjectController.php ProjectControllerTest.php I am currently getting this error I have tried other options like makePartial() instead,
Carbon object in mockery php test
Thank you for your time. I have stripped out the fluff from the code/test. The furthest I have got with this is that setAttribute requires two strings as paramĀ“s, but i am passing in an Carbon object, which Mockery as a test suite does not like? Is this the case, is there a better way to test dates with Mockery/PHPUnit?
How to mock properly IlluminateHttpRequest class from Laravel
I’m trying to test a method from a class which contains a method using the request() helper from Laravel. This is the method: Category class The test should make this helper to catch properly the URI when doing getRequestUri() but it’s actually returning an empty string. This is one of the thousand tries that I gave to the test. Test
Mocking the response only for a certain parameter
I have a class where I am mocking the get method when called with test1 to return 123. This works fine. However, I want to have all other calls to the get method return what would normally be …
Mockery: how does a passive partial mock differ from the default mock?
In the very last paragraphs of this (great) quick reference to Mockery, the author explains some behaviour modifiers for a mock which are not default, but may be useful. These include the makePartial() call and the shouldDeferMissing() call. How do these differ from the default behaviour? When you create a mock (Mockery::mock(‘myClass’)), and don’t add any method expectations, all method
Mockery no matching handler for closure
I can’t figure out why I’m getting this error during this test. My test appears to be matching the rest of the code exactly. What am I overlooking? In my test I have: $passwordBroker = m::mock(…