XmlUtils::loadFile($fixtures.'valid.xml', array($mock, 'validate'));
$this->fail();
} catch (\InvalidArgumentException $e) {
- $this->assertContains('is not valid', $e->getMessage());
+ $this->assertRegExp('/The XML file ".+" is not valid\./', $e->getMessage());
}
$this->assertInstanceOf('DOMDocument', XmlUtils::loadFile($fixtures.'valid.xml', array($mock, 'validate')));
$this->assertSame(array(), libxml_get_errors());
}
+ /**
+ * @expectedException \Symfony\Component\Config\Util\Exception\InvalidXmlException
+ * @expectedExceptionMessage The XML is not valid
+ */
+ public function testParseWithInvalidValidatorCallable()
+ {
+ $fixtures = __DIR__.'/../Fixtures/Util/';
+
+ $mock = $this->getMockBuilder(__NAMESPACE__.'\Validator')->getMock();
+ $mock->expects($this->once())->method('validate')->willReturn(false);
+
+ XmlUtils::parse(file_get_contents($fixtures.'valid.xml'), array($mock, 'validate'));
+ }
+
public function testLoadFileWithInternalErrorsEnabled()
{
$internalErrors = libxml_use_internal_errors(true);
} catch (\InvalidArgumentException $e) {
$this->assertEquals(sprintf('File %s does not contain valid XML, it is empty.', $file), $e->getMessage());
}
- } catch (\Exception $e) {
+ } finally {
restore_error_handler();
error_reporting($errorReporting);
-
- throw $e;
}
- restore_error_handler();
- error_reporting($errorReporting);
-
$disableEntities = libxml_disable_entity_loader(true);
libxml_disable_entity_loader($disableEntities);