From 952c6e5890daa36236be675d8c4f21cecabc1fe7 Mon Sep 17 00:00:00 2001 From: Nick Liu Date: Thu, 1 Nov 2018 06:55:26 -0500 Subject: [PATCH] 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. --- e107 | 2 +- lib/PriorityCallbacks.php | 46 +++++++++++++++++++++++++++++++++++ lib/preparers/GitPreparer.php | 3 +++ tests/_bootstrap.php | 5 +++- 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 lib/PriorityCallbacks.php 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 @@ +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");