Closed danizord closed 6 years ago
Verified. I had to make a few changes to your proposed test case, as prepareMiddleware()
is a method of Application
, not the test case; it is, in fact, private (requiring reflection); and it has two more required arguments. Final test case looks like this:
public function testPreparingArrayWithPairOfObjectAndStringMiddlewaresShouldNotBeTreatedAsCallable()
{
$first = $this->prophesize(MiddlewareInterface::class)->reveal();
$second = TestAsset\CallableInteropMiddleware::class;
$queue = [$first, $second];
$router = $this->router->reveal();
$response = $this->prophesize(ResponseInterface::class)->reveal();
$app = $this->getApp();
$r = new ReflectionMethod($app, 'prepareMiddleware');
$r->setAccessible(true);
$middleware = $r->invoke($app, $queue, $router, $response);
$this->assertInstanceOf(MiddlewarePipe::class, $middleware);
$r = new ReflectionProperty($middleware, 'pipeline');
$r->setAccessible(true);
$this->assertCount(2, $r->getValue($middleware));
}
That fails, indicating that a method by the name of Double\MiddlewareInterface\P213::ZendTest\Expressive\TestAsset\CallableInteropMiddleware()
does not exist.
When writing tests for #525, I've realised that Expressive is failing when piping two middlewares like that:
Since
is_callable()
returnstrue
for[$object, 'string']
, Expressive is trying to handle it as a callable interop middleware, then it breaks at https://github.com/zendframework/zend-expressive/blob/2.0.5/src/IsCallableInteropMiddlewareTrait.php#L46-L48.Here's the failing testcase: