diff --git a/src/Util/XML.php b/src/Util/XML.php index 176204b9048..f070d221af1 100644 --- a/src/Util/XML.php +++ b/src/Util/XML.php @@ -100,6 +100,14 @@ public static function load($actual, $isHtml = false, $filename = '', $xinclude return $actual; } + if (!is_string($actual)) { + throw new PHPUnit_Framework_Exception('Could not load XML from ' . gettype($actual)); + } + + if ($actual === '') { + throw new PHPUnit_Framework_Exception('Could not load XML from empty string'); + } + // Required for XInclude on Windows. if ($xinclude) { $cwd = getcwd(); @@ -149,6 +157,9 @@ public static function load($actual, $isHtml = false, $filename = '', $xinclude ) ); } else { + if ($message === '') { + $message = 'Could not load XML for unknown reason'; + } throw new PHPUnit_Framework_Exception($message); } } diff --git a/tests/Util/XMLTest.php b/tests/Util/XMLTest.php index 086b738c1a7..c958771cba1 100644 --- a/tests/Util/XMLTest.php +++ b/tests/Util/XMLTest.php @@ -315,4 +315,31 @@ public function charProvider() return $data; } + + /** + * @expectedException PHPUnit_Framework_Exception + * @expectedExceptionMessage Could not load XML from empty string + */ + public function testLoadEmptyString() + { + PHPUnit_Util_XML::load(''); + } + + /** + * @expectedException PHPUnit_Framework_Exception + * @expectedExceptionMessage Could not load XML from array + */ + public function testLoadArray() + { + PHPUnit_Util_XML::load(array(1, 2, 3)); + } + + /** + * @expectedException PHPUnit_Framework_Exception + * @expectedExceptionMessage Could not load XML from boolean + */ + public function testLoadBoolean() + { + PHPUnit_Util_XML::load(false); + } }