jeudi 8 juin 2017

Mock a service provider - Laravel 5.4

I am using a service provider in a specific controller, i registered the provider and resolved it successfully.

But the test i used to run by mocking the actual classes are not working any more.

I resolve the service in my controller using app():

$cart = app()->make('Cart');

This is how i used to mock it before switching to a service provider:

$this->cart = $this->createMock(Cart::class);

Now if i want to mock it, i am doing something like this:

$this->createMock(app()->make('Cart'));

And the test fails with the error:

PHPUnit_Framework_MockObject_Generator::getMock() must be a array or string

Any Suggestion ?

Aucun commentaire:

Enregistrer un commentaire