Correr seeds y botar tablas al final
This commit is contained in:
@ -62,6 +62,7 @@ class TestBootstrap
|
|||||||
if (!Benchmark::execute([$this, 'isMigrated'])) {
|
if (!Benchmark::execute([$this, 'isMigrated'])) {
|
||||||
Benchmark::execute([$this, 'migrate']);
|
Benchmark::execute([$this, 'migrate']);
|
||||||
}
|
}
|
||||||
|
Benchmark::execute([$this, 'seedTables']);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected string $baseCommand = "bin/phinx";
|
protected string $baseCommand = "bin/phinx";
|
||||||
@ -71,16 +72,12 @@ class TestBootstrap
|
|||||||
$output = shell_exec($cmd);
|
$output = shell_exec($cmd);
|
||||||
$status = json_decode($output, true);
|
$status = json_decode($output, true);
|
||||||
|
|
||||||
return $status['missing_count'] === 0;
|
return $status['missing_count'] === 0 and $status['pending_count'] === 0;
|
||||||
}
|
}
|
||||||
public function migrate(): void
|
public function migrate(): void
|
||||||
{
|
{
|
||||||
$cmd = "{$this->baseCommand} migrate -e testing";
|
$cmd = "{$this->baseCommand} migrate -e testing";
|
||||||
$status = shell_exec($cmd);
|
shell_exec($cmd);
|
||||||
if ($status !== false and $status !== null) {
|
|
||||||
$cmd = "{$this->baseCommand} seed:run -e testing";
|
|
||||||
shell_exec($cmd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resetDatabase(): void
|
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 PDO $connection;
|
||||||
protected function connect(): PDO
|
protected function connect(): PDO
|
||||||
@ -171,6 +173,6 @@ Benchmark::execute([$bootstrap, 'run'], ['resetDatabase' => $resetDatabase]);
|
|||||||
Benchmark::print();
|
Benchmark::print();
|
||||||
|
|
||||||
register_shutdown_function(function() use ($bootstrap) {
|
register_shutdown_function(function() use ($bootstrap) {
|
||||||
Benchmark::execute([$bootstrap, 'truncateTables']);
|
Benchmark::execute([$bootstrap, 'resetDatabase']);
|
||||||
Benchmark::print();
|
Benchmark::print();
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user