public function testIntercept() { $request = $this->prophesizeServerRequest()->reveal(); $response = $this->prophesizeResponse()->reveal(); $response2 = $this->prophesizeResponse()->reveal(); $stack = new MiddlewareStack(); $interceptor = function (ServerRequestInterface $req, ResponseInterface $res, callable $next) use($response2) { return $response2; }; $failMiddleware = function () { $this->fail('this middleware should not be runned'); }; $stack->append($interceptor); $stack->append($failMiddleware); $returnValue = call_user_func($stack, $request, $response, $failMiddleware); $this->assertSame($response2, $returnValue); }
/** * append $middleware after this one, return the new $middlewareStack * * @param $middleware * @return MiddlewareStack */ public function append($middleware) { $stack = new MiddlewareStack(); return $stack->append($this)->append($middleware); }