On the BitExpert blog Stephan Hochdörfer shows you how to mock callables in a Zend Expressive application based on a way he found during his own unit testing.
While working with Zend Expressive, a PSR-7 middleware microframework, I wanted to apply some unit testing with a nice coverage to my middlewares. Middlewares are called by the __invoke method if you provide them as an object and not as a closure. [...] Additionally, my middleware implementation does some stuff, but the middleware itself does not return a response, which is fine. Instead, my implementation calls the $next middleware in line.
He finishes the post with a quick example of how to mock out this $next
call in his testing using the createPartialMock
functionality in PHPUnit. He uses this method to create a mock that covers the __invoke
method and returns a ResponseInterface
instance of his choosing.