From b652038a9285064e3c99b0067e31d6337434413c Mon Sep 17 00:00:00 2001 From: ndm2 Date: Thu, 31 Aug 2023 16:34:06 +0200 Subject: [PATCH] Fix diff baking tests. #618 changed how the path for the baked files is being built. --- .../Command/BakeMigrationDiffCommandTest.php | 4 +-- .../CustomBakeMigrationDiffCommand.php | 25 ++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/TestCase/Command/BakeMigrationDiffCommandTest.php b/tests/TestCase/Command/BakeMigrationDiffCommandTest.php index 79afe675..94296961 100644 --- a/tests/TestCase/Command/BakeMigrationDiffCommandTest.php +++ b/tests/TestCase/Command/BakeMigrationDiffCommandTest.php @@ -227,9 +227,9 @@ protected function runDiffBakingTest(string $scenario): void $this->_compareBasePath = Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Diff' . DS . lcfirst($scenario) . DS; $bakeName = $this->getBakeName("TheDiff{$scenario}"); - $pathFragment = "MigrationsDiff{$scenario}"; + $targetFolder = "MigrationsDiff{$scenario}"; $comparison = lcfirst($scenario); - $this->exec("custom bake migration_diff {$bakeName} -c test_comparisons --path-fragment {$pathFragment} --comparison {$comparison}"); + $this->exec("custom bake migration_diff {$bakeName} -c test_comparisons --test-target-folder {$targetFolder} --comparison {$comparison}"); $this->generatedFiles[] = ROOT . DS . 'config' . DS . 'Migrations' . DS . 'schema-dump-test_comparisons.lock'; diff --git a/tests/test_app/App/Command/CustomBakeMigrationDiffCommand.php b/tests/test_app/App/Command/CustomBakeMigrationDiffCommand.php index 3274f860..b91c347c 100644 --- a/tests/test_app/App/Command/CustomBakeMigrationDiffCommand.php +++ b/tests/test_app/App/Command/CustomBakeMigrationDiffCommand.php @@ -12,8 +12,6 @@ class CustomBakeMigrationDiffCommand extends BakeMigrationDiffCommand { - public string $pathFragment = ''; - /** * @inheritDoc */ @@ -28,20 +26,35 @@ public static function defaultName(): string public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { return parent::buildOptionParser($parser) - ->addOption('path-fragment') + ->addOption('test-target-folder') ->addOption('comparison'); } public function execute(Arguments $args, ConsoleIo $io): ?int { - $pathFragment = $args->getOption('path-fragment'); - assert($pathFragment !== null); + $testTargetFolder = $args->getOption('test-target-folder'); + assert($testTargetFolder !== null); - $this->pathFragment = 'config' . DS . $pathFragment . DS; + $this->pathFragment = 'config' . DS . $testTargetFolder . DS; return parent::execute($args, $io); } + public function getPath(Arguments $args): string + { + // Avoids having to use the `source` option, as it would be passed down to + // other commands, causing a migration files lookup in the folder where + // the new migration has been baked, causing an error as a class with the + // same name will already exist from loading/applying the comparison diff. + + $path = ROOT . DS . $this->pathFragment; + if ($this->plugin) { + $path = $this->_pluginPath($this->plugin) . $this->pathFragment; + } + + return str_replace('/', DS, $path); + } + protected function getDumpSchema(Arguments $args): array { $comparison = $args->getOption('comparison');