mirror of
https://github.com/e107inc/e107.git
synced 2025-07-26 17:30:24 +02: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:
2
e107
2
e107
Submodule e107 updated: dae0c58af2...46efef4d4d
46
lib/PriorityCallbacks.php
Normal file
46
lib/PriorityCallbacks.php
Normal 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();
|
@@ -17,6 +17,9 @@ class GitPreparer implements Preparer
|
|||||||
|
|
||||||
protected function setVcsInProgress()
|
protected function setVcsInProgress()
|
||||||
{
|
{
|
||||||
|
// Cleanup in case of a fatal error
|
||||||
|
PriorityCallbacks::instance()->register_shutdown_function([$this, 'rollback']);
|
||||||
|
|
||||||
if ($this->isVcsInProgress())
|
if ($this->isVcsInProgress())
|
||||||
{
|
{
|
||||||
$this->debug('Git repo shows test in progress. Probably crashed test.');
|
$this->debug('Git repo shows test in progress. Probably crashed test.');
|
||||||
|
@@ -12,3 +12,6 @@ if (substr($app_path, 0, 1) !== '/')
|
|||||||
|
|
||||||
define('APP_PATH', realpath($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");
|
||||||
|
Reference in New Issue
Block a user