Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Cli/Command/TasksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Note the description is blue so it stands out, to avoid developers missing it if they add a new
* task and suddenly they don't see the tasks in their main commands list anymore.
*/
#[AsCommand(name: 'tasks', description: '<fg=blue>See a list of build tasks to run</>')]
#[AsCommand(name: 'tasks', description: '<fg=blue>See a list of build tasks to run</>', aliases: ['dev/tasks'])]
class TasksCommand extends Command
{
private Command $listCommand;
Expand Down
8 changes: 6 additions & 2 deletions src/Cli/Sake.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
$suggestions->suggestValue(new Suggestion($command->getName(), $command->getDescription()));
foreach ($command->getAliases() as $name) {
// Skip legacy dev aliases
if (str_starts_with($name, 'dev/')) {
if ($name === 'dev' || str_starts_with($name, 'dev/')) {
continue;
}
$suggestions->suggestValue(new Suggestion($name, $command->getDescription()));
Expand All @@ -204,7 +204,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
{
$name = $command->getName() ?? '';
$nameUsedAs = $input->getFirstArgument() ?? '';
if (str_starts_with($nameUsedAs, 'dev/')) {
if ($nameUsedAs === 'dev' || str_starts_with($nameUsedAs, 'dev/')) {
Deprecation::notice(
'6.0.0',
"Using the command with the name '$nameUsedAs' is deprecated. Use '$name' instead",
Expand Down Expand Up @@ -243,6 +243,10 @@ protected function getDefaultCommands(): array
if (in_array(get_class($command), $toHide)) {
$command->setHidden(true);
}
// Add deprecated alias "sake dev" for backwards compatibility
if ($command instanceof ListCommand) {
$command->setAliases([...$command->getAliases(), 'dev']);
}
}

$commands[] = $this->createFlushCommand();
Expand Down
27 changes: 23 additions & 4 deletions tests/php/Cli/SakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,23 +248,42 @@ public function testVersion(): void
$this->assertSame($versionProvider->getVersion(), $sake->getVersion());
}

public function testLegacyDevCommands(): void
public static function provideLegacyDevCommands(): array
{
return [
[
'command' => 'dev',
'correctName' => 'list',
],
[
'command' => 'dev/config',
'correctName' => 'config:dump',
],
[
'command' => 'dev/tasks',
'correctName' => 'tasks',
],
// NOTE: Do not run `dev/build` as that will manipulate the database in a way that causes subsequent tests to fail.
];
}

#[DataProvider('provideLegacyDevCommands')]
public function testLegacyDevCommands(string $command, string $correctName): void
{
$sake = new Sake(Injector::inst()->get(Kernel::class));
$sake->setAutoExit(false);
$input = new ArrayInput(['dev/config']);
$input = new ArrayInput([$command, '--quiet' => 1]);
$input->setInteractive(false);
$output = new BufferedOutput();

$deprecationsWereEnabled = Deprecation::isEnabled();
Deprecation::enable();
$this->expectException(DeprecationTestException::class);
$expectedErrorString = 'Using the command with the name \'dev/config\' is deprecated. Use \'config:dump\' instead';
$expectedErrorString = "Using the command with the name '$command' is deprecated. Use '$correctName' instead";
$this->expectExceptionMessage($expectedErrorString);

$exitCode = $sake->run($input, $output);
$this->assertSame(0, $exitCode, 'command should run successfully');
// $this->assertStringContainsString('abababa', $output->fetch());

$this->allowCatchingDeprecations($expectedErrorString);
try {
Expand Down