Skip to content

Commit 617f6e3

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 eda6382 + d8f520f commit 617f6e3

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-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\Form\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()

0 commit comments

Comments
 (0)