I have the following controller class in my Lumen application that implements the route controller:
<?php
class MyController {
public function route_method(Request $request) {
// some code
$success = $this->private_method($request->get('get_variable'));
// some code
return \response()->json(['results' => $success]);
}
private function private_method($data) {
// some code, calling 3rd party service
return $some_value;
}
}
And the following corresponding route in Lumen application web.php
:
<?php
$app->get('/endpoint', ['uses' => 'MyController@route_method']);
Now I want to write the unit test that confirms the returned response for call /endpoint
returns an expected JSON response that contains the key/value pair of 'results': true
, but without letting route_method()
call private_method()
by mocking the latter, because - as in the comment - the private_method()
calls a 3rd party service and I want to avoid that, so I think I need something like this:
<?php
class RouteTest extends TestCase {
public function testRouteReturnsExpectedJsonResponse() {
// need to mock the private_method here somehow first, then...
$this->json('GET', '/endpoint', ['get_variable' => 'get_value'])->seeJson(['results' => true]);
}
}
But how do I make use of Mockery
for this purpose, or is there another way to isolate the 3rd party call?