Error when mocking interfaces in PHP using Mockery Error when mocking interfaces in PHP using Mockery laravel laravel

Error when mocking interfaces in PHP using Mockery


You should call mock() method at the and of mock declaration.

$mock = Mockery::mock('MyNamespace\SomeSubFolder\MyInterface');$mock->shouldReceive('method1')     ->andReturn('foo')     ->mock();


I think the problem is with PHP class loading. Your 'MyNamespace\SomeSubFolder\MyInterface' class isn't available from your test file.

You'll need to modify your composer.json to autoload that namespace or you'll need a require_once('path/to/file/containing/namespace/MyInterface.php') at the top of your test.

Although, when you did try the interface_exists it seemed to pass. It could also be that you misspelled your namespaced class when you mocked it. I've made that mistake as well.

In any case, Mockery isn't able to see that the class exists so it's just inventing one.

Can you provide your full test source?