ZendTest\Stratigility\MiddlewarePipeTest::testHandleInvokesFirstErrorHandlerOnErrorInChain PHP Method

testHandleInvokesFirstErrorHandlerOnErrorInChain() public method

    public function testHandleInvokesFirstErrorHandlerOnErrorInChain()
    {
        $this->middleware->pipe(function ($req, $res, $next) {
            $next($req, $res->write("First\n"));
        });
        $this->middleware->pipe(function ($req, $res, $next) {
            return $next($req, $res, 'error');
        });
        $this->middleware->pipe(function ($req, $res, $next) {
            return $res->write("Third\n");
        });
        $this->middleware->pipe(function ($err, $req, $res, $next) {
            return $res->write("ERROR HANDLER\n");
        });
        $phpunit = $this;
        $this->middleware->pipe(function ($req, $res, $next) use($phpunit) {
            $phpunit->fail('Should not hit fourth handler!');
        });
        set_error_handler(function ($errno, $errstr) {
            // no-op; skip handling
            return true;
        }, E_USER_DEPRECATED);
        $request = new Request([], [], 'http://local.example.com/foo', 'GET', 'php://memory');
        $response = $this->middleware->__invoke($request, $this->response);
        restore_error_handler();
        $body = (string) $response->getBody();
        $this->assertContains('First', $body);
        $this->assertContains('ERROR HANDLER', $body);
        $this->assertNotContains('Third', $body);
    }
MiddlewarePipeTest