#898·mockery

Mocking invokable classes

Author: downsiderCreated Jul 10, 2018Updated Oct 9, 2023

I'm currently working with a codebase that uses the __invoke magic method extensively and this is proving difficult to test.

The invokable classes are injected into services (and type hinted), and Mockery doesn't seem to allow mocking of the __invoke method, so I am unable to inject a closure/callable or to intercept the method call when the object is invoked.

Is there an existing solution to this problem that I haven't been able to find? If not, would it be possible to add functionality similar to akamon/mockery-callable-mock. I'm thinking along the lines of $mock->shouldBeInvoked()->once()->with("foo")->andReturn("bar")