I am trying to test my service with Mockery
. I have bound the route param {user}
to my service:
$repo = 'Services\\UserService';
$router->bind('user', function($id, $route) use($repo) {
return $this->app->make($repo)->get($id);
});
When I run my first test it succeeds.
$mocked = Mockery::mock('UserService');
\App::instance('UserService', $mocked);
$mocked->shouldReceive('create')
->once()
->andReturn($user);
When my next test runs it fails
$mocked = Mockery::mock('UserService');
\App::instance('UserService', $mocked);
$mocked->shouldReceive('update')
->once()
->andReturn('1');
Dumping out in the router->bind
method
dump(get_class($this->app->make($repo));
I get Services\UserService
the first time but the second time I get Mockery_0_Services_UserService
and then this error:
testing.ERROR: exception 'BadMethodCallException' with message
'Method Mockery_0_Services_UserService::get() does not exist on this mock object
I would assume that it has something to do with the App::instance
method but I am not sure.
What could be the issue here?