Skip to content

[TwigComponent] Restrict anonymous component lookup to Twig files in debug command #1882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
6 changes: 2 additions & 4 deletions src/TwigComponent/src/Command/TwigComponentDebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,10 @@ private function findAnonymousComponents(): array
$components = [];
$anonymousPath = $this->twigTemplatesPath.'/'.$this->anonymousDirectory;
$finderTemplates = new Finder();
$finderTemplates->files()->in($anonymousPath)->notPath('/_');
$finderTemplates->files()->in($anonymousPath)->notPath('/_')->name('*.html.twig');
foreach ($finderTemplates as $template) {
$component = str_replace('/', ':', $template->getRelativePathname());
if (str_ends_with($component, '.html.twig')) {
$component = substr($component, 0, -10);
}
$component = substr($component, 0, -10);
$components[$component] = $component;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file should not cause issues with the debug:twig:component command.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a case in TwigComponentDebugTest that check NotAComponent is not listed ?

(like the testWithNoMatchComponent test ?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public function testWithNoMatchComponent(): void
$this->assertStringContainsString('Unknown component "NoMatchComponent".', $commandTester->getDisplay());
}

public function testNotComponentsIsNotListed(): void
{
$commandTester = $this->createCommandTester();
$result = $commandTester->execute(['name' => 'NotAComponent']);

$this->assertEquals(1, $result);
$this->assertStringContainsString('Unknown component "NotAComponent".', $commandTester->getDisplay());
}

public function testWithOnePartialMatchComponent(): void
{
$commandTester = $this->createCommandTester();
Expand Down