Skip to content

Commit 4eab297

Browse files
committed
Test for PHP 7 Throwable in ApiProblemListener.
1 parent 346d702 commit 4eab297

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/Listener/ApiProblemListenerTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,28 @@ public function testOnDispatchErrorReturnsAnApiProblemResponseBasedOnCurrentEven
5252
$this->assertEquals(400, $problem->status);
5353
$this->assertSame($event->getParam('exception'), $problem->detail);
5454
}
55+
56+
/**
57+
* @requires PHP 7.0
58+
*/
59+
public function testOnDispatchErrorReturnsAnApiProblemResponseBasedOnCurrentEventThrowable()
60+
{
61+
$request = new Request();
62+
$request->getHeaders()->addHeaderLine('Accept', 'application/json');
63+
64+
$event = new MvcEvent();
65+
$event->setError(Application::ERROR_EXCEPTION);
66+
$event->setParam('exception', new \TypeError('triggering throwable', 400));
67+
$event->setRequest($request);
68+
$return = $this->listener->onDispatchError($event);
69+
70+
$this->assertTrue($event->propagationIsStopped());
71+
$this->assertInstanceOf('ZF\ApiProblem\ApiProblemResponse', $return);
72+
$response = $event->getResponse();
73+
$this->assertSame($return, $response);
74+
$problem = $response->getApiProblem();
75+
$this->assertInstanceOf('ZF\ApiProblem\ApiProblem', $problem);
76+
$this->assertEquals(400, $problem->status);
77+
$this->assertSame($event->getParam('exception'), $problem->detail);
78+
}
5579
}

0 commit comments

Comments
 (0)