Skip to content

Commit bf9e6be

Browse files
committed
[Translator] Add functional test to ensure only enabled_locales are dumped
1 parent e1b43e7 commit bf9e6be

File tree

8 files changed

+105
-2
lines changed

8 files changed

+105
-2
lines changed

src/Translator/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"require-dev": {
3838
"symfony/framework-bundle": "^5.4|^6.0|^7.0",
3939
"symfony/phpunit-bridge": "^5.2|^6.0|^7.0",
40-
"symfony/var-dumper": "^5.4|^6.0|^7.0"
40+
"symfony/var-dumper": "^5.4|^6.0|^7.0",
41+
"symfony/yaml": "^5.4|^6.0|^7.0"
4142
},
4243
"extra": {
4344
"thanks": {

src/Translator/phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:noNamespaceSchemaLocation="vendor/bin/.phpunit/phpunit.xsd"
66
colors="true"
7-
bootstrap="vendor/autoload.php"
7+
bootstrap="tests/bootstrap.php"
88
failOnRisky="true"
99
failOnWarning="true"
1010
>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
symfony_ux.great: Symfony UX is awesome
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
symfony_ux.great: Symfony UX es genial
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
symfony_ux.great: Symfony UX est génial
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\UX\Translator\Tests\Functional;
13+
14+
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
15+
use Symfony\UX\Translator\Tests\Kernel\FrameworkAppKernel;
16+
17+
class DumpEnabledLocalesTest extends KernelTestCase
18+
{
19+
protected static function getKernelClass(): string
20+
{
21+
return FrameworkAppKernel::class;
22+
}
23+
24+
public function testShouldDumpOnlyEnabledLocales(): void
25+
{
26+
self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.en.yaml');
27+
self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.fr.yaml');
28+
self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.es.yaml');
29+
30+
//// Manually warmup cache warmers when < https://github.com/symfony/symfony/pull/57553
31+
//if (FrameworkAppKernel::VERSION_ID < 60409) {
32+
// $cacheWarmer = self::getContainer()->get('cache_warmer');
33+
// $cacheWarmer->warmUp(self::getContainer()->getParameter('kernel.cache_dir'));
34+
//}
35+
36+
$enabledLocales = self::getContainer()->getParameter('kernel.enabled_locales');
37+
self::assertNotContains('es', $enabledLocales, 'The "es" locale should not be enabled in this test');
38+
39+
$translationsDumpDir = self::getContainer()->getParameter('kernel.project_dir').'/var/translations';
40+
self::assertDirectoryExists($translationsDumpDir);
41+
42+
self::assertStringEqualsFile(
43+
$translationsDumpDir.'/index.js',
44+
<<<JAVASCRIPT
45+
export const SYMFONY_UX_GREAT = {"id":"symfony_ux.great","translations":{"messages":{"en":"Symfony UX is awesome","fr":"Symfony UX est g\u00e9nial"}}};
46+
47+
JAVASCRIPT
48+
);
49+
self::assertStringEqualsFile(
50+
$translationsDumpDir.'/index.d.ts',
51+
<<<TYPESCRIPT
52+
import { Message, NoParametersType } from '@symfony/ux-translator';
53+
54+
export declare const SYMFONY_UX_GREAT: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'fr'>;
55+
56+
TYPESCRIPT
57+
);
58+
self::assertStringEqualsFile(
59+
$translationsDumpDir.'/configuration.js',
60+
<<<JAVASCRIPT
61+
export const localeFallbacks = {"en":null,"fr":"en"};
62+
63+
JAVASCRIPT
64+
);
65+
self::assertStringEqualsFile(
66+
$translationsDumpDir.'/configuration.d.ts',
67+
<<<TYPESCRIPT
68+
import { LocaleType } from '@symfony/ux-translator';
69+
70+
export declare const localeFallbacks: Record<LocaleType, LocaleType>;
71+
TYPESCRIPT
72+
);
73+
}
74+
}

src/Translator/tests/Kernel/FrameworkAppKernel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
3939
'test' => true,
4040
'translator' => [
4141
'fallbacks' => ['en'],
42+
'default_path' => '%kernel.project_dir%/tests/Fixtures/translations',
4243
],
44+
'enabled_locales' => ['en', 'fr'],
4345
'http_method_override' => false,
4446
]);
4547
});

src/Translator/tests/bootstrap.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\Bundle\FrameworkBundle\Console\Application;
13+
use Symfony\Component\Console\Input\StringInput;
14+
use Symfony\Component\Filesystem\Filesystem;
15+
use Symfony\UX\Translator\Tests\Kernel\FrameworkAppKernel;
16+
17+
require __DIR__.'/../vendor/autoload.php';
18+
19+
(new Filesystem())->remove(__DIR__.'/../var');
20+
21+
$kernel = new FrameworkAppKernel('test', true);
22+
$application = new Application($kernel);
23+
$application->run(new StringInput('cache:clear'));

0 commit comments

Comments
 (0)