Search code examples
laravelphpunitmockery

Laravel Mockery Integration Test


I am a little lost on how to perform integration test using mockery.

I have the following classes: TeacherController TeacherManager - Interface TeacherManagerImpl - Implementation

When it comes to mockery / PHPUnit, how do I call a method from my interface? It says that the interface can not be instantiated. I know it can't but how can I inject it into the test class or should I just do new on the implementation. Doing a new on the implementation just does not seem right to me.


Solution

  • Thanks to Kindari in the Laravel IRC chat room In the Test setup method just bind the interface to the implementation and then set a private member variable using App::make. See below.

    App::bind('FooInterface', 'FooImplementation'); 
    $foo = App::make('FooInterface');
    

    also app() is a shortcut to App::make