Pruebas de integracion con seeds
This commit is contained in:
@ -52,17 +52,15 @@ class TestBootstrap
|
||||
{
|
||||
public function __construct(protected array $configuration) {}
|
||||
|
||||
public function run(bool $resetDatabase = false): void
|
||||
public function run(bool $debug = false): void
|
||||
{
|
||||
if ($resetDatabase) {
|
||||
if (Benchmark::execute([$this, 'isMigrated'])) {
|
||||
Benchmark::execute([$this, 'resetDatabase']);
|
||||
}
|
||||
}
|
||||
if (!Benchmark::execute([$this, 'isMigrated'])) {
|
||||
Benchmark::execute([$this, 'migrate']);
|
||||
}
|
||||
Benchmark::execute([$this, 'seedTables']);
|
||||
$output = Benchmark::execute([$this, 'seedTables']);
|
||||
if ($debug) {
|
||||
var_dump($output);
|
||||
}
|
||||
}
|
||||
|
||||
protected string $baseCommand = "bin/phinx";
|
||||
@ -74,10 +72,10 @@ class TestBootstrap
|
||||
|
||||
return $status['missing_count'] === 0 and $status['pending_count'] === 0;
|
||||
}
|
||||
public function migrate(): void
|
||||
public function migrate(): false|null|string
|
||||
{
|
||||
$cmd = "{$this->baseCommand} migrate -e testing";
|
||||
shell_exec($cmd);
|
||||
return shell_exec($cmd);
|
||||
}
|
||||
|
||||
public function resetDatabase(): void
|
||||
@ -122,10 +120,15 @@ class TestBootstrap
|
||||
}
|
||||
}
|
||||
}
|
||||
public function seedTables(): void
|
||||
public function seedTables(): false|null|string
|
||||
{
|
||||
$cmd = "{$this->baseCommand} seed:run -e testing";
|
||||
shell_exec($cmd);
|
||||
$output = shell_exec($cmd);
|
||||
|
||||
$testSeeder = new Tests\Extension\TestSeeder($this->connect());
|
||||
$testSeeder->run();
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
protected PDO $connection;
|
||||
@ -161,18 +164,24 @@ spl_autoload_register(function($className) {
|
||||
];
|
||||
foreach ($namespaceMap as $namespace => $path) {
|
||||
if (str_starts_with($className, $namespace)) {
|
||||
require str_replace($namespace, "{$path}/", $className) . ".php";
|
||||
require str_replace([$namespace, '\\'], ["{$path}/", DIRECTORY_SEPARATOR], $className) . ".php";
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$bootstrap = new TestBootstrap($_ENV);
|
||||
$resetDatabase = $_ENV['RESET_DATABASE'] ?? false;
|
||||
Benchmark::execute([$bootstrap, 'run'], ['resetDatabase' => $resetDatabase]);
|
||||
$resetDatabase = ($_ENV['RESET_DATABASE'] === 'true') ?? false;
|
||||
$debug = ($_ENV['DEBUG'] === 'true') ?? false;
|
||||
|
||||
Benchmark::execute([$bootstrap, 'run'], ['debug' => $debug]);
|
||||
Benchmark::print();
|
||||
|
||||
register_shutdown_function(function() use ($bootstrap) {
|
||||
Benchmark::execute([$bootstrap, 'resetDatabase']);
|
||||
register_shutdown_function(function() use ($bootstrap, $resetDatabase) {
|
||||
$method = 'truncateTables';
|
||||
if ($resetDatabase) {
|
||||
$method = 'resetDatabase';
|
||||
}
|
||||
Benchmark::execute([$bootstrap, $method]);
|
||||
Benchmark::print();
|
||||
});
|
||||
|
Reference in New Issue
Block a user