1
0
mirror of https://github.com/e107inc/e107.git synced 2025-03-23 05:49:47 +01:00

PriorityCallbacks: Execute callbacks before Codeception's

GitPreparer now registers a "priority" register_shutdown_function
callback in order to clean up in case of a fatal error.
This commit is contained in:
Nick Liu 2018-11-01 06:55:26 -05:00
parent 6f416523c3
commit 952c6e5890
No known key found for this signature in database
GPG Key ID: 1167C5F9C9897637
4 changed files with 54 additions and 2 deletions

2
e107

@ -1 +1 @@
Subproject commit dae0c58af23f0fd31183dc823a328e2d14680d89
Subproject commit 46efef4d4d4e5546ee6de815690faff2ebfc59f2

46
lib/PriorityCallbacks.php Normal file
View File

@ -0,0 +1,46 @@
<?php
/**
* Execute callbacks before Codeception does
*/
class PriorityCallbacks
{
/** @var array */
private $shutdown_functions = [];
private function __construct()
{
register_shutdown_function([$this, 'call_shutdown_functions']);
}
public static function instance()
{
static $instance = null;
if (!$instance instanceof self)
{
$instance = new static();
}
return $instance;
}
public function call_shutdown_functions()
{
foreach ($this->shutdown_functions as $shutdown_function)
{
call_user_func($shutdown_function);
}
}
public function register_shutdown_function($callable)
{
$this->shutdown_functions[] = $callable;
}
private function __clone() {}
private function __sleep() {}
private function __wakeup() {}
}
PriorityCallbacks::instance();

View File

@ -17,6 +17,9 @@ class GitPreparer implements Preparer
protected function setVcsInProgress()
{
// Cleanup in case of a fatal error
PriorityCallbacks::instance()->register_shutdown_function([$this, 'rollback']);
if ($this->isVcsInProgress())
{
$this->debug('Git repo shows test in progress. Probably crashed test.');

View File

@ -11,4 +11,7 @@ if (substr($app_path, 0, 1) !== '/')
$app_path = codecept_root_dir() . "/${app_path}";
define('APP_PATH', realpath($app_path));
define('PARAMS_SERIALIZED', serialize($params));
define('PARAMS_SERIALIZED', serialize($params));
// Provide a way to register callbacks that execute before Codeception's
include(codecept_root_dir()."/lib/PriorityCallbacks.php");