8000 [Config] extracted the xml parsing from XmlUtils::loadFile into XmlUt… by Basster · Pull Request #23482 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Config] extracted the xml parsing from XmlUtils::loadFile into XmlUt… #23482

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

Closed
Prev Previous commit
Next Next commit
renamed load to parse, that's more specific.
  • Loading branch information
Basster committed Jul 12, 2017
commit 43b2c2f5aadb79ee3d370bd43abc0c8b8719e2cf
4 changes: 2 additions & 2 deletions src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public function testLoadFile()
$this->assertSame(array(), libxml_get_errors());
}

public function testLoad()
public function testParse()
{
$fixtures = __DIR__.'/../Fixtures/Util/';

$mock = $this->getMockBuilder(__NAMESPACE__.'\Validator')->getMock();
$mock->expects($this->once())->method('validate')->will($this->onConsecutiveCalls(false, true));

try {
XmlUtils::load(file_get_contents($fixtures.'valid.xml'), array($mock, 'validate'));
XmlUtils::parse(file_get_contents($fixtures.'valid.xml'), array($mock, 'validate'));
$this->fail();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better solution is to use @expectedException and @expectedExceptionMessage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just re-used the way it has been done in the other tests in this class. Normally I'd go with the annotations, too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other tests are written this way, because they try to test multiple cases in the same test. This is a legacy from tests written in the early days of Symfony's usage of PHPUnit.

} catch (\InvalidArgumentException $e) {
$this->assertContains('The XML is not valid', $e->getMessage());
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Config/Util/XmlUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private function __construct()
*
* @throws \InvalidArgumentException When loading of XML file returns error
*/
public static function load($content, $schemaOrCallable = null)
public static function parse($content, $schemaOrCallable = null)
{
$internalErrors = libxml_use_internal_errors(true);
$disableEntities = libxml_disable_entity_loader(true);
Expand Down Expand Up @@ -119,7 +119,7 @@ public static function loadFile($file, $schemaOrCallable = null)
}

try {
return static::load($content, $schemaOrCallable);
return static::parse($content, $schemaOrCallable);
} catch (\InvalidArgumentException $ex) {
throw new \InvalidArgumentException(
str_replace(self::XML_IS_NOT_VALID_MESSAGE, sprintf('The XML file "%s" is not valid.', $file), $ex->getMessage()),
Expand Down
0