Add option to leave Temp DB when exiting

This commit is contained in:
Bernard Hamlin 2019-03-11 11:46:20 +13:00
parent cb8ec9ae1d
commit 8d1a238e97

View File

@ -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;
}