mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Add option to leave Temp DB when exiting
This commit is contained in:
parent
cb8ec9ae1d
commit
8d1a238e97
@ -4,6 +4,7 @@ namespace SilverStripe\ORM\Connect;
|
||||
|
||||
use Exception;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\Environment;
|
||||
use SilverStripe\Core\Injector\Injectable;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
@ -23,6 +24,13 @@ class TempDatabase
|
||||
*/
|
||||
protected $name = null;
|
||||
|
||||
/**
|
||||
* Optionally remove the test DB when the PHP process exits
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private static $teardown_on_exit = true;
|
||||
|
||||
/**
|
||||
* Create a new temp database
|
||||
*
|
||||
@ -195,13 +203,16 @@ class TempDatabase
|
||||
set_error_handler($oldErrorHandler);
|
||||
|
||||
// Ensure test db is killed on exit
|
||||
register_shutdown_function(function () {
|
||||
try {
|
||||
$this->kill();
|
||||
} catch (Exception $ex) {
|
||||
// An exception thrown while trying to remove a test database shouldn't fail a build, ignore
|
||||
}
|
||||
});
|
||||
$teardownOnExit = Config::inst()->get(static::class, 'teardown_on_exit');
|
||||
if ($teardownOnExit) {
|
||||
register_shutdown_function(function () {
|
||||
try {
|
||||
$this->kill();
|
||||
} catch (Exception $ex) {
|
||||
// An exception thrown while trying to remove a test database shouldn't fail a build, ignore
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return $dbname;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user