Skip to content

Commit cbb4f78

Browse files
nutamanicoschoenmaker
authored andcommitted
change compiler to support *.yaml files (#20)
1 parent a6ef8c7 commit cbb4f78

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/DependencyInjection/EnumTranslationCompilerPass.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function registerEnums(ContainerBuilder $container, array $enum_files)
6161
foreach ($enum_files as $file) {
6262
list(, $locale, $format) = explode('.', basename($file), 3);
6363

64-
if (strtolower($format) !== 'yml') {
64+
if (!\in_array(strtolower($format), ['yml', 'yaml'], true)) {
6565
throw new \RuntimeException(sprintf("Unsupported enum translation file format '%s'.", $format));
6666
}
6767

test/DependencyInjection/EnumTranslationCompilerPassTest.php

+28
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,34 @@
1010
*/
1111
class EnumTranslationCompilerPassTest extends \PHPUnit_Framework_TestCase
1212
{
13+
/**
14+
* @dataProvider processLoadYamlFilesProvider
15+
*/
16+
public function testProcessLoadYamlFiles($resource_path)
17+
{
18+
$resources = realpath($resource_path);
19+
$container = new ContainerBuilder();
20+
$translator = new Definition();
21+
$translator->setArguments([[], [], [], [
22+
'resource_files' => ['en' => [$resources]]
23+
]]);
24+
$container->setDefinition('translator.default', $translator);
25+
26+
$pass = new EnumTranslationCompilerPass();
27+
$pass->process($container);
28+
29+
$calls = $translator->getMethodCalls();
30+
31+
$this->assertEquals(1, count($calls));
32+
$this->assertEquals(['addResource', ['enum', $resources, 'en', MockEnum::class]], $calls[0]);
33+
}
34+
35+
public function processLoadYamlFilesProvider()
36+
{
37+
yield [__DIR__ . '/../Mock/Resources/translations/enum.en.yml'];
38+
yield [__DIR__ . '/../Mock/Resources/translations/enum.en.yaml'];
39+
}
40+
1341
public function testProcess()
1442
{
1543
$resources = realpath(__DIR__ . '/../Mock/Resources/translations/enum.en.yml');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
hostnet:
2+
bundle:
3+
entity_translation_bundle:
4+
mock:
5+
# Hostnet\Bundle\EntityTranslationBundle\Mock\MockEnum enum translations
6+
mock_enum:
7+
foo : "Foo"
8+
bar : "Not so Bar"

0 commit comments

Comments
 (0)