Skip to content

Commit 4689ee6

Browse files
committed
Fix GenerateFixturesCommand: replace getDefaultName() with #[AsCommand] attribute
Symfony requires commands to declare their name at compile time via the attribute for lazy loading. Using the deprecated getDefaultName() static method caused cache:clear to throw an 'Eagerly loading command failed' error after composer update.
1 parent ae2e12d commit 4689ee6

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

src/Command/GenerateFixturesCommand.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@
1818
use Silverback\ApiComponentsBundle\Entity\Core\Layout;
1919
use Silverback\ApiComponentsBundle\Entity\Core\Page;
2020
use Silverback\ApiComponentsBundle\Entity\Core\Route;
21+
use Symfony\Component\Console\Attribute\AsCommand;
2122
use Symfony\Component\Console\Command\Command;
2223
use Symfony\Component\Console\Input\InputInterface;
2324
use Symfony\Component\Console\Input\InputOption;
2425
use Symfony\Component\Console\Output\OutputInterface;
2526

27+
#[AsCommand(
28+
name: 'silverback:api-components:generate-fixtures',
29+
description: 'Walk the database and output an AbstractCwaScaffold-compatible PHP fixture class',
30+
)]
2631
class GenerateFixturesCommand extends Command
2732
{
2833
private array $useClasses;
@@ -33,16 +38,6 @@ public function __construct(private readonly ManagerRegistry $registry)
3338
parent::__construct();
3439
}
3540

36-
public static function getDefaultName(): string
37-
{
38-
return 'silverback:api-components:generate-fixtures';
39-
}
40-
41-
public function getDescription(): string
42-
{
43-
return 'Walk the database and output an AbstractCwaScaffold-compatible PHP fixture class';
44-
}
45-
4641
protected function configure(): void
4742
{
4843
$this->addOption('output', 'o', InputOption::VALUE_REQUIRED, 'Output file path', 'src/DataFixtures/GeneratedScaffold.php');

tests/Command/GenerateFixturesCommandTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ private function makeLayout(string $reference, string $uiComponent): Layout
141141

142142
public function test_command_name(): void
143143
{
144-
$this->assertSame('silverback:api-components:generate-fixtures', GenerateFixturesCommand::getDefaultName());
144+
$command = $this->makeCommand();
145+
$this->assertSame('silverback:api-components:generate-fixtures', $command->getName());
145146
}
146147

147148
public function test_command_description(): void

0 commit comments

Comments
 (0)