Skip to content
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

Improved exception messages of PHPUnit_Util_XML::load #2054

Merged
merged 1 commit into from Feb 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Util/XML.php
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
Expand Down
27 changes: 27 additions & 0 deletions tests/Util/XMLTest.php
Expand Up @@ -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);
}
}