Skip to content

Commit

Permalink
Fix test error handler to not mute errors
Browse files Browse the repository at this point in the history
  • Loading branch information
xemlock committed Sep 20, 2021
1 parent 265ed8e commit dd5dd10
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tests/BaseTestCase.php
Expand Up @@ -35,13 +35,22 @@ protected function setUp()
set_error_handler(array($this, 'errorHandler'), E_USER_NOTICE | E_USER_WARNING);
}

protected function tearDown()
{
foreach ($this->errors as $error) {
throw new PHPUnit_Framework_Error_Error($error['message'], $error['errno'], $error['file'], $error['line']);
}
}

/**
* @param int $errno
* @param string $message
* @param string $file
* @param int $line
*/
public function errorHandler($errno, $message)
public function errorHandler($errno, $message, $file, $line)
{
$this->errors[] = compact('errno', 'message');
$this->errors[] = compact('errno', 'message', 'file', 'line');
}

/**
Expand All @@ -60,8 +69,9 @@ public function assertPurification($input, $expect = null)
*/
public function assertWarning($message)
{
foreach ($this->errors as $error) {
if ($error['message'] === $message && $error['errno'] === E_USER_WARNING) {
foreach ($this->errors as $key => $error) {
if ($error['message'] === $message && ($error['errno'] === E_USER_WARNING || $error['errno'] === E_WARNING)) {
unset($this->errors[$key]);
return;
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/bootstrap.php
Expand Up @@ -13,6 +13,11 @@ class_alias('PHPUnit\Framework\TestSuite', 'PHPUnit_Framework_TestSuite');
class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase');
}

if (!class_exists('PHPUnit_Framework_Error_Error') && class_exists('PHPUnit\Framework\Error\Error')) {
/** @noinspection PhpIgnoredClassAliasDeclaration */
class_alias('PHPUnit\Framework\Error\Error', 'PHPUnit_Framework_Error_Error');
}

echo "HTMLPurifier version: ", HTMLPurifier::VERSION, "\n";
echo "libxml version: ", constant('LIBXML_DOTTED_VERSION'), "\n";
echo "PHP version: ", PHP_VERSION, "\n";
Expand Down

0 comments on commit dd5dd10

Please sign in to comment.