Skip to content

Commit

Permalink
Take care of prefix in component generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Halleck45 committed Jan 31, 2025
1 parent daf701d commit 790ec26
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/Toolkit/src/Compiler/TwigComponentCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ public function compile(
$filesystem->mkdir($directory);
}

$filename = $directory.\DIRECTORY_SEPARATOR.$component->getName().'.html.twig';
$filename = implode(\DIRECTORY_SEPARATOR, [
$directory,
$this->prefix,
$component->getName().'.html.twig',
]);

if ($filesystem->exists($filename)) {
throw new TwigComponentAlreadyExist();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Toolkit/tests/Command/UxToolkitInstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testShouldAbleToCreateTheBadgeComponent(): void
$this->createMock(GithubRepository::class)
);
$identifier = new ComponentIdentifier();
$compiler = new TwigComponentCompiler('default', 'ux');
$compiler = new TwigComponentCompiler('default', 'Acme');
$command = new UxToolkitInstallCommand($repositoryFactory, $identifier, $compiler);

$destination = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid();
Expand All @@ -54,11 +54,11 @@ public function testShouldAbleToCreateTheBadgeComponent(): void
$this->assertEquals(Command::SUCCESS, $result);

// A file should be created
$expectedFile = $destination.\DIRECTORY_SEPARATOR.'Badge.html.twig';
$expectedFile = $destination.\DIRECTORY_SEPARATOR.'Acme'.\DIRECTORY_SEPARATOR.'Badge.html.twig';
$this->assertFileExists($expectedFile);

// The content of the file should be the same as the content of the Badge component
$expectedContent = file_get_contents(__DIR__. '/../../templates/default/components/Badge.html.twig');
$expectedContent = file_get_contents(__DIR__.'/../../templates/default/components/Badge.html.twig');
$actualContent = file_get_contents($expectedFile);
$this->assertEquals($expectedContent, $actualContent);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Toolkit/tests/Compiler/TwigComponentCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ class TwigComponentCompilerTest extends KernelTestCase
{
public function testItShouldCompileComponentToFile(): void
{
$compiler = new TwigComponentCompiler('default', 'ux');
$compiler = new TwigComponentCompiler('default', 'Acme');
$destination = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('component_');
$repository = new OfficialRepository();
$component = new ComponentIdentity('symfony', '', 'Badge');
$compiler->compile($component, $repository, $destination);

$this->assertFileExists($destination);
$this->assertFileExists($destination.'/Badge.html.twig');
$this->assertFileExists($destination.'/Acme/Badge.html.twig');

$content = file_get_contents($destination.'/Badge.html.twig');
$content = file_get_contents($destination.'/Acme/Badge.html.twig');
$this->assertStringContainsString('{% block content %}{% endblock %}', $content);
}

Expand Down

0 comments on commit 790ec26

Please sign in to comment.