8000 bug #1569 Fix generated twig file location · symfony/maker-bundle@10459ae · GitHub
[go: up one dir, main page]

Skip to content

Commit 10459ae

Browse files
authored
bug #1569 Fix generated twig file location
1 parent d4fa901 commit 10459ae

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/Maker/MakeTwigComponent.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Bundle\MakerBundle\DependencyBuilder;
1616
use Symfony\Bundle\MakerBundle\Generator;
1717
use Symfony\Bundle\MakerBundle\InputConfiguration;
18-
use Symfony\Bundle\MakerBundle\Str;
1918
use Symfony\Component\Console\Command\Command;
2019
use Symfony\Component\Console\Input\InputArgument;
2120
use Symfony\Component\Console\Input\InputInterface;
@@ -66,7 +65,8 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
6665
'Twig\\Components',
6766
);
6867

69-
$shortName = Str::getShortClassName($factory->getShortName());
68+
$templatePath = str_replace('\\', '/', $factory->getRelativeNameWithoutSuffix());
69+
$shortName = str_replace('\\', ':', $factory->getRelativeNameWithoutSuffix());
7070

7171
$generator->generateClass(
7272
$factory->getFullName(),
@@ -76,7 +76,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
7676
]
7777
);
7878
$generator->generateTemplate(
79-
"components/{$shortName}.html.twig",
79+
"components/{$templatePath}.html.twig",
8080
sprintf('%s/../Resources/skeleton/twig/%s', __DIR__, 'component_template.tpl.php')
8181
);
8282

tests/Maker/MakeTwigComponentTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ public function getTestDetails(): \Generator
9090
$runner->runTests();
9191
}),
9292
];
93+
94+
yield 'it_generates_live_component_on_subdirectory' => [$this->createMakerTest()
95+
->addExtraDependencies('symfony/ux-live-component', 'symfony/twig-bundle')
96+
->run(function (MakerTestRunner $runner) {
97+
$output = $runner->runMaker(['Form\Input', 'y']);
98+
99+
$this->assertStringContainsString('src/Twig/Components/Form/Input.php', $output);
100+
$this->assertStringContainsString('templates/components/Form/Input.html.twig', $output);
101+
$this->assertStringContainsString('To render the component, use <twig:Form:Input />.', $output);
102+
103+
$runner->copy(
104+
'make-twig-component/tests/it_generates_live_component.php',
105+
'tests/GeneratedLiveComponentTest.php'
106+
);
107+
$runner->replaceInFile('tests/GeneratedLiveComponentTest.php', '{name}', 'Form:Input');
108+
$runner->runTests();
109+
}),
110+
];
93111
}
94112

95113
protected function getMakerClass(): string

0 commit comments

Comments
 (0)
0