diff --git a/README.md b/README.md index b03d0bf..a8250ce 100644 --- a/README.md +++ b/README.md @@ -74,17 +74,19 @@ DROP TABLE IF EXISTS public.entity; ```php use DI\Container; -use kuaukutsu\poc\migration\Migration; -use kuaukutsu\poc\migration\MigrationCollection; use kuaukutsu\poc\migration\internal\connection\PDO\Driver; use kuaukutsu\poc\migration\example\presentation\DownCommand; +use kuaukutsu\poc\migration\example\presentation\CreateCommand; use kuaukutsu\poc\migration\example\presentation\FixtureCommand; +use kuaukutsu\poc\migration\example\presentation\VerifyCommand; use kuaukutsu\poc\migration\example\presentation\InitCommand; use kuaukutsu\poc\migration\example\presentation\RedoCommand; use kuaukutsu\poc\migration\example\presentation\UpCommand; +use kuaukutsu\poc\migration\tools\PrettyConsoleOutput; +use kuaukutsu\poc\migration\Migration; +use kuaukutsu\poc\migration\MigrationCollection; use kuaukutsu\poc\migration\Migrator; use kuaukutsu\poc\migration\MigratorInterface; -use kuaukutsu\poc\migration\tools\PrettyConsoleOutput; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\CommandLoader\ContainerCommandLoader; @@ -120,7 +122,9 @@ $console->setCommandLoader( 'migrate:up' => UpCommand::class, 'migrate:down' => DownCommand::class, 'migrate:redo' => RedoCommand::class, + 'migrate:verify' => VerifyCommand::class, 'migrate:fixture' => FixtureCommand::class, + 'migrate:create' => CreateCommand::class, ], ) ); diff --git a/example/mysql.php b/example/mysql.php index f414486..545a7a7 100644 --- a/example/mysql.php +++ b/example/mysql.php @@ -4,7 +4,7 @@ use kuaukutsu\poc\migration\internal\connection\PDO\Driver; use kuaukutsu\poc\migration\tools\PrettyConsoleOutput; -use kuaukutsu\poc\migration\InputArgs; +use kuaukutsu\poc\migration\InputOptions; use kuaukutsu\poc\migration\Migration; use kuaukutsu\poc\migration\MigrationCollection; use kuaukutsu\poc\migration\Migrator; @@ -28,7 +28,7 @@ ); foreach (range(1, 1000) as $row) { - $migrator->create(new InputArgs(dbName: "mysql/main", migrationName: $row . "-test")); + $migrator->create(new InputOptions(dbName: "mysql/main", migrationName: $row . "-test")); } try { @@ -38,7 +38,7 @@ } try { - $migrator->up(new InputArgs(limit: 100)); + $migrator->up(new InputOptions(limit: 100)); } catch (Throwable $exception) { echo $exception->getMessage() . PHP_EOL; } diff --git a/example/presentation/CommandOptions.php b/example/presentation/CommandOptions.php index 0cd4413..9cb2e1b 100644 --- a/example/presentation/CommandOptions.php +++ b/example/presentation/CommandOptions.php @@ -6,14 +6,14 @@ use InvalidArgumentException; use Symfony\Component\Console\Input\InputInterface; -use kuaukutsu\poc\migration\InputArgs; +use kuaukutsu\poc\migration\InputOptions; trait CommandOptions { /** * @throws InvalidArgumentException */ - protected function getArguments(InputInterface $input): InputArgs + protected function getOptions(InputInterface $input): InputOptions { $options = []; if ($input->hasOption('limit')) { @@ -44,7 +44,7 @@ protected function getArguments(InputInterface $input): InputArgs $options['migrationName'] = $this->getMigrationName($input); } - return new InputArgs(...$options); + return new InputOptions(...$options); } /** diff --git a/example/presentation/CreateCommand.php b/example/presentation/CreateCommand.php index 3a049dc..a76ebf0 100644 --- a/example/presentation/CreateCommand.php +++ b/example/presentation/CreateCommand.php @@ -47,7 +47,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { try { - $this->migrator->create($this->getArguments($input)); + $this->migrator->create($this->getOptions($input)); } catch (InvalidArgumentException | MigratorException $e) { $output->writeln($e->getMessage()); return Command::INVALID; diff --git a/example/presentation/DownCommand.php b/example/presentation/DownCommand.php index f89fc2c..40cdc3b 100644 --- a/example/presentation/DownCommand.php +++ b/example/presentation/DownCommand.php @@ -64,7 +64,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { try { - $this->migrator->down($this->getArguments($input)); + $this->migrator->down($this->getOptions($input)); } catch (InvalidArgumentException | MigratorException $e) { if ($e instanceof InitializationException) { $output->writeln('Calling the command "migrate:init" may help fix the error.'); diff --git a/example/presentation/FixtureCommand.php b/example/presentation/FixtureCommand.php index 6c7cc04..ba796e8 100644 --- a/example/presentation/FixtureCommand.php +++ b/example/presentation/FixtureCommand.php @@ -57,7 +57,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { try { - $this->migrator->fixture($this->getArguments($input)); + $this->migrator->fixture($this->getOptions($input)); } catch (InvalidArgumentException | MigratorException $e) { $output->writeln($e->getMessage()); return Command::INVALID; diff --git a/example/presentation/RedoCommand.php b/example/presentation/RedoCommand.php index 7537f83..cedf3a9 100644 --- a/example/presentation/RedoCommand.php +++ b/example/presentation/RedoCommand.php @@ -64,7 +64,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { try { - $this->migrator->redo($this->getArguments($input)); + $this->migrator->redo($this->getOptions($input)); } catch (InvalidArgumentException | MigratorException $e) { if ($e instanceof InitializationException) { $output->writeln('Calling the command "migrate:init" may help fix the error.'); diff --git a/example/presentation/UpCommand.php b/example/presentation/UpCommand.php index 95c9ab1..1558cbd 100644 --- a/example/presentation/UpCommand.php +++ b/example/presentation/UpCommand.php @@ -72,7 +72,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { try { - $this->migrator->up($this->getArguments($input)); + $this->migrator->up($this->getOptions($input)); } catch (InvalidArgumentException | MigratorException $e) { if ($e instanceof InitializationException) { $output->writeln('Calling the command "migrate:init" may help fix the error.'); diff --git a/example/presentation/VerifyCommand.php b/example/presentation/VerifyCommand.php index 1a9be4e..11edb7f 100644 --- a/example/presentation/VerifyCommand.php +++ b/example/presentation/VerifyCommand.php @@ -58,7 +58,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { try { - $this->migrator->verify($this->getArguments($input)); + $this->migrator->verify($this->getOptions($input)); } catch (InvalidArgumentException | MigratorException $e) { if ($e instanceof InitializationException) { $output->writeln('Calling the command "migrate:init" may help fix the error.'); diff --git a/src/Config.php b/src/Config.php new file mode 100644 index 0000000..6a1df00 --- /dev/null +++ b/src/Config.php @@ -0,0 +1,20 @@ +name = $this->driver->getName() . '/' . $this->driver->getDbName(); + $this->name = $this->driver->getName() . '/' . $this->driver->getSourceName(); } /** @@ -53,6 +50,6 @@ public function getSetupPath(): string */ public function getCommand(): CommandInterface { - return $this->driver->makeCommand(new Params(table: $this->table)); + return $this->driver->makeCommand($this->config); } } diff --git a/src/Migrator.php b/src/Migrator.php index 6b02048..26e2c44 100644 --- a/src/Migrator.php +++ b/src/Migrator.php @@ -42,7 +42,27 @@ public function init(): void } #[Override] - public function up(InputArgs $args = new InputArgs()): void + public function create(InputOptions $args = new InputOptions()): void + { + if ($args->dbName === null) { + throw new ConfigurationException( + "DBName must be declared." + ); + } + + if ($args->migrationName === null) { + throw new ConfigurationException( + "Migration Name must be declared." + ); + } + + foreach ($this->selectDb($args) as $migration) { + $this->actionWorkflow->create($migration, $args->migrationName); + } + } + + #[Override] + public function up(InputOptions $args = new InputOptions()): void { foreach ($this->selectDb($args) as $migration) { $this->actionWorkflow->up($migration, $args); @@ -50,7 +70,7 @@ public function up(InputArgs $args = new InputArgs()): void } #[Override] - public function down(InputArgs $args = new InputArgs()): void + public function down(InputOptions $args = new InputOptions()): void { foreach ($this->selectDb($args) as $migration) { $this->actionWorkflow->down($migration, $args); @@ -58,14 +78,22 @@ public function down(InputArgs $args = new InputArgs()): void } #[Override] - public function redo(InputArgs $args = new InputArgs()): void + public function fixture(InputOptions $args = new InputOptions()): void + { + foreach ($this->selectDb($args) as $migration) { + $this->actionWorkflow->fixture($migration, $args); + } + } + + #[Override] + public function redo(InputOptions $args = new InputOptions()): void { $this->down($args); $this->up($args->withResetLimit()); } #[Override] - public function verify(InputArgs $args = new InputArgs()): void + public function verify(InputOptions $args = new InputOptions()): void { foreach ($this->selectDb($args) as $migration) { $version = $this->actionWorkflow->up( @@ -82,39 +110,11 @@ public function verify(InputArgs $args = new InputArgs()): void } } - #[Override] - public function fixture(InputArgs $args = new InputArgs()): void - { - foreach ($this->selectDb($args) as $migration) { - $this->actionWorkflow->fixture($migration, $args); - } - } - - #[Override] - public function create(InputArgs $args = new InputArgs()): void - { - if ($args->dbName === null) { - throw new ConfigurationException( - "DBName must be declared." - ); - } - - if ($args->migrationName === null) { - throw new ConfigurationException( - "Migration Name must be declared." - ); - } - - foreach ($this->selectDb($args) as $migration) { - $this->actionWorkflow->create($migration, $args->migrationName); - } - } - /** * @return iterable * @throws ConfigurationException */ - private function selectDb(InputArgs $args): iterable + private function selectDb(InputOptions $args): iterable { if ($args->dbName === null) { return $this->collection; diff --git a/src/MigratorInterface.php b/src/MigratorInterface.php index 3ad32a0..d193468 100644 --- a/src/MigratorInterface.php +++ b/src/MigratorInterface.php @@ -18,13 +18,18 @@ interface MigratorInterface */ public function init(): void; + /** + * @throws ConfigurationException + */ + public function create(InputOptions $args = new InputOptions()): void; + /** * @throws ActionException * @throws ConfigurationException If the driver is not implemented * @throws ConnectionException * @throws InitializationException initialization step is required */ - public function up(InputArgs $args = new InputArgs()): void; + public function up(InputOptions $args = new InputOptions()): void; /** * @throws ActionException @@ -32,15 +37,14 @@ public function up(InputArgs $args = new InputArgs()): void; * @throws ConnectionException * @throws InitializationException initialization step is required */ - public function down(InputArgs $args = new InputArgs()): void; + public function down(InputOptions $args = new InputOptions()): void; /** * @throws ActionException * @throws ConfigurationException If the driver is not implemented * @throws ConnectionException - * @throws InitializationException initialization step is required */ - public function redo(InputArgs $args = new InputArgs()): void; + public function fixture(InputOptions $args = new InputOptions()): void; /** * @throws ActionException @@ -48,17 +52,13 @@ public function redo(InputArgs $args = new InputArgs()): void; * @throws ConnectionException * @throws InitializationException initialization step is required */ - public function verify(InputArgs $args = new InputArgs()): void; + public function redo(InputOptions $args = new InputOptions()): void; /** * @throws ActionException * @throws ConfigurationException If the driver is not implemented * @throws ConnectionException + * @throws InitializationException initialization step is required */ - public function fixture(InputArgs $args = new InputArgs()): void; - - /** - * @throws ConfigurationException - */ - public function create(InputArgs $args = new InputArgs()): void; + public function verify(InputOptions $args = new InputOptions()): void; } diff --git a/src/internal/command/CommandInterface.php b/src/command/CommandInterface.php similarity index 78% rename from src/internal/command/CommandInterface.php rename to src/command/CommandInterface.php index 10507c4..510a5ff 100644 --- a/src/internal/command/CommandInterface.php +++ b/src/command/CommandInterface.php @@ -2,10 +2,9 @@ declare(strict_types=1); -namespace kuaukutsu\poc\migration\internal\command; +namespace kuaukutsu\poc\migration\command; use Throwable; -use kuaukutsu\poc\migration\internal\command; use kuaukutsu\poc\migration\Context; interface CommandInterface @@ -13,7 +12,7 @@ interface CommandInterface /** * @return array */ - public function fetchApplied(command\Args $args = new command\Args()): array; + public function fetchApplied(Options $options = new Options()): array; /** * @return bool true: request completed; false: request rejected diff --git a/src/internal/command/Args.php b/src/command/Options.php similarity index 65% rename from src/internal/command/Args.php rename to src/command/Options.php index 221ce57..a7b4343 100644 --- a/src/internal/command/Args.php +++ b/src/command/Options.php @@ -2,14 +2,11 @@ declare(strict_types=1); -namespace kuaukutsu\poc\migration\internal\command; +namespace kuaukutsu\poc\migration\command; -use kuaukutsu\poc\migration\InputArgs; +use kuaukutsu\poc\migration\InputOptions; -/** - * @psalm-internal kuaukutsu\poc\migration - */ -final readonly class Args +final readonly class Options { /** * @param non-negative-int $limit @@ -18,18 +15,16 @@ public function __construct( public int $limit = 0, public int $version = 0, - public bool $applyLatestVersion = false, ) { assert($this->limit >= 0); assert($this->version >= 0); } - public static function makeFromInput(InputArgs $args): self + public static function makeFromInput(InputOptions $args): self { return new self( limit: $args->limit, version: $args->version, - applyLatestVersion: $args->hasApplyLatestVersion(), ); } diff --git a/src/connection/DriverInterface.php b/src/connection/DriverInterface.php index eddae4b..39515f0 100644 --- a/src/connection/DriverInterface.php +++ b/src/connection/DriverInterface.php @@ -4,9 +4,9 @@ namespace kuaukutsu\poc\migration\connection; +use kuaukutsu\poc\migration\command\CommandInterface; use kuaukutsu\poc\migration\exception\ConnectionException; -use kuaukutsu\poc\migration\internal\command\CommandInterface; -use kuaukutsu\poc\migration\internal\command\Params; +use kuaukutsu\poc\migration\Config; interface DriverInterface { @@ -18,7 +18,7 @@ public function getName(): string; /** * @return non-empty-lowercase-string */ - public function getDbName(): string; + public function getSourceName(): string; /** * @return non-empty-string @@ -28,5 +28,5 @@ public function getSetupPath(): string; /** * @throws ConnectionException */ - public function makeCommand(Params $params): CommandInterface; + public function makeCommand(Config $config): CommandInterface; } diff --git a/src/internal/command/Command.php b/src/internal/action/Command.php similarity index 68% rename from src/internal/command/Command.php rename to src/internal/action/Command.php index 7063d9e..3f412d6 100644 --- a/src/internal/command/Command.php +++ b/src/internal/action/Command.php @@ -2,11 +2,14 @@ declare(strict_types=1); -namespace kuaukutsu\poc\migration\internal\command; +namespace kuaukutsu\poc\migration\internal\action; use Override; use Throwable; +use kuaukutsu\poc\migration\command\CommandInterface; +use kuaukutsu\poc\migration\command\Options; use kuaukutsu\poc\migration\connection\ConnectionInterface; +use kuaukutsu\poc\migration\Config; use kuaukutsu\poc\migration\Context; /** @@ -16,26 +19,41 @@ { public function __construct( private ConnectionInterface $connection, - private Params $params, + private Config $config, ) { } #[Override] - public function fetchApplied(Args $args = new Args()): array + public function fetchApplied(Options $options = new Options()): array { $params = []; - $query = sprintf('SELECT name, version FROM %s', $this->params->table); - if ($args->version > 0) { - $query .= ' WHERE version=:version'; - $params['version'] = $args->version; + $where = ''; + if ($options->version > 0) { + $where = 'WHERE version=:version'; + $params['version'] = $options->version; } - $query .= ' ORDER BY atime DESC, name DESC'; - if ($args->limit > 0) { - $query .= ' LIMIT ' . $args->limit; + $limit = ''; + if ($options->limit > 0) { + $limit = 'LIMIT ' . $options->limit; } + /** @var non-empty-string $query */ + $query = str_replace( + [ + ':table', + '[WHERE]', + '[LIMIT]', + ], + [ + $this->config->table, + $where, + $limit, + ], + 'SELECT name, version FROM :table [WHERE] ORDER BY atime DESC, name DESC [LIMIT]', + ); + return $this->connection->fetchRecord($query, $params); } @@ -53,7 +71,7 @@ public function up(Context $context): bool $transaction->exec( sprintf( 'INSERT INTO %s (name, version, atime) VALUES (\'%s\', %d, \'%s\')', - $this->params->table, + $this->config->table, $context->filename, $context->version, gmdate('Y-m-d H:i:s'), @@ -82,7 +100,7 @@ public function down(Context $context): bool $transaction->exec( sprintf( 'DELETE FROM %s WHERE name=\'%s\'', - $this->params->table, + $this->config->table, $context->filename, ) ); diff --git a/src/internal/action/Workflow.php b/src/internal/action/Workflow.php index 7c7e766..2651815 100644 --- a/src/internal/action/Workflow.php +++ b/src/internal/action/Workflow.php @@ -4,24 +4,24 @@ namespace kuaukutsu\poc\migration\internal\action; -use Iterator; use Throwable; use DateTimeImmutable; -use kuaukutsu\poc\migration\event\ExceptionEvent; +use Iterator; +use kuaukutsu\poc\migration\command\CommandInterface; +use kuaukutsu\poc\migration\command\Options; use kuaukutsu\poc\migration\event\Event; use kuaukutsu\poc\migration\event\EventAction; use kuaukutsu\poc\migration\event\EventDispatcher; +use kuaukutsu\poc\migration\event\ExceptionEvent; use kuaukutsu\poc\migration\event\MigrateErrorEvent; use kuaukutsu\poc\migration\event\MigrateSuccessEvent; use kuaukutsu\poc\migration\exception\ActionException; use kuaukutsu\poc\migration\exception\ConfigurationException; use kuaukutsu\poc\migration\exception\ConnectionException; use kuaukutsu\poc\migration\exception\InitializationException; -use kuaukutsu\poc\migration\internal\command; -use kuaukutsu\poc\migration\internal\command\CommandInterface; use kuaukutsu\poc\migration\internal\filesystem; use kuaukutsu\poc\migration\Context; -use kuaukutsu\poc\migration\InputArgs; +use kuaukutsu\poc\migration\InputOptions; use kuaukutsu\poc\migration\Migration; /** @@ -40,14 +40,14 @@ public function __construct(private EventDispatcher $eventDispatcher) * @throws ConnectionException * @throws InitializationException */ - public function up(Migration $migration, InputArgs $args): int + public function up(Migration $migration, InputOptions $options): int { $command = $this->makeCommand($migration); - $appliedMigrations = $this->getAppliedMigrations($migration, $command, new command\Args()); + $appliedMigrations = $this->getAppliedMigrations($migration, $command, new Options()); $fsHandler = static fn(filesystem\Action $fs): Iterator => $fs->up( $appliedMigrations, - filesystem\Args::makeFromInput($args) + filesystem\Options::makeFromInput($options) ); $version = generateVersion(); @@ -60,20 +60,20 @@ public function up(Migration $migration, InputArgs $args): int filename: $filename, query: $query, version: $version, - dryRun: $args->dryRun, + dryRun: $options->dryRun, ), EventAction::up, ); } catch (ActionException $exception) { - if ($args->exactlyAll) { - $this->down($migration, new InputArgs(version: $version)); + if ($options->exactlyAll) { + $this->down($migration, new InputOptions(version: $version)); } throw $exception; } } - if ($args->hasRepeatable()) { + if ($options->hasRepeatable()) { $this->repeatable($migration, $command, $version); } @@ -86,11 +86,18 @@ public function up(Migration $migration, InputArgs $args): int * @throws ConnectionException * @throws InitializationException */ - public function down(Migration $migration, InputArgs $args): void + public function down(Migration $migration, InputOptions $options): void { $command = $this->makeCommand($migration); - $appliedMigrations = $this->getAppliedMigrations($migration, $command, command\Args::makeFromInput($args)); + $commandOptions = Options::makeFromInput($options); + if ($options->hasApplyLatestVersion()) { + $commandOptions = $commandOptions->withVersion( + $this->getLastVersion($migration, $command) + ); + } + + $appliedMigrations = $this->getAppliedMigrations($migration, $command, $commandOptions); $fsHandler = static fn(filesystem\Action $fs): Iterator => $fs->down($appliedMigrations); foreach ($this->iteratorHandler($migration, $fsHandler) as $filename => $query) { @@ -101,7 +108,7 @@ public function down(Migration $migration, InputArgs $args): void filename: $filename, query: $query, version: $appliedMigrations[$filename], - dryRun: $args->dryRun, + dryRun: $options->dryRun, ), EventAction::down, ); @@ -113,12 +120,12 @@ public function down(Migration $migration, InputArgs $args): void * @throws ConfigurationException * @throws ConnectionException */ - public function fixture(Migration $migration, InputArgs $args): void + public function fixture(Migration $migration, InputOptions $options): void { $command = $this->makeCommand($migration); $fsHandler = static fn(filesystem\Action $fs): Iterator => $fs->fixture( - filesystem\Args::makeFromInput($args) + filesystem\Options::makeFromInput($options) ); foreach ($this->iteratorHandler($migration, $fsHandler) as $filename => $query) { @@ -128,7 +135,7 @@ public function fixture(Migration $migration, InputArgs $args): void dbName: $migration->getName(), filename: $filename, query: $query, - dryRun: $args->dryRun, + dryRun: $options->dryRun, ), EventAction::fixture, ); @@ -145,7 +152,7 @@ public function initialization(Migration $migration): void $command = $this->makeCommand($migration); try { - $files = (new filesystem\Setup($migration->getSetupPath(), $migration->table))->all(); + $files = (new filesystem\Setup($migration->getSetupPath(), $migration->config->table))->all(); } catch (ConfigurationException $exception) { $this->eventDispatcher->trigger( Event::FilesystemError, @@ -176,8 +183,8 @@ public function create(Migration $migration, string $name): void { try { (new filesystem\Action($migration->path))->create( - $migration->templFactory->makeName($name), - $migration->templFactory->makeBody(), + $migration->config->templFactory->makeName($name), + $migration->config->templFactory->makeBody(), ); } catch (ConfigurationException $exception) { $this->eventDispatcher->trigger( @@ -217,17 +224,10 @@ private function repeatable(Migration $migration, CommandInterface $command, int * @return array * @throws InitializationException */ - private function getAppliedMigrations(Migration $migration, CommandInterface $command, command\Args $args): array + private function getAppliedMigrations(Migration $migration, CommandInterface $command, Options $options): array { try { - if ($args->applyLatestVersion) { - $appliedMigrations = $command->fetchApplied(new command\Args(limit: 1)); - if (count($appliedMigrations) === 1) { - $args = $args->withVersion(current($appliedMigrations)); - } - } - - return $command->fetchApplied($args); + return $command->fetchApplied($options); } catch (Throwable $exception) { $this->eventDispatcher->trigger( Event::InitializationError, @@ -238,6 +238,20 @@ private function getAppliedMigrations(Migration $migration, CommandInterface $co } } + /** + * @return non-negative-int + * @throws InitializationException + */ + private function getLastVersion(Migration $migration, CommandInterface $command): int + { + $appliedMigrations = $this->getAppliedMigrations($migration, $command, new Options(limit: 1)); + if (count($appliedMigrations) === 1) { + return current($appliedMigrations); + } + + return 0; + } + /** * @param callable(Context $context):bool $handler * @throws ActionException diff --git a/src/internal/command/Params.php b/src/internal/command/Params.php deleted file mode 100644 index a6816b6..0000000 --- a/src/internal/command/Params.php +++ /dev/null @@ -1,19 +0,0 @@ -dbname; } @@ -74,9 +74,9 @@ public function getSetupPath(): string } #[Override] - public function makeCommand(Params $params): CommandInterface + public function makeCommand(Config $config): CommandInterface { - return new Command($this->makeConnection(), $params); + return new Command($this->makeConnection(), $config); } /** diff --git a/src/internal/filesystem/Action.php b/src/internal/filesystem/Action.php index 4616928..20f2be2 100644 --- a/src/internal/filesystem/Action.php +++ b/src/internal/filesystem/Action.php @@ -32,7 +32,7 @@ public function __construct(string $path) * @return Iterator * @throws ConfigurationException */ - public function up(array $listExcluded, Args $args = new Args()): Iterator + public function up(array $listExcluded, Options $options = new Options()): Iterator { $iternum = 0; foreach ($this->makeIterator($this->path) as $matchFilename) { @@ -42,7 +42,7 @@ public function up(array $listExcluded, Args $args = new Args()): Iterator continue; } - if ($args->limit > 0 && $iternum >= $args->limit) { + if ($options->limit > 0 && $iternum >= $options->limit) { return; } @@ -61,11 +61,11 @@ public function up(array $listExcluded, Args $args = new Args()): Iterator * @return Iterator * @throws ConfigurationException */ - public function down(array $listApplied, Args $args = new Args()): Iterator + public function down(array $listApplied, Options $options = new Options()): Iterator { $iternum = 0; foreach ($listApplied as $filename => $_) { - if ($args->limit > 0 && $iternum >= $args->limit) { + if ($options->limit > 0 && $iternum >= $options->limit) { return; } @@ -82,11 +82,11 @@ public function down(array $listApplied, Args $args = new Args()): Iterator * @return Iterator * @throws ConfigurationException */ - public function fixture(Args $args = new Args()): Iterator + public function fixture(Options $options = new Options()): Iterator { $iternum = 0; foreach ($this->makeIterator(joinBasename($this->path, '-fixture')) as $matchFilename) { - if ($args->limit > 0 && $iternum >= $args->limit) { + if ($options->limit > 0 && $iternum >= $options->limit) { return; } diff --git a/src/internal/filesystem/Args.php b/src/internal/filesystem/Options.php similarity index 74% rename from src/internal/filesystem/Args.php rename to src/internal/filesystem/Options.php index 0e39703..8708404 100644 --- a/src/internal/filesystem/Args.php +++ b/src/internal/filesystem/Options.php @@ -4,12 +4,12 @@ namespace kuaukutsu\poc\migration\internal\filesystem; -use kuaukutsu\poc\migration\InputArgs; +use kuaukutsu\poc\migration\InputOptions; /** * @psalm-internal kuaukutsu\poc\migration */ -final readonly class Args +final readonly class Options { /** * @param non-negative-int $limit @@ -20,7 +20,7 @@ public function __construct( assert($this->limit >= 0); } - public static function makeFromInput(InputArgs $args): self + public static function makeFromInput(InputOptions $args): self { return new self( limit: $args->limit, diff --git a/src/template/Factory.php b/src/template/Factory.php index e715038..d2e82d3 100644 --- a/src/template/Factory.php +++ b/src/template/Factory.php @@ -20,12 +20,12 @@ public function makeName(string $name): string #[Override] public function makeBody(): string { - return << 1, ]; - $iterator = $this->fs->down($savedFilenames, new Args(limit: 1)); + $iterator = $this->fs->down($savedFilenames, new Options(limit: 1)); self::assertTrue($iterator->valid()); $files = []; @@ -52,7 +52,7 @@ public function testLimit(): void self::assertCount(1, $files); self::assertEquals('202501011024_entity_create.sql', $files[0]); - $iterator = $this->fs->up([], new Args(limit: 2)); + $iterator = $this->fs->up([], new Options(limit: 2)); self::assertTrue($iterator->valid()); $files = []; @@ -69,7 +69,7 @@ public function testLimitSkipZero(): void { $savedFilenames = ['202501011024_entity_create.sql' => 1]; - $iterator = $this->fs->down($savedFilenames, new Args(limit: 0)); + $iterator = $this->fs->down($savedFilenames, new Options(limit: 0)); self::assertTrue($iterator->valid()); self::assertNotEmpty(iterator_count($iterator)); } diff --git a/tests/internal/FilesFixtureTest.php b/tests/internal/FilesFixtureTest.php index 7a1e8bd..d7a11ef 100644 --- a/tests/internal/FilesFixtureTest.php +++ b/tests/internal/FilesFixtureTest.php @@ -8,7 +8,7 @@ use PHPUnit\Framework\TestCase; use kuaukutsu\poc\migration\exception\ConfigurationException; use kuaukutsu\poc\migration\internal\filesystem\Action; -use kuaukutsu\poc\migration\internal\filesystem\Args; +use kuaukutsu\poc\migration\internal\filesystem\Options; final class FilesFixtureTest extends TestCase { @@ -34,7 +34,7 @@ public function testFixture(): void public function testLimit(): void { - $iterator = $this->fs->fixture(new Args(limit: 1)); + $iterator = $this->fs->fixture(new Options(limit: 1)); self::assertTrue($iterator->valid()); $files = []; @@ -45,7 +45,7 @@ public function testLimit(): void self::assertCount(1, $files); self::assertEquals('202501011024_entity_base.sql', $files[0]); - $iterator = $this->fs->fixture(new Args(limit: 2)); + $iterator = $this->fs->fixture(new Options(limit: 2)); self::assertTrue($iterator->valid()); $files = []; @@ -60,7 +60,7 @@ public function testLimit(): void public function testLimitSkipZero(): void { - $iterator = $this->fs->fixture(new Args(limit: 0)); + $iterator = $this->fs->fixture(new Options(limit: 0)); self::assertTrue($iterator->valid()); self::assertNotEmpty(iterator_count($iterator)); } diff --git a/tests/internal/FilesUpTest.php b/tests/internal/FilesUpTest.php index d35cfd5..2d93800 100644 --- a/tests/internal/FilesUpTest.php +++ b/tests/internal/FilesUpTest.php @@ -8,7 +8,7 @@ use PHPUnit\Framework\TestCase; use kuaukutsu\poc\migration\exception\ConfigurationException; use kuaukutsu\poc\migration\internal\filesystem\Action; -use kuaukutsu\poc\migration\internal\filesystem\Args; +use kuaukutsu\poc\migration\internal\filesystem\Options; final class FilesUpTest extends TestCase { @@ -34,7 +34,7 @@ public function testUp(): void public function testLimit(): void { - $iterator = $this->fs->up([], new Args(limit: 1)); + $iterator = $this->fs->up([], new Options(limit: 1)); self::assertTrue($iterator->valid()); $files = []; @@ -45,7 +45,7 @@ public function testLimit(): void self::assertCount(1, $files); self::assertEquals('202501011024_entity_create.sql', $files[0]); - $iterator = $this->fs->up([], new Args(limit: 2)); + $iterator = $this->fs->up([], new Options(limit: 2)); self::assertTrue($iterator->valid()); $files = []; @@ -60,7 +60,7 @@ public function testLimit(): void public function testLimitSkipZero(): void { - $iterator = $this->fs->up([], new Args(limit: 0)); + $iterator = $this->fs->up([], new Options(limit: 0)); self::assertTrue($iterator->valid()); self::assertNotEmpty(iterator_count($iterator)); } diff --git a/tests/stub/TestCommand.php b/tests/stub/TestCommand.php index 0128c17..74befd5 100644 --- a/tests/stub/TestCommand.php +++ b/tests/stub/TestCommand.php @@ -5,8 +5,8 @@ namespace kuaukutsu\poc\migration\tests\stub; use Override; -use kuaukutsu\poc\migration\internal\command; -use kuaukutsu\poc\migration\internal\command\CommandInterface; +use kuaukutsu\poc\migration\command\CommandInterface; +use kuaukutsu\poc\migration\command\Options; use kuaukutsu\poc\migration\Context; final readonly class TestCommand implements CommandInterface @@ -17,10 +17,10 @@ public function __construct( } #[Override] - public function fetchApplied(command\Args $args = new command\Args()): array + public function fetchApplied(Options $options = new Options()): array { - if ($args->limit > 0) { - return array_slice($this->storage->getMigration(), 0, $args->limit); + if ($options->limit > 0) { + return array_slice($this->storage->getMigration(), 0, $options->limit); } return $this->storage->getMigration(); diff --git a/tests/stub/TestDriver.php b/tests/stub/TestDriver.php index 2792323..11408a4 100644 --- a/tests/stub/TestDriver.php +++ b/tests/stub/TestDriver.php @@ -5,9 +5,9 @@ namespace kuaukutsu\poc\migration\tests\stub; use Override; +use kuaukutsu\poc\migration\command\CommandInterface; use kuaukutsu\poc\migration\connection\DriverInterface; -use kuaukutsu\poc\migration\internal\command\CommandInterface; -use kuaukutsu\poc\migration\internal\command\Params; +use kuaukutsu\poc\migration\Config; final readonly class TestDriver implements DriverInterface { @@ -21,7 +21,7 @@ public function getName(): string return 'test'; } - public function getDbName(): string + public function getSourceName(): string { return 'storage'; } @@ -33,7 +33,7 @@ public function getSetupPath(): string } #[Override] - public function makeCommand(Params $params): CommandInterface + public function makeCommand(Config $config): CommandInterface { return new TestCommand($this->storage); } diff --git a/tests/workflow/ArgumentsTest.php b/tests/workflow/ArgumentsTest.php index a7087bf..0590d4b 100644 --- a/tests/workflow/ArgumentsTest.php +++ b/tests/workflow/ArgumentsTest.php @@ -6,13 +6,13 @@ use Override; use PHPUnit\Framework\TestCase; +use kuaukutsu\poc\migration\command\CommandInterface; use kuaukutsu\poc\migration\exception\ConfigurationException; -use kuaukutsu\poc\migration\internal\command\CommandInterface; -use kuaukutsu\poc\migration\internal\command\Params; use kuaukutsu\poc\migration\internal\connection\PDO\Driver; use kuaukutsu\poc\migration\tests\MigratorFactory; +use kuaukutsu\poc\migration\Config; +use kuaukutsu\poc\migration\InputOptions; use kuaukutsu\poc\migration\MigratorInterface; -use kuaukutsu\poc\migration\InputArgs; /** * Верхнеуровневая работа приложения. @@ -31,7 +31,7 @@ protected function setUp(): void ); $this->migrator = MigratorFactory::makeFromDriver($driver); - $this->command = $driver->makeCommand(new Params(table: 'migration')); + $this->command = $driver->makeCommand(new Config(table: 'migration')); } public function testUpWithLimit(): void @@ -40,12 +40,12 @@ public function testUpWithLimit(): void $data = $this->command->fetchApplied(); self::assertEmpty($data); - $this->migrator->up(new InputArgs(limit: 1)); + $this->migrator->up(new InputOptions(limit: 1)); $data = $this->command->fetchApplied(); self::assertCount(1, $data); self::assertNotEmpty($data['202501011024_entity_create.sql']); - $this->migrator->up(new InputArgs(limit: 2)); + $this->migrator->up(new InputOptions(limit: 2)); $data = $this->command->fetchApplied(); self::assertCount(3, $data); @@ -64,11 +64,11 @@ public function testDownWithLimit(): void $this->migrator->up(); - $this->migrator->down(new InputArgs(limit: 1)); + $this->migrator->down(new InputOptions(limit: 1)); $data = $this->command->fetchApplied(); self::assertCount(2, $data); - $this->migrator->down(new InputArgs(limit: 2)); + $this->migrator->down(new InputOptions(limit: 2)); $data = $this->command->fetchApplied(); self::assertEmpty($data); } @@ -83,7 +83,7 @@ public function testWithDryRun(): void $data = $this->command->fetchApplied(); self::assertCount(3, $data); - $this->migrator->down(new InputArgs(dryRun: true)); + $this->migrator->down(new InputOptions(dryRun: true)); $data = $this->command->fetchApplied(); self::assertCount(3, $data); @@ -98,7 +98,7 @@ public function testWithDb(): void $data = $this->command->fetchApplied(); self::assertEmpty($data); - $this->migrator->up(new InputArgs(limit: 2, dbName: 'sqlite/memory')); + $this->migrator->up(new InputOptions(limit: 2, dbName: 'sqlite/memory')); $data = $this->command->fetchApplied(); self::assertCount(2, $data); } @@ -108,7 +108,7 @@ public function testWithUnknownDb(): void $this->migrator->init(); $this->expectException(ConfigurationException::class); - $this->migrator->up(new InputArgs(dbName: 'sqlite/unknown')); + $this->migrator->up(new InputOptions(dbName: 'sqlite/unknown')); } public function testDownWithVersion(): void @@ -117,7 +117,7 @@ public function testDownWithVersion(): void $data = $this->command->fetchApplied(); self::assertEmpty($data); - $this->migrator->up(new InputArgs(limit: 2)); + $this->migrator->up(new InputOptions(limit: 2)); $data = $this->command->fetchApplied(); self::assertCount(2, $data); @@ -125,12 +125,12 @@ public function testDownWithVersion(): void self::assertGreaterThan(0, $version); // not found version - $this->migrator->down(new InputArgs(version: 2)); + $this->migrator->down(new InputOptions(version: 2)); $data = $this->command->fetchApplied(); self::assertCount(2, $data); // down with version - $this->migrator->down(new InputArgs(version: $version)); + $this->migrator->down(new InputOptions(version: $version)); $data = $this->command->fetchApplied(); self::assertEmpty($data); } @@ -141,7 +141,7 @@ public function testDownWithLatestVersion(): void $data = $this->command->fetchApplied(); self::assertEmpty($data); - $args = new InputArgs(limit: 1); + $args = new InputOptions(limit: 1); self::assertFalse($args->hasApplyLatestVersion()); $this->migrator->up($args); @@ -158,16 +158,16 @@ public function testDownWithLatestVersion(): void $data = $this->command->fetchApplied(); self::assertCount(3, $data); - $args = new InputArgs(); + $args = new InputOptions(); self::assertFalse($args->hasApplyLatestVersion()); - $args = new InputArgs(version: 111, applyLatestVersion: true); + $args = new InputOptions(version: 111, applyLatestVersion: true); self::assertFalse($args->hasApplyLatestVersion()); - $args = new InputArgs(limit: 1, applyLatestVersion: true); + $args = new InputOptions(limit: 1, applyLatestVersion: true); self::assertFalse($args->hasApplyLatestVersion()); - $args = new InputArgs(applyLatestVersion: true); + $args = new InputOptions(applyLatestVersion: true); self::assertTrue($args->hasApplyLatestVersion()); // down with latest version diff --git a/tests/workflow/CommandTest.php b/tests/workflow/CommandTest.php index ae62aff..8d47605 100644 --- a/tests/workflow/CommandTest.php +++ b/tests/workflow/CommandTest.php @@ -10,12 +10,12 @@ use PDOException; use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\TestCase; -use kuaukutsu\poc\migration\internal\command\Args; -use kuaukutsu\poc\migration\internal\command\Command; -use kuaukutsu\poc\migration\internal\command\CommandInterface; -use kuaukutsu\poc\migration\internal\command\Params; +use kuaukutsu\poc\migration\command\CommandInterface; +use kuaukutsu\poc\migration\command\Options; +use kuaukutsu\poc\migration\internal\action\Command; use kuaukutsu\poc\migration\internal\connection\PDO\Connection; use kuaukutsu\poc\migration\internal\connection\PDO\Type; +use kuaukutsu\poc\migration\Config; use kuaukutsu\poc\migration\Context; final class CommandTest extends TestCase @@ -27,7 +27,7 @@ protected function setUp(): void { $this->command = new Command( new Connection(new PDO(dsn: 'sqlite::memory:'), Type::PDO_SQLITE), - new Params(table: 'migration'), + new Config(table: 'migration'), ); } @@ -96,13 +96,13 @@ public function testFetchLimit(): void $this->execUp('table3'); $data = $this->command->fetchApplied( - new Args(limit: 1) + new Options(limit: 1) ); self::assertCount(1, $data); self::assertNotEmpty($data['test-table3']); $data = $this->command->fetchApplied( - new Args(limit: 2) + new Options(limit: 2) ); self::assertCount(2, $data); @@ -125,21 +125,21 @@ public function testFetchVersion(): void $this->execUp('table3', 222); $data = $this->command->fetchApplied( - new Args(version: 111) + new Options(version: 111) ); self::assertCount(2, $data); self::assertNotEmpty($data['test-table1']); self::assertNotEmpty($data['test-table2']); $data = $this->command->fetchApplied( - new Args(version: 222) + new Options(version: 222) ); self::assertCount(1, $data); self::assertNotEmpty($data['test-table3']); // сомнительный кейс, но допускаем $data = $this->command->fetchApplied( - new Args(limit: 1, version: 111) + new Options(limit: 1, version: 111) ); self::assertCount(1, $data); self::assertNotEmpty($data['test-table2']); diff --git a/tests/workflow/ConfigurationTest.php b/tests/workflow/ConfigurationTest.php index a7c0687..eb6d0bd 100644 --- a/tests/workflow/ConfigurationTest.php +++ b/tests/workflow/ConfigurationTest.php @@ -6,13 +6,13 @@ use PHPUnit\Framework\TestCase; use kuaukutsu\poc\migration\exception\ActionException; -use kuaukutsu\poc\migration\exception\ConnectionException; use kuaukutsu\poc\migration\exception\ConfigurationException; +use kuaukutsu\poc\migration\exception\ConnectionException; use kuaukutsu\poc\migration\exception\InitializationException; -use kuaukutsu\poc\migration\internal\command\Params; use kuaukutsu\poc\migration\internal\connection\PDO\Driver; use kuaukutsu\poc\migration\tests\MigratorFactory; -use kuaukutsu\poc\migration\InputArgs; +use kuaukutsu\poc\migration\Config; +use kuaukutsu\poc\migration\InputOptions; final class ConfigurationTest extends TestCase { @@ -67,11 +67,11 @@ public function testActionNotExceptionDryRun(): void { $driver = new Driver(dsn: 'sqlite::memory:'); $migrator = MigratorFactory::makeFromEvent($driver); - $command = $driver->makeCommand(new Params(table: 'migration')); + $command = $driver->makeCommand(new Config(table: 'migration')); $migrator->init(); - $migrator->up(new InputArgs(dryRun: true)); + $migrator->up(new InputOptions(dryRun: true)); $data = $command->fetchApplied(); self::assertEmpty($data); } @@ -114,6 +114,6 @@ public function testCreateMigrationNameException(): void $this->expectException(ConfigurationException::class); $this->expectExceptionMessage('Migration Name must be declared.'); - $migrator->create(new InputArgs(dbName: 'test')); + $migrator->create(new InputOptions(dbName: 'test')); } } diff --git a/tests/workflow/CreateTest.php b/tests/workflow/CreateTest.php index 7cbe617..4b084f0 100644 --- a/tests/workflow/CreateTest.php +++ b/tests/workflow/CreateTest.php @@ -6,11 +6,11 @@ use Override; use PHPUnit\Framework\TestCase; -use kuaukutsu\poc\migration\internal\command\Params; -use kuaukutsu\poc\migration\internal\connection\PDO\Driver; use kuaukutsu\poc\migration\exception\ConfigurationException; +use kuaukutsu\poc\migration\internal\connection\PDO\Driver; use kuaukutsu\poc\migration\tests\MigratorFactory; -use kuaukutsu\poc\migration\InputArgs; +use kuaukutsu\poc\migration\Config; +use kuaukutsu\poc\migration\InputOptions; final class CreateTest extends TestCase { @@ -22,15 +22,15 @@ public function testCreate(): void $path = dirname(__DIR__) . '/migration/sqlite/memory'; $migrator = MigratorFactory::makeFromEvent(driver: $driver, path: $path); - $command = $driver->makeCommand(new Params(table: 'migration')); + $command = $driver->makeCommand(new Config(table: 'migration')); $migrator->init(); $migrator->up(); $countMigration = count($command->fetchApplied()); - $migrator->create(new InputArgs(dbName: 'sqlite/memory', migrationName: 'test')); - $migrator->create(new InputArgs(dbName: 'sqlite/memory', migrationName: '2test')); + $migrator->create(new InputOptions(dbName: 'sqlite/memory', migrationName: 'test')); + $migrator->create(new InputOptions(dbName: 'sqlite/memory', migrationName: '2test')); $migrator->up(); self::assertCount($countMigration + 2, $command->fetchApplied()); @@ -48,7 +48,7 @@ public function testCreateException(): void $this->expectException(ConfigurationException::class); $this->expectExceptionMessageMatches('/^the dir .+ is not writable or does not exist.$/i'); - $migrator->create(new InputArgs(dbName: 'sqlite/memory', migrationName: 'test')); + $migrator->create(new InputOptions(dbName: 'sqlite/memory', migrationName: 'test')); } #[Override] diff --git a/tests/workflow/EventTest.php b/tests/workflow/EventTest.php index 68b4753..5b0df19 100644 --- a/tests/workflow/EventTest.php +++ b/tests/workflow/EventTest.php @@ -8,7 +8,7 @@ use PHPUnit\Framework\TestCase; use kuaukutsu\poc\migration\internal\connection\PDO\Driver; use kuaukutsu\poc\migration\event\Event; -use kuaukutsu\poc\migration\InputArgs; +use kuaukutsu\poc\migration\InputOptions; use kuaukutsu\poc\migration\tests\MigratorFactory; use kuaukutsu\poc\migration\tests\stub\TestSubscriber; @@ -28,7 +28,7 @@ public function testSelectDatabaseError(): void try { $migrator->init(); - $migrator->up(new InputArgs(dbName: 'test')); + $migrator->up(new InputOptions(dbName: 'test')); } catch (Throwable) { } @@ -131,7 +131,7 @@ public function testMigrationDryRun(): void $migrator->init(); try { - $migrator->up(new InputArgs(dryRun: true)); + $migrator->up(new InputOptions(dryRun: true)); } catch (Throwable) { } @@ -160,7 +160,7 @@ public function testMigrationFilesystemNotice(): void ); $migrator->init(); - $migrator->up(new InputArgs(limit: 1, hasRepeatable: true)); + $migrator->up(new InputOptions(limit: 1, hasRepeatable: true)); // event-repeatable: does not exist self::assertStringContainsString( @@ -256,7 +256,7 @@ public function testCreateDirectoryDoesNotExistError(): void $migrator->init(); try { - $migrator->create(new InputArgs(dbName: 'sqlite/memory', migrationName: 'test')); + $migrator->create(new InputOptions(dbName: 'sqlite/memory', migrationName: 'test')); } catch (Throwable) { } diff --git a/tests/workflow/MigrationTest.php b/tests/workflow/MigrationTest.php index 2de1f77..1b7780a 100644 --- a/tests/workflow/MigrationTest.php +++ b/tests/workflow/MigrationTest.php @@ -7,12 +7,12 @@ use Override; use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\TestCase; -use kuaukutsu\poc\migration\internal\command\CommandInterface; -use kuaukutsu\poc\migration\internal\command\Params; +use kuaukutsu\poc\migration\command\CommandInterface; use kuaukutsu\poc\migration\internal\connection\PDO\Driver; use kuaukutsu\poc\migration\tests\MigratorFactory; +use kuaukutsu\poc\migration\Config; +use kuaukutsu\poc\migration\InputOptions; use kuaukutsu\poc\migration\MigratorInterface; -use kuaukutsu\poc\migration\InputArgs; /** * Верхнеуровневая работа приложения. @@ -31,7 +31,7 @@ protected function setUp(): void ); $this->migrator = MigratorFactory::makeFromDriver($driver); - $this->command = $driver->makeCommand(new Params(table: 'migration')); + $this->command = $driver->makeCommand(new Config(table: 'migration')); } public function testInit(): void @@ -106,7 +106,7 @@ public function testVerify(): void { $this->migrator->init(); - $this->migrator->up(new InputArgs(limit: 1)); + $this->migrator->up(new InputOptions(limit: 1)); $data = $this->command->fetchApplied(); self::assertCount(1, $data); diff --git a/tests/workflow/PdoDriverTest.php b/tests/workflow/PdoDriverTest.php index bd4230f..2d71136 100644 --- a/tests/workflow/PdoDriverTest.php +++ b/tests/workflow/PdoDriverTest.php @@ -17,28 +17,28 @@ public function testTypeDriver(): void ); self::assertEquals('pgsql', $driver->getName()); - self::assertEquals('main', $driver->getDbName()); + self::assertEquals('main', $driver->getSourceName()); $driver = new Driver( dsn: 'MYSQL:host=mysql;dbname=copyDb', ); self::assertEquals('mysql', $driver->getName()); - self::assertEquals('copydb', $driver->getDbName()); + self::assertEquals('copydb', $driver->getSourceName()); $driver = new Driver( dsn: 'sqlite::memory:', ); self::assertEquals('sqlite', $driver->getName()); - self::assertEquals('memory', $driver->getDbName()); + self::assertEquals('memory', $driver->getSourceName()); $driver = new Driver( dsn: 'sqlite:tests/data/sqlite/db.sqlite3', ); self::assertEquals('sqlite', $driver->getName()); - self::assertEquals('db', $driver->getDbName()); + self::assertEquals('db', $driver->getSourceName()); } public function testConfigurationException(): void diff --git a/tests/workflow/UpExactlyTest.php b/tests/workflow/UpExactlyTest.php index f72fed7..09ea4d3 100644 --- a/tests/workflow/UpExactlyTest.php +++ b/tests/workflow/UpExactlyTest.php @@ -6,13 +6,13 @@ use Override; use PHPUnit\Framework\TestCase; -use kuaukutsu\poc\migration\internal\connection\PDO\Driver; +use kuaukutsu\poc\migration\command\CommandInterface; use kuaukutsu\poc\migration\exception\ActionException; -use kuaukutsu\poc\migration\internal\command\CommandInterface; -use kuaukutsu\poc\migration\internal\command\Params; +use kuaukutsu\poc\migration\internal\connection\PDO\Driver; use kuaukutsu\poc\migration\tests\MigratorFactory; +use kuaukutsu\poc\migration\Config; +use kuaukutsu\poc\migration\InputOptions; use kuaukutsu\poc\migration\MigratorInterface; -use kuaukutsu\poc\migration\InputArgs; final class UpExactlyTest extends TestCase { @@ -28,7 +28,7 @@ protected function setUp(): void ); $this->migrator = MigratorFactory::makeFromEvent($driver); - $this->command = $driver->makeCommand(new Params(table: 'migration')); + $this->command = $driver->makeCommand(new Config(table: 'migration')); } public function testUpExactlyAll(): void @@ -37,7 +37,7 @@ public function testUpExactlyAll(): void $data = $this->command->fetchApplied(); self::assertEmpty($data); - $this->migrator->up(new InputArgs(limit: 1)); + $this->migrator->up(new InputOptions(limit: 1)); $data = $this->command->fetchApplied(); self::assertCount(1, $data); @@ -59,7 +59,7 @@ public function testUpExactlyAll(): void self::assertEmpty($data); try { - $this->migrator->up(new InputArgs(exactlyAll: true)); + $this->migrator->up(new InputOptions(exactlyAll: true)); } catch (ActionException) { } @@ -77,7 +77,7 @@ public function testUpExactlyAllException(): void 'SQLSTATE[HY000]: General error: 1 no such table:' ); - $this->migrator->up(new InputArgs(exactlyAll: true)); + $this->migrator->up(new InputOptions(exactlyAll: true)); } public function testVerify(): void @@ -86,7 +86,7 @@ public function testVerify(): void $data = $this->command->fetchApplied(); self::assertEmpty($data); - $this->migrator->up(new InputArgs(limit: 1)); + $this->migrator->up(new InputOptions(limit: 1)); $data = $this->command->fetchApplied(); self::assertCount(1, $data); diff --git a/tests/workflow/WorkflowTest.php b/tests/workflow/WorkflowTest.php index 0f74388..c5ad699 100644 --- a/tests/workflow/WorkflowTest.php +++ b/tests/workflow/WorkflowTest.php @@ -11,7 +11,7 @@ use kuaukutsu\poc\migration\tests\stub\TestDriver; use kuaukutsu\poc\migration\tests\stub\TestStorage; use kuaukutsu\poc\migration\tests\MigratorFactory; -use kuaukutsu\poc\migration\InputArgs; +use kuaukutsu\poc\migration\InputOptions; use kuaukutsu\poc\migration\MigratorInterface; /** @@ -72,7 +72,7 @@ public function testUp(): void public function testUpWithRepeatable(): void { - $this->migrator->up(new InputArgs(hasRepeatable: true)); + $this->migrator->up(new InputOptions(hasRepeatable: true)); // repeatable self::assertStringContainsString(