8000 minor #38939 Validate XLIFF files in tests using the XSD (wouterj) · symfony/symfony@9947e14 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9947e14

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 #38935 in the future. cc @Nyholm Commits ------- 17dfa1d Validate XLIFF files in tests using the XSD
2 parents 7740bb3 + 17dfa1d commit 9947e14

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

src/Symfony/Component/Form/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()

src/Symfony/Component/Security/Core/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()

src/Symfony/Component/Security/Core/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
},

src/Symfony/Component/Validator/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\Validator\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)
0