Skip to content

Commit d489c8a

Browse files
committed
Validate XLIFF files in tests using the XSD
1 parent 0cf5b4c commit d489c8a

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)