Skip to content

Commit df82b4a

Browse files
squriouskbond
authored andcommitted
[TwigComponent] Restrict anonymous component lookup to Twig files in debug command
1 parent 2c360c6 commit df82b4a

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/TwigComponent/src/Command/TwigComponentDebugCommand.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,10 @@ private function findAnonymousComponents(): array
151151
$components = [];
152152
$anonymousPath = $this->twigTemplatesPath.'/'.$this->anonymousDirectory;
153153
$finderTemplates = new Finder();
154-
$finderTemplates->files()->in($anonymousPath)->notPath('/_');
154+
$finderTemplates->files()->in($anonymousPath)->notPath('/_')->name('*.html.twig');
155155
foreach ($finderTemplates as $template) {
156156
$component = str_replace('/', ':', $template->getRelativePathname());
157-
if (str_ends_with($component, '.html.twig')) {
158-
$component = substr($component, 0, -10);
159-
}
157+
$component = substr($component, 0, -10);
160158
$components[$component] = $component;
161159
}
162160

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file should not cause issues with the debug:twig:component command.

src/TwigComponent/tests/Integration/Command/TwigComponentDebugCommandTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ public function testWithNoMatchComponent(): void
4141
$this->assertStringContainsString('Unknown component "NoMatchComponent".', $commandTester->getDisplay());
4242
}
4343

44+
public function testNotComponentsIsNotListed(): void
45+
{
46+
$commandTester = $this->createCommandTester();
47+
$result = $commandTester->execute(['name' => 'NotAComponent']);
48+
49+
$this->assertEquals(1, $result);
50+
$this->assertStringContainsString('Unknown component "NotAComponent".', $commandTester->getDisplay());
51+
}
52+
4453
public function testWithOnePartialMatchComponent(): void
4554
{
4655
$commandTester = $this->createCommandTester();

0 commit comments

Comments
 (0)