diff --git a/e107 b/e107 index dae0c58af..46efef4d4 160000 --- a/e107 +++ b/e107 @@ -1 +1 @@ -Subproject commit dae0c58af23f0fd31183dc823a328e2d14680d89 +Subproject commit 46efef4d4d4e5546ee6de815690faff2ebfc59f2 diff --git a/lib/PriorityCallbacks.php b/lib/PriorityCallbacks.php new file mode 100644 index 000000000..a66c78e3b --- /dev/null +++ b/lib/PriorityCallbacks.php @@ -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(); \ No newline at end of file diff --git a/lib/preparers/GitPreparer.php b/lib/preparers/GitPreparer.php index ce628faba..cce2fb1a2 100644 --- a/lib/preparers/GitPreparer.php +++ b/lib/preparers/GitPreparer.php @@ -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.'); diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php index b635f8686..ab9835dda 100644 --- a/tests/_bootstrap.php +++ b/tests/_bootstrap.php @@ -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)); \ No newline at end of file +define('PARAMS_SERIALIZED', serialize($params)); + +// Provide a way to register callbacks that execute before Codeception's +include(codecept_root_dir()."/lib/PriorityCallbacks.php");