Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 1077480

Browse files
author
Moritz Fain
committed
Added unittest for PHP7 throwable support
1 parent cdf576c commit 1077480

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

test/ApplicationTest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public function setupActionController()
291291
return $this->application;
292292
}
293293

294-
public function setupBadController($addService = true)
294+
public function setupBadController($addService = true, $action = 'test')
295295
{
296296
$request = $this->serviceManager->get('Request');
297297
$request->setUri('http://example.local/bad');
@@ -301,7 +301,7 @@ public function setupBadController($addService = true)
301301
'route' => '/bad',
302302
'defaults' => [
303303
'controller' => 'bad',
304-
'action' => 'test',
304+
'action' => $action,
305305
],
306306
]);
307307
$router->addRoute('bad', $route);
@@ -374,6 +374,25 @@ public function testLocatorExceptionShouldTriggerDispatchError()
374374
$this->assertSame($response, $result->getResponse(), get_class($result));
375375
}
376376

377+
/**
378+
* @requires PHP 7.0
379+
* @group error-handling
380+
*/
381+
public function testPhp7ErrorRaisedInDispatchableShouldRaiseDispatchErrorEvent()
382+
{
383+
$this->setupBadController(true, 'test-php7-error');
384+
$response = $this->application->getResponse();
385+
$events = $this->application->getEventManager();
386+
$events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($response) {
387+
$exception = $e->getParam('exception');
388+
$response->setContent($exception->getMessage());
389+
return $response;
390+
});
391+
392+
$this->application->run();
393+
$this->assertContains('Raised an error', $response->getContent());
394+
}
395+
377396
/**
378397
* @group error-handling
379398
*/

test/Controller/TestAsset/BadController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ public function testAction()
1717
{
1818
throw new \Exception('Raised an exception');
1919
}
20+
21+
public function testPhp7ErrorAction()
22+
{
23+
throw new \Error('Raised an error');
24+
}
2025
}

0 commit comments

Comments
 (0)