Skip to content
Snippets Groups Projects
Commit b427f797 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Ajout d'une commande CLI pour lancer des tests de migration (......

Ajout d'une commande CLI pour lancer des tests de migration (... bddadmin:test-migration <Nom test> <utile|before|after>)
parent 2d0bc301
No related branches found
No related tags found
No related merge requests found
Pipeline #38537 passed
1.4.2 (28/05/2025)
------------------
- Ajout d'une commande CLI pour lancer des tests de migration (... bddadmin:test-migration <Nom test> <utile|before|after>)
1.4.1 (23/05/2025)
------------------
......
......@@ -66,6 +66,7 @@ return [
Command\CopyFromCommand::class => Command\CommandFactory::class,
Command\LoadCommand::class => Command\CommandFactory::class,
Command\SaveCommand::class => Command\CommandFactory::class,
Command\TestMigrationCommand::class => Command\CommandFactory::class,
],
],
......@@ -83,6 +84,7 @@ return [
'bddadmin:copy-from' => Command\CopyFromCommand::class,
'bddadmin:load' => Command\LoadCommand::class,
'bddadmin:save' => Command\SaveCommand::class,
'bddadmin:test-migration' => Command\TestMigrationCommand::class,
],
],
];
\ No newline at end of file
<?php
namespace Unicaen\BddAdmin\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Unicaen\BddAdmin\BddAwareTrait;
use Unicaen\BddAdmin\Data\DataManager;
use Unicaen\BddAdmin\Ddl\Ddl;
/**
* Description of TestMigrationCommand
*
* @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
*/
class TestMigrationCommand extends Command
{
use BddAwareTrait;
protected function configure(): void
{
$this->setDescription('Test de script de migration args: <Nom partiel du script> <utile|before|after>')
->addArgument('class', InputArgument::REQUIRED, 'Nom du script de migration (classe)')
->addArgument('context', InputArgument::REQUIRED, 'Contexte de migration (utile, before ou after)');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$bdd = $this->getBdd()->setLogger($io);
$io->title('Test de script de migration');
$class = $input->getArgument('class');
$context = $input->getArgument('context');
$bdd->migration()->test($class, $context);
return Command::SUCCESS;
}
}
\ No newline at end of file
......@@ -208,4 +208,48 @@ class MigrationManager
}
}
}
public function test(string $class, string $context): void
{
if ($context != self::ACTION_BEFORE && $context != self::ACTION_AFTER && $context != 'utile') {
throw new \Exception('Le contexte de migration ' . $context . ' est non conforme, seuls after, before et utile sont possibles');
}
$scripts = $this->getScripts();
$script = null;
foreach ($scripts as $object) {
if (str_contains($object::class, $class)) {
if ($script !== null) {
throw new \Exception("Plusieurs scripts de migration correspondent à \"$class\", merci de préciser");
}
$script = $object;
}
}
if (!$script){
throw new \Exception('Aucun script de migration ne correspond à "'.$class.'"');
}
$object->logBegin($object::class.' -> '.$context);
if ('utile' === $context) {
if ($script->utile()){
$object->logMsg("Utile renvoie OUI");
}else{
$object->logMsg("Utile renvoie NON");
}
}else{
try {
$script->$context();
}catch(\Throwable $e){
$object->logError($e);
}
}
$object->logEnd('Fin du test');
$script->$context();
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment