From b0ce83d617a7d168f0ab381d300c1e1de17284dc Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Thu, 9 Nov 2023 18:02:10 +0700 Subject: [PATCH] Add set prefix to MigrationService setters (#231) --- src/Command/CreateCommand.php | 6 +++--- src/Command/NewCommand.php | 4 ++-- src/Command/UpdateCommand.php | 4 ++-- src/Service/MigrationService.php | 18 +++++++++--------- .../Command/AbstractCreateCommandTest.php | 8 ++++---- .../Command/AbstractUpdateCommandTest.php | 4 ++-- .../Service/AbstractMigrationServiceTest.php | 2 +- tests/Support/Helper/MigrationHelper.php | 16 ++++++++-------- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/Command/CreateCommand.php b/src/Command/CreateCommand.php index 97458568..fe87ac38 100644 --- a/src/Command/CreateCommand.php +++ b/src/Command/CreateCommand.php @@ -59,7 +59,7 @@ * ./yii migrate:create post --command=table --path=@root/migrations/blog * ``` * - * In case {@see createPath} is not set and no namespace is provided, {@see createNamespace} will be used. + * In case {@see $createPath} is not set and no namespace is provided, {@see $createNamespace} will be used. */ #[AsCommand('migrate:create', 'Creates a new migration.')] final class CreateCommand extends Command @@ -101,8 +101,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $namespace = $input->getOption('namespace'); if ($path !== null || $namespace !== null) { - $this->migrationService->createPath((string) $path); - $this->migrationService->createNamespace((string) $namespace); + $this->migrationService->setCreatePath((string) $path); + $this->migrationService->setCreateNamespace((string) $namespace); } else { $namespace = $this->migrationService->getCreateNamespace(); } diff --git a/src/Command/NewCommand.php b/src/Command/NewCommand.php index 7c26fba4..e2e1a860 100644 --- a/src/Command/NewCommand.php +++ b/src/Command/NewCommand.php @@ -66,8 +66,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $namespaces = $input->getOption('namespace'); if (!empty($paths) || !empty($namespaces)) { - $this->migrationService->updatePaths($paths); - $this->migrationService->updateNamespaces($namespaces); + $this->migrationService->setUpdatePaths($paths); + $this->migrationService->setUpdateNamespaces($namespaces); } $this->migrationService->before(self::getDefaultName() ?? ''); diff --git a/src/Command/UpdateCommand.php b/src/Command/UpdateCommand.php index f68be8f6..ffbdbc14 100644 --- a/src/Command/UpdateCommand.php +++ b/src/Command/UpdateCommand.php @@ -70,8 +70,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $namespaces = $input->getOption('namespace'); if (!empty($paths) || !empty($namespaces)) { - $this->migrationService->updatePaths($paths); - $this->migrationService->updateNamespaces($namespaces); + $this->migrationService->setUpdatePaths($paths); + $this->migrationService->setUpdateNamespaces($namespaces); } if ($this->migrationService->before(self::getDefaultName() ?? '') === Command::INVALID) { diff --git a/src/Service/MigrationService.php b/src/Service/MigrationService.php index 6b96b7a4..ba3221c3 100644 --- a/src/Service/MigrationService.php +++ b/src/Service/MigrationService.php @@ -70,8 +70,8 @@ public function setIO(?SymfonyStyle $io): void /** * This method is invoked right before an action is to be executed (after all possible filters.) * - * It checks the existence of the {@see createPath}, {@see updatePaths}, {@see createNamespace}, - * {@see updateNamespaces}. + * It checks the existence of the {@see $createPath}, {@see $updatePaths}, {@see $createNamespace}, + * {@see $updateNamespaces}. * * @return int Whether the action should continue to be executed. */ @@ -182,7 +182,7 @@ public function getNewMigrations(): array * * @psalm-param string[] $value */ - public function updateNamespaces(array $value): void + public function setUpdateNamespaces(array $value): void { $this->updateNamespaces = $value; } @@ -193,12 +193,12 @@ public function updateNamespaces(array $value): void * This can be either a [path alias](guide:concept-aliases) or a directory path. * * Migration classes located at this path should be declared without a namespace. - * Use {@see createNamespace} property in case you are using namespaced migrations. + * Use {@see $createNamespace} property in case you are using namespaced migrations. * - * If you have set up {@see createNamespace}, you may set this field to `null` in order to disable usage of migrations + * If you have set up {@see $createNamespace}, you may set this field to `null` in order to disable usage of migrations * that are not namespaced. * - * In general, to load migrations from different locations, {@see createNamespace} is the preferable solution as the + * In general, to load migrations from different locations, {@see $createNamespace} is the preferable solution as the * migration name contains the origin of the migration in the history, which is not the case when using multiple * migration paths. * @@ -207,7 +207,7 @@ public function updateNamespaces(array $value): void * * @psalm-param string[] $value */ - public function updatePaths(array $value): void + public function setUpdatePaths(array $value): void { $this->updatePaths = $value; } @@ -318,12 +318,12 @@ public function makeRevertibleMigrations(array $classes): array ); } - public function createNamespace(string $value): void + public function setCreateNamespace(string $value): void { $this->createNamespace = $value; } - public function createPath(string $value): void + public function setCreatePath(string $value): void { $this->createPath = $value; } diff --git a/tests/Common/Command/AbstractCreateCommandTest.php b/tests/Common/Command/AbstractCreateCommandTest.php index caaec379..b306a5d9 100644 --- a/tests/Common/Command/AbstractCreateCommandTest.php +++ b/tests/Common/Command/AbstractCreateCommandTest.php @@ -996,7 +996,7 @@ public function testIncorrectCreatePath(): void { MigrationHelper::useMigrationsPath($this->container); - $this->container->get(MigrationService::class)->createPath(__DIR__ . '/not-exists'); + $this->container->get(MigrationService::class)->setCreatePath(__DIR__ . '/not-exists'); $command = $this->createCommand($this->container); $command->setInputs(['yes']); @@ -1012,7 +1012,7 @@ public function testWithoutCreatePath(): void { MigrationHelper::useMigrationsPath($this->container); - $this->container->get(MigrationService::class)->createPath(''); + $this->container->get(MigrationService::class)->setCreatePath(''); $command = $this->createCommand($this->container); $command->setInputs(['yes']); @@ -1032,7 +1032,7 @@ public function testIncorrectCreateNamespace(): void MigrationHelper::useMigrationsNamespace($this->container); $this->container->get(MigrationService::class) - ->createNamespace('Yiisoft\\Db\\Migration\\TestsRuntime\\NotExists'); + ->setCreateNamespace('Yiisoft\\Db\\Migration\\TestsRuntime\\NotExists'); $command = $this->createCommand($this->container); $command->setInputs(['yes']); @@ -1048,7 +1048,7 @@ public function testWithoutCreateNamespace(): void { MigrationHelper::useMigrationsNamespace($this->container); - $this->container->get(MigrationService::class)->createNamespace(''); + $this->container->get(MigrationService::class)->setCreateNamespace(''); $command = $this->createCommand($this->container); $command->setInputs(['yes']); diff --git a/tests/Common/Command/AbstractUpdateCommandTest.php b/tests/Common/Command/AbstractUpdateCommandTest.php index 5e912d61..7bcdfbb3 100644 --- a/tests/Common/Command/AbstractUpdateCommandTest.php +++ b/tests/Common/Command/AbstractUpdateCommandTest.php @@ -271,7 +271,7 @@ public function testWithoutUpdatePath(): void { MigrationHelper::useMigrationsPath($this->container); - $this->container->get(MigrationService::class)->updatePaths([]); + $this->container->get(MigrationService::class)->setUpdatePaths([]); $command = $this->createCommand($this->container); $command->setInputs(['yes']); @@ -290,7 +290,7 @@ public function testWithoutUpdateNamespaces(): void { MigrationHelper::useMigrationsNamespace($this->container); - $this->container->get(MigrationService::class)->updateNamespaces([]); + $this->container->get(MigrationService::class)->setUpdateNamespaces([]); $command = $this->createCommand($this->container); $command->setInputs(['yes']); diff --git a/tests/Common/Service/AbstractMigrationServiceTest.php b/tests/Common/Service/AbstractMigrationServiceTest.php index 082ec9ee..e0472d94 100644 --- a/tests/Common/Service/AbstractMigrationServiceTest.php +++ b/tests/Common/Service/AbstractMigrationServiceTest.php @@ -46,7 +46,7 @@ public function testGetNewMigrationsWithNotExistNamespace(): void $service = $this->container->get(MigrationService::class); - $service->updateNamespaces([ + $service->setUpdateNamespaces([ MigrationHelper::NAMESPACE, 'Yiisoft\\Db\\Migration\\TestsRuntime\\NotExists', ]); diff --git a/tests/Support/Helper/MigrationHelper.php b/tests/Support/Helper/MigrationHelper.php index 6dfea2e6..a29ae50b 100644 --- a/tests/Support/Helper/MigrationHelper.php +++ b/tests/Support/Helper/MigrationHelper.php @@ -26,8 +26,8 @@ public static function useMigrationsPath(ContainerInterface $container): string { $service = $container->get(MigrationService::class); - $service->createPath(self::PATH_ALIAS); - $service->updatePaths([self::PATH_ALIAS]); + $service->setCreatePath(self::PATH_ALIAS); + $service->setUpdatePaths([self::PATH_ALIAS]); self::preparePaths($container); @@ -41,8 +41,8 @@ public static function useMigrationsNamespace(ContainerInterface $container): st { $service = $container->get(MigrationService::class); - $service->createNamespace(self::NAMESPACE); - $service->updateNamespaces([self::NAMESPACE]); + $service->setCreateNamespace(self::NAMESPACE); + $service->setUpdateNamespaces([self::NAMESPACE]); self::preparePaths($container); @@ -136,9 +136,9 @@ public static function resetPathAndNamespace(ContainerInterface $container): voi { $service = $container->get(MigrationService::class); - $service->createPath(''); - $service->updatePaths([]); - $service->createNamespace(''); - $service->updateNamespaces([]); + $service->setCreatePath(''); + $service->setUpdatePaths([]); + $service->setCreateNamespace(''); + $service->setUpdateNamespaces([]); } }