Skip to content

Commit

Permalink
zendframework#37 - Covering Throwable catching logic - PHP 7 except…
Browse files Browse the repository at this point in the history
…ions should also be caught
  • Loading branch information
Ocramius committed Mar 7, 2016
1 parent a54d9af commit 9f06282
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions test/DispatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@

class DispatchTest extends TestCase
{
/**
* @var \Zend\Stratigility\Http\Request|\PHPUnit_Framework_MockObject_MockObject
*/
private $request;

/**
* @var \Zend\Stratigility\Http\Response|\PHPUnit_Framework_MockObject_MockObject
*/
private $response;

public function setUp()
{
$this->request = $this->getMockBuilder('Zend\Stratigility\Http\Request')
Expand Down Expand Up @@ -199,4 +209,47 @@ public function testShouldAllowDispatchingPsr7Instances()
$result = $dispatch($route, $err, $request->reveal(), $response->reveal(), $next);
$this->assertSame($response->reveal(), $result);
}

/**
* @requires PHP 7.0
* @group 37
*/
public function testWillCatchPhp7Throwable()
{
$callableWithHint = function (\stdClass $parameter) {
// will not be executed
};

$middleware = function ($req, $res, $next) use ($callableWithHint) {
$callableWithHint('not an stdClass');
};

$errorHandler = $this->getMock('stdClass', ['__invoke']);
$errorHandler
->expects(self::once())
->method('__invoke')
->with(
$this->request,
$this->response,
self::callback(function (\TypeError $throwable) {
self::assertStringStartsWith(
'Argument 1 passed to ZendTest\Stratigility\DispatchTest::ZendTest\Stratigility\{closure}()'
. ' must be an instance of stdClass, string given',
$throwable->getMessage()
);

return true;
})
);

$dispatch = new Dispatch();

$dispatch(
new Route('/foo', $middleware),
null,
$this->request,
$this->response,
$errorHandler
);
}
}

0 comments on commit 9f06282

Please sign in to comment.