Skip to content

Commit

Permalink
Adding Logic In Case Of Exit (#4604)
Browse files Browse the repository at this point in the history
* Converting Shutdown Into Existing Subscriber

* Updating Test To Satisfy Premature Exit Logic
  • Loading branch information
Fenikkusu authored and DavertMik committed Dec 5, 2017
1 parent dc9cf8b commit fba4837
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Codeception/Subscriber/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class ErrorHandler implements EventSubscriberInterface
use Shared\StaticEvents;

public static $events = [
Events::SUITE_BEFORE => 'handle'
Events::SUITE_BEFORE => 'handle',
Events::SUITE_AFTER => 'onFinish'
];

/**
Expand All @@ -27,6 +28,8 @@ class ErrorHandler implements EventSubscriberInterface
private $deprecationsInstalled = false;
private $oldHandler;

private $suiteFinished = false;

/**
* @var int stores bitmask for errors
*/
Expand All @@ -37,6 +40,11 @@ public function __construct()
$this->errorLevel = E_ALL & ~E_STRICT & ~E_DEPRECATED;
}

public function onFinish(SuiteEvent $e)
{
$this->suiteFinished = true;
}

public function handle(SuiteEvent $e)
{
$settings = $e->getSettings();
Expand Down Expand Up @@ -86,7 +94,12 @@ public function shutdownHandler()
}
$this->stopped = true;
$error = error_get_last();
if (!is_array($error)) {

if (!$this->suiteFinished && (
$error === null || !in_array($error['type'], [E_ERROR, E_COMPILE_ERROR, E_CORE_ERROR])
)) {
throw new \RuntimeException('Command Did Not Finish Properly');
} elseif (!is_array($error)) {
return;
}
if (error_reporting() === 0) {
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/Codeception/Subscriber/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public function testDeprecationMessagesRespectErrorLevelSetting()
$suiteEvent = new SuiteEvent(new Suite(), null, ['error_level' => 'E_ERROR']);
$errorHandler->handle($suiteEvent);

//Satisfying The Premature Exit Handling
$errorHandler->onFinish($suiteEvent);

Notification::all(); //clear the messages
$errorHandler->errorHandler(E_USER_DEPRECATED, 'deprecated message', __FILE__, __LINE__, []);

Expand Down

0 comments on commit fba4837

Please sign in to comment.