Skip to content

Commit b9b1d8b

Browse files
committed
minor #38939 Validate XLIFF files in tests using the XSD (wouterj)
This PR was merged into the 4.4 branch. Discussion ---------- Validate XLIFF files in tests using the XSD | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - The current tests only validated that the Xliff files were valid XML. This improves it to also validate the Xliff files against the correct XSD. This will avoid issues like symfony/symfony#38935 in the future. cc @Nyholm Commits ------- 17dfa1d5fc Validate XLIFF files in tests using the XSD
2 parents 378927b + d489c8a commit b9b1d8b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Tests/Resources/TranslationFilesTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Security\Core\Tests\Resources;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use PHPUnit\Util\Xml\Loader;
15+
use Symfony\Component\Translation\Util\XliffUtils;
1616

1717
class TranslationFilesTest extends TestCase
1818
{
@@ -21,13 +21,12 @@ class TranslationFilesTest extends TestCase
2121
*/
2222
public function testTranslationFileIsValid($filePath)
2323
{
24-
$loader = class_exists(Loader::class)
25-
? [new Loader(), 'loadFile']
26-
: ['PHPUnit\Util\XML', 'loadfile'];
24+
$document = new \DOMDocument();
25+
$document->loadXML(file_get_contents($filePath));
2726

28-
$loader($filePath, false, false, true);
27+
$errors = XliffUtils::validateSchema($document);
2928

30-
$this->addToAssertionCount(1);
29+
$this->assertCount(0, $errors, sprintf('"%s" is invalid:%s', $filePath, \PHP_EOL.implode(\PHP_EOL, array_column($errors, 'message'))));
3130
}
3231

3332
public function provideTranslationFiles()

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"symfony/expression-language": "^3.4|^4.0|^5.0",
2727
"symfony/http-foundation": "^3.4|^4.0|^5.0",
2828
"symfony/ldap": "^4.4|^5.0",
29+
"symfony/translation": "^4.4|^5.0",
2930
"symfony/validator": "^3.4.31|^4.3.4|^5.0",
3031
"psr/log": "~1.0"
3132
},

0 commit comments

Comments
 (0)