Skip to content

Commit

Permalink
Merge pull request #644 from cakephp/4.x-fix-diff-baking-tests
Browse files Browse the repository at this point in the history
4.x - Fix diff baking tests.
  • Loading branch information
othercorey authored Sep 23, 2023
2 parents b76eefc + b652038 commit 7659d42
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions tests/TestCase/Command/BakeMigrationDiffCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
25 changes: 19 additions & 6 deletions tests/test_app/App/Command/CustomBakeMigrationDiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

class CustomBakeMigrationDiffCommand extends BakeMigrationDiffCommand
{
public string $pathFragment = '';

/**
* @inheritDoc
*/
Expand All @@ -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');
Expand Down

0 comments on commit 7659d42

Please sign in to comment.