diff --git a/src/Command/SeedCommand.php b/src/Command/SeedCommand.php index 8c74e25a..b7562809 100644 --- a/src/Command/SeedCommand.php +++ b/src/Command/SeedCommand.php @@ -21,6 +21,7 @@ use Exception; use Migrations\Config\ConfigInterface; use Migrations\Migration\ManagerFactory; +use Migrations\Util\Util; /** * Seed command runs seeder scripts @@ -182,11 +183,7 @@ protected function executeSeeds(Arguments $args, ConsoleIo $io): ?int $io->out(''); $io->out('The following seeds will be executed:'); foreach ($availableSeeds as $seed) { - $seedName = $seed->getName(); - if (str_ends_with($seedName, 'Seed')) { - $seedName = substr($seedName, 0, -4); - } - $io->out(' - ' . $seedName); + $io->out(' - ' . Util::getSeedDisplayName($seed->getName())); } $io->out(''); if (!(bool)$args->getOption('force')) { diff --git a/src/Command/SeedResetCommand.php b/src/Command/SeedResetCommand.php index 27461d10..18ef30b1 100644 --- a/src/Command/SeedResetCommand.php +++ b/src/Command/SeedResetCommand.php @@ -19,6 +19,7 @@ use Cake\Console\ConsoleOptionParser; use Migrations\Config\ConfigInterface; use Migrations\Migration\ManagerFactory; +use Migrations\Util\Util; /** * Seed reset command removes seeds from the execution log @@ -112,11 +113,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int $io->out(''); $io->out('All seeds will be reset:'); foreach ($seedsToReset as $seed) { - $seedName = $seed->getName(); - if (str_ends_with($seedName, 'Seed')) { - $seedName = substr($seedName, 0, -4); - } - $io->out(' - ' . $seedName); + $io->out(' - ' . Util::getSeedDisplayName($seed->getName())); } $io->out(''); @@ -132,14 +129,15 @@ public function execute(Arguments $args, ConsoleIo $io): ?int // Reset the seeds $count = 0; foreach ($seedsToReset as $seed) { + $seedName = Util::getSeedDisplayName($seed->getName()); if ($manager->isSeedExecuted($seed)) { if (!$config->isDryRun()) { $adapter->removeSeedFromLog($seed); } - $io->info("Reset: {$seed->getName()}"); + $io->info("Reset: {$seedName} seed"); $count++; } else { - $io->verbose("Skipped (not executed): {$seed->getName()}"); + $io->verbose("Skipped (not executed): {$seedName} seed"); } } diff --git a/src/Command/SeedStatusCommand.php b/src/Command/SeedStatusCommand.php index 6647a627..bf4038e1 100644 --- a/src/Command/SeedStatusCommand.php +++ b/src/Command/SeedStatusCommand.php @@ -20,6 +20,7 @@ use Cake\Core\Configure; use Migrations\Config\ConfigInterface; use Migrations\Migration\ManagerFactory; +use Migrations\Util\Util; /** * Seed status command shows which seeds have been executed @@ -129,8 +130,11 @@ public function execute(Arguments $args, ConsoleIo $io): ?int } } + // Strip 'Seed' suffix for display and add ' seed' suffix + $displayName = Util::getSeedDisplayName($seedName) . ' seed'; + $statuses[] = [ - 'seedName' => $seedName, + 'seedName' => $displayName, 'plugin' => $plugin, 'status' => $executed ? 'executed' : 'pending', 'executedAt' => $executedAt, diff --git a/src/Migration/Manager.php b/src/Migration/Manager.php index bb32ce69..963bd57f 100644 --- a/src/Migration/Manager.php +++ b/src/Migration/Manager.php @@ -620,7 +620,7 @@ protected function printMigrationStatus(MigrationInterface $migration, string $s protected function printSeedStatus(SeedInterface $seed, string $status, ?string $duration = null): void { $this->printStatusOutput( - $seed->getName(), + Util::getSeedDisplayName($seed->getName()) . ' seed', $status, $duration, ); diff --git a/src/Util/Util.php b/src/Util/Util.php index 90f101f9..e8138cd0 100644 --- a/src/Util/Util.php +++ b/src/Util/Util.php @@ -192,6 +192,23 @@ public static function isValidSeedFileName(string $fileName): bool return (bool)preg_match(static::SEED_FILE_NAME_PATTERN, $fileName); } + /** + * Get a human-readable display name for a seed class. + * + * Strips the 'Seed' suffix from class names like 'UsersSeed' to produce 'Users'. + * + * @param string $seedName The seed class name + * @return string The display name without the 'Seed' suffix + */ + public static function getSeedDisplayName(string $seedName): string + { + if (str_ends_with($seedName, 'Seed')) { + return substr($seedName, 0, -4); + } + + return $seedName; + } + /** * Expands a set of paths with curly braces (if supported by the OS). * diff --git a/tests/TestCase/Command/SeedCommandTest.php b/tests/TestCase/Command/SeedCommandTest.php index 9271b326..77935ae4 100644 --- a/tests/TestCase/Command/SeedCommandTest.php +++ b/tests/TestCase/Command/SeedCommandTest.php @@ -96,7 +96,7 @@ public function testSeederOne(): void $this->exec('seeds run -c test NumbersSeed'); $this->assertExitSuccess(); - $this->assertOutputContains('NumbersSeed: seeding'); + $this->assertOutputContains('Numbers seed: seeding'); $this->assertOutputContains('All Done'); /** @var \Cake\Database\Connection $connection */ @@ -110,8 +110,8 @@ public function testSeederBaseSeed(): void $this->createTables(); $this->exec('seeds run -c test --source BaseSeeds MigrationSeedNumbers'); $this->assertExitSuccess(); - $this->assertOutputContains('MigrationSeedNumbers: seeding'); - $this->assertOutputContains('AnotherNumbersSeed: seeding'); + $this->assertOutputContains('MigrationSeedNumbers seed: seeding'); + $this->assertOutputContains('AnotherNumbers seed: seeding'); $this->assertOutputContains('radix=10'); $this->assertOutputContains('fetchRow=121'); $this->assertOutputContains('hasTable=1'); @@ -154,8 +154,8 @@ public function testSeederMultiple(): void $this->exec('seeds run -c test --source CallSeeds LettersSeed,NumbersCallSeed'); $this->assertExitSuccess(); - $this->assertOutputContains('NumbersCallSeed: seeding'); - $this->assertOutputContains('LettersSeed: seeding'); + $this->assertOutputContains('NumbersCall seed: seeding'); + $this->assertOutputContains('Letters seed: seeding'); $this->assertOutputContains('All Done'); /** @var \Cake\Database\Connection $connection */ @@ -182,7 +182,7 @@ public function testSeederWithTimestampFields(): void $this->exec('seeds run -c test StoresSeed'); $this->assertExitSuccess(); - $this->assertOutputContains('StoresSeed: seeding'); + $this->assertOutputContains('Stores seed: seeding'); $this->assertOutputContains('All Done'); /** @var \Cake\Database\Connection $connection */ @@ -208,7 +208,7 @@ public function testDryRunModeWarning(): void $this->assertExitSuccess(); $this->assertOutputContains('DRY-RUN mode enabled'); - $this->assertOutputContains('NumbersSeed: seeding'); + $this->assertOutputContains('Numbers seed: seeding'); $this->assertOutputContains('All Done'); } @@ -219,7 +219,7 @@ public function testDryRunModeShortOption(): void $this->assertExitSuccess(); $this->assertOutputContains('DRY-RUN mode enabled'); - $this->assertOutputContains('NumbersSeed: seeding'); + $this->assertOutputContains('Numbers seed: seeding'); $this->assertOutputContains('All Done'); } @@ -245,8 +245,8 @@ public function testDryRunModeMultipleSeeds(): void $this->assertExitSuccess(); $this->assertOutputContains('DRY-RUN mode enabled'); - $this->assertOutputContains('NumbersCallSeed: seeding'); - $this->assertOutputContains('LettersSeed: seeding'); + $this->assertOutputContains('NumbersCall seed: seeding'); + $this->assertOutputContains('Letters seed: seeding'); $this->assertOutputContains('All Done'); /** @var \Cake\Database\Connection $connection */ @@ -303,7 +303,7 @@ public function testDryRunModeWithStoresSeed(): void $this->exec('seeds run -c test StoresSeed --dry-run'); $this->assertExitSuccess(); $this->assertOutputContains('DRY-RUN mode enabled'); - $this->assertOutputContains('StoresSeed: seeding'); + $this->assertOutputContains('Stores seed: seeding'); $finalCount = $connection->execute('SELECT COUNT(*) FROM stores')->fetchColumn(0); $this->assertEquals($initialCount, $finalCount, 'Dry-run mode should not modify stores table'); @@ -315,7 +315,7 @@ public function testSeederAnonymousClass(): void $this->exec('seeds run -c test AnonymousStoreSeed'); $this->assertExitSuccess(); - $this->assertOutputContains('AnonymousStoreSeed: seeding'); + $this->assertOutputContains('AnonymousStore seed: seeding'); $this->assertOutputContains('All Done'); /** @var \Cake\Database\Connection $connection */ @@ -334,7 +334,7 @@ public function testSeederShortName(): void $this->exec('seeds run -c test Numbers'); $this->assertExitSuccess(); - $this->assertOutputContains('NumbersSeed: seeding'); + $this->assertOutputContains('Numbers seed: seeding'); $this->assertOutputContains('All Done'); /** @var \Cake\Database\Connection $connection */ @@ -349,8 +349,8 @@ public function testSeederShortNameMultiple(): void $this->exec('seeds run -c test --source CallSeeds Letters,NumbersCall'); $this->assertExitSuccess(); - $this->assertOutputContains('NumbersCallSeed: seeding'); - $this->assertOutputContains('LettersSeed: seeding'); + $this->assertOutputContains('NumbersCall seed: seeding'); + $this->assertOutputContains('Letters seed: seeding'); $this->assertOutputContains('All Done'); /** @var \Cake\Database\Connection $connection */ @@ -368,7 +368,7 @@ public function testSeederShortNameAnonymous(): void $this->exec('seeds run -c test AnonymousStore'); $this->assertExitSuccess(); - $this->assertOutputContains('AnonymousStoreSeed: seeding'); + $this->assertOutputContains('AnonymousStore seed: seeding'); $this->assertOutputContains('All Done'); /** @var \Cake\Database\Connection $connection */ @@ -417,7 +417,7 @@ public function testSeederSpecificSeedSkipsConfirmation(): void $this->assertExitSuccess(); $this->assertOutputNotContains('The following seeds will be executed:'); $this->assertOutputNotContains('Do you want to continue?'); - $this->assertOutputContains('NumbersSeed: seeding'); + $this->assertOutputContains('Numbers seed: seeding'); $this->assertOutputContains('All Done'); } @@ -427,8 +427,8 @@ public function testSeederCommaSeparated(): void $this->exec('seeds run -c test --source CallSeeds Letters,NumbersCall'); $this->assertExitSuccess(); - $this->assertOutputContains('NumbersCallSeed: seeding'); - $this->assertOutputContains('LettersSeed: seeding'); + $this->assertOutputContains('NumbersCall seed: seeding'); + $this->assertOutputContains('Letters seed: seeding'); $this->assertOutputContains('All Done'); /** @var \Cake\Database\Connection $connection */ @@ -450,7 +450,7 @@ public function testSeedStateTracking(): void // First run should execute the seed $this->exec('seeds run -c test NumbersSeed'); $this->assertExitSuccess(); - $this->assertOutputContains('NumbersSeed: seeding'); + $this->assertOutputContains('Numbers seed: seeding'); $this->assertOutputContains('All Done'); // Verify data was inserted @@ -460,7 +460,7 @@ public function testSeedStateTracking(): void // Second run should skip the seed (already executed) $this->exec('seeds run -c test NumbersSeed'); $this->assertExitSuccess(); - $this->assertOutputContains('NumbersSeed: already executed'); + $this->assertOutputContains('Numbers seed: already executed'); $this->assertOutputNotContains('seeding'); // Verify no additional data was inserted @@ -470,7 +470,7 @@ public function testSeedStateTracking(): void // Run with --force should re-execute $this->exec('seeds run -c test NumbersSeed --force'); $this->assertExitSuccess(); - $this->assertOutputContains('NumbersSeed: seeding'); + $this->assertOutputContains('Numbers seed: seeding'); // Verify data was inserted again (now 2 records) $query = $connection->execute('SELECT COUNT(*) FROM numbers'); @@ -495,7 +495,7 @@ public function testSeedStatusCommand(): void $this->exec('seeds status -c test'); $this->assertExitSuccess(); $this->assertOutputContains('executed'); - $this->assertOutputContains('NumbersSeed'); + $this->assertOutputContains('Numbers'); } public function testSeedResetCommand(): void