Correr seeds y botar tablas al final

This commit is contained in:
Juan Pablo Vial
2025-06-24 12:54:48 -04:00
parent a7cd661938
commit 29d9ea8e4a

View File

@ -62,6 +62,7 @@ class TestBootstrap
if (!Benchmark::execute([$this, 'isMigrated'])) {
Benchmark::execute([$this, 'migrate']);
}
Benchmark::execute([$this, 'seedTables']);
}
protected string $baseCommand = "bin/phinx";
@ -71,16 +72,12 @@ class TestBootstrap
$output = shell_exec($cmd);
$status = json_decode($output, true);
return $status['missing_count'] === 0;
return $status['missing_count'] === 0 and $status['pending_count'] === 0;
}
public function migrate(): void
{
$cmd = "{$this->baseCommand} migrate -e testing";
$status = shell_exec($cmd);
if ($status !== false and $status !== null) {
$cmd = "{$this->baseCommand} seed:run -e testing";
shell_exec($cmd);
}
shell_exec($cmd);
}
public function resetDatabase(): void
@ -125,6 +122,11 @@ class TestBootstrap
}
}
}
public function seedTables(): void
{
$cmd = "{$this->baseCommand} seed:run -e testing";
shell_exec($cmd);
}
protected PDO $connection;
protected function connect(): PDO
@ -171,6 +173,6 @@ Benchmark::execute([$bootstrap, 'run'], ['resetDatabase' => $resetDatabase]);
Benchmark::print();
register_shutdown_function(function() use ($bootstrap) {
Benchmark::execute([$bootstrap, 'truncateTables']);
Benchmark::execute([$bootstrap, 'resetDatabase']);
Benchmark::print();
});