-
-
Notifications
You must be signed in to change notification settings - Fork 382
[Translator] Add functional test to ensure only enabled locales are dumped #2946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
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
commit 8cb4384ba7ec4c5119c5d0bd457a1875bdb48464
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
symfony_ux.great: Symfony UX is awesome |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
symfony_ux.great: Symfony UX es genial |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
68
src/Translator/tests/Functional/DumpEnabledLocalesTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
$application->run(new StringInput('cache:clear')); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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