diff --git a/app/test.bootstrap.php b/app/test.bootstrap.php index acda92d..96b575f 100644 --- a/app/test.bootstrap.php +++ b/app/test.bootstrap.php @@ -52,12 +52,16 @@ class TestBootstrap { public function __construct(protected array $configuration) {} - public function run(): void + public function run(bool $resetDatabase = false): void { - if (Benchmark::execute([$this, 'isMigrated'])) { - Benchmark::execute([$this, 'resetDatabase']); + if ($resetDatabase) { + if (Benchmark::execute([$this, 'isMigrated'])) { + Benchmark::execute([$this, 'resetDatabase']); + } + } + if (!Benchmark::execute([$this, 'isMigrated'])) { + Benchmark::execute([$this, 'migrate']); } - Benchmark::execute([$this, 'migrate']); } protected string $baseCommand = "bin/phinx"; @@ -67,7 +71,7 @@ class TestBootstrap $output = shell_exec($cmd); $status = json_decode($output, true); - return $status['missing_count'] > 0; + return $status['missing_count'] === 0; } public function migrate(): void { @@ -162,7 +166,8 @@ spl_autoload_register(function($className) { }); $bootstrap = new TestBootstrap($_ENV); -Benchmark::execute([$bootstrap, 'run']); +$resetDatabase = $_ENV['RESET_DATABASE'] ?? false; +Benchmark::execute([$bootstrap, 'run'], ['resetDatabase' => $resetDatabase]); Benchmark::print(); register_shutdown_function(function() use ($bootstrap) {