|
18 | 18 |
|
19 | 19 | class DispatchTest extends TestCase
|
20 | 20 | {
|
| 21 | + /** |
| 22 | + * @var \Zend\Stratigility\Http\Request|\PHPUnit_Framework_MockObject_MockObject |
| 23 | + */ |
| 24 | + private $request; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var \Zend\Stratigility\Http\Response|\PHPUnit_Framework_MockObject_MockObject |
| 28 | + */ |
| 29 | + private $response; |
| 30 | + |
21 | 31 | public function setUp()
|
22 | 32 | {
|
23 | 33 | $this->request = $this->getMockBuilder('Zend\Stratigility\Http\Request')
|
@@ -199,4 +209,47 @@ public function testShouldAllowDispatchingPsr7Instances()
|
199 | 209 | $result = $dispatch($route, $err, $request->reveal(), $response->reveal(), $next);
|
200 | 210 | $this->assertSame($response->reveal(), $result);
|
201 | 211 | }
|
| 212 | + |
| 213 | + /** |
| 214 | + * @requires PHP 7.0 |
| 215 | + * @group 37 |
| 216 | + */ |
| 217 | + public function testWillCatchPhp7Throwable() |
| 218 | + { |
| 219 | + $callableWithHint = function (\stdClass $parameter) { |
| 220 | + // will not be executed |
| 221 | + }; |
| 222 | + |
| 223 | + $middleware = function ($req, $res, $next) use ($callableWithHint) { |
| 224 | + $callableWithHint('not an stdClass'); |
| 225 | + }; |
| 226 | + |
| 227 | + $errorHandler = $this->getMock('stdClass', ['__invoke']); |
| 228 | + $errorHandler |
| 229 | + ->expects(self::once()) |
| 230 | + ->method('__invoke') |
| 231 | + ->with( |
| 232 | + $this->request, |
| 233 | + $this->response, |
| 234 | + self::callback(function (\TypeError $throwable) { |
| 235 | + self::assertStringStartsWith( |
| 236 | + 'Argument 1 passed to ZendTest\Stratigility\DispatchTest::ZendTest\Stratigility\{closure}()' |
| 237 | + . ' must be an instance of stdClass, string given', |
| 238 | + $throwable->getMessage() |
| 239 | + ); |
| 240 | + |
| 241 | + return true; |
| 242 | + }) |
| 243 | + ); |
| 244 | + |
| 245 | + $dispatch = new Dispatch(); |
| 246 | + |
| 247 | + $dispatch( |
| 248 | + new Route('/foo', $middleware), |
| 249 | + null, |
| 250 | + $this->request, |
| 251 | + $this->response, |
| 252 | + $errorHandler |
| 253 | + ); |
| 254 | + } |
202 | 255 | }
|
0 commit comments