Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Translator] Add functional test to ensure only enabled_locales are d…
…umped
  • Loading branch information
Kocal committed Jul 27, 2025
commit 8cb4384ba7ec4c5119c5d0bd457a1875bdb48464
3 changes: 2 additions & 1 deletion src/Translator/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"require-dev": {
"symfony/framework-bundle": "^5.4|^6.0|^7.0",
"symfony/phpunit-bridge": "^5.2|^6.0|^7.0",
"symfony/var-dumper": "^5.4|^6.0|^7.0"
"symfony/var-dumper": "^5.4|^6.0|^7.0",
"symfony/yaml": "^5.4|^6.0|^7.0"
},
"extra": {
"thanks": {
Expand Down
2 changes: 1 addition & 1 deletion src/Translator/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/bin/.phpunit/phpunit.xsd"
colors="true"
bootstrap="vendor/autoload.php"
bootstrap="tests/bootstrap.php"
failOnRisky="true"
failOnWarning="true"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
symfony_ux.great: Symfony UX is awesome
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
symfony_ux.great: Symfony UX es genial
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
symfony_ux.great: Symfony UX est génial
68 changes: 68 additions & 0 deletions src/Translator/tests/Functional/DumpEnabledLocalesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\UX\Translator\Tests\Functional;

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\UX\Translator\Tests\Kernel\FrameworkAppKernel;

class DumpEnabledLocalesTest extends KernelTestCase
{
protected static function getKernelClass(): string
{
return FrameworkAppKernel::class;
}

public function testShouldDumpOnlyEnabledLocales(): void
{
self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.en.yaml');
self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.fr.yaml');
self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.es.yaml');

$enabledLocales = self::getContainer()->getParameter('kernel.enabled_locales');
self::assertNotContains('es', $enabledLocales, 'The "es" locale should not be enabled in this test');

$translationsDumpDir = self::getContainer()->getParameter('kernel.project_dir').'/var/translations';
self::assertDirectoryExists($translationsDumpDir);

self::assertStringEqualsFile(
$translationsDumpDir.'/index.js',
<<<JAVASCRIPT
export const SYMFONY_UX_GREAT = {"id":"symfony_ux.great","translations":{"messages":{"en":"Symfony UX is awesome","fr":"Symfony UX est g\u00e9nial"}}};

JAVASCRIPT
);
self::assertStringEqualsFile(
$translationsDumpDir.'/index.d.ts',
<<<TYPESCRIPT
import { Message, NoParametersType } from '@symfony/ux-translator';

export declare const SYMFONY_UX_GREAT: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'fr'>;

TYPESCRIPT
);
self::assertStringEqualsFile(
$translationsDumpDir.'/configuration.js',
<<<JAVASCRIPT
export const localeFallbacks = {"en":null,"fr":"en"};

JAVASCRIPT
);
self::assertStringEqualsFile(
$translationsDumpDir.'/configuration.d.ts',
<<<TYPESCRIPT
import { LocaleType } from '@symfony/ux-translator';

export declare const localeFallbacks: Record<LocaleType, LocaleType>;
TYPESCRIPT
);
}
}
2 changes: 2 additions & 0 deletions src/Translator/tests/Kernel/FrameworkAppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
'test' => true,
'translator' => [
'fallbacks' => ['en'],
'default_path' => '%kernel.project_dir%/tests/Fixtures/translations',
],
'enabled_locales' => ['en', 'fr'],
'http_method_override' => false,
]);
});
Expand Down
25 changes: 25 additions & 0 deletions src/Translator/tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\UX\Translator\Tests\Kernel\FrameworkAppKernel;

require __DIR__.'/../vendor/autoload.php';

(new Filesystem())->remove(__DIR__.'/../var');

$kernel = new FrameworkAppKernel('test', true);
$application = new Application($kernel);

// Trigger Symfony Translator and UX Translator cache warmers
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some issues in lower tests, where our cache warmer was not called when running the functional test.
It worked fine in higher tests thanks to symfony/symfony#57553

But to make it easily consistent, we can manually trigger a cache clear here and the functional test will pass for every Symfony version

$application->run(new StringInput('cache:clear'));