diff --git a/src/ORM/Connect/TempDatabase.php b/src/ORM/Connect/TempDatabase.php index dce37959f..a47c50078 100644 --- a/src/ORM/Connect/TempDatabase.php +++ b/src/ORM/Connect/TempDatabase.php @@ -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; }