On 01/14/2013 06:00 PM, Marc Delisle wrote:
Hi,
I want to modify a test to fit with a modification I am working on. In
this modification, the tested function uses $GLOBALS['error_handler'].
How can I define this global inside my test?
How about the below code? Totally untested, off the top of my head, but
should work....
protected function setUp()
{
$GLOBALS['error_handler'] = new PMA_Error_Handler();
}
Thanks. I added this (plus the "require" for the error class) but now I get
Failed asserting that exception of type "PHPUnit_Framework_Error" is
thrown. See attached patch.
--
Marc Delisle
http://infomarc.info
diff --git a/libraries/Error_Handler.class.php b/libraries/Error_Handler.class.php
index b6b9bf0..609791c 100644
--- a/libraries/Error_Handler.class.php
+++ b/libraries/Error_Handler.class.php
@@ -99,8 +99,16 @@ class PMA_Error_Handler
*/
public function handleError($errno, $errstr, $errfile, $errline)
{
+ $this->addError($errstr, $errno, $errfile, $errline, $escape=true);
+ }
+
+ public function addError($errstr, $errno, $errfile, $errline, $escape=true)
+ {
+ if ($escape) {
+ $errstr = htmlspecialchars($errstr);
+ }
// create error object
- $error = new PMA_Error($errno, htmlspecialchars($errstr), $errfile, $errline);
+ $error = new PMA_Error($errno, $errstr, $errfile, $errline);
// do not repeat errors
$this->_errors[$error->getHash()] = $error;
@@ -131,6 +139,7 @@ class PMA_Error_Handler
}
}
+
/**
* log error to configured log facility
*
diff --git a/libraries/core.lib.php b/libraries/core.lib.php
index 93be5fe..eb698ff 100644
--- a/libraries/core.lib.php
+++ b/libraries/core.lib.php
@@ -277,7 +277,12 @@ function PMA_warnMissingExtension($extension, $fatal = false, $extra = '')
if ($fatal) {
PMA_fatalError($message);
} else {
- trigger_error($message, E_USER_WARNING);
+ $GLOBALS['error_handler']->addError(
+ $message,
+ E_USER_WARNING,
+ '',
+ '',
+ $escape=false);
}
}
diff --git a/test/libraries/core/PMA_warnMissingExtension_test.php b/test/libraries/core/PMA_warnMissingExtension_test.php
index 1e11c73..661e6c7 100644
--- a/test/libraries/core/PMA_warnMissingExtension_test.php
+++ b/test/libraries/core/PMA_warnMissingExtension_test.php
@@ -15,6 +15,11 @@ require_once 'libraries/core.lib.php';
class PMA_warnMissingExtension_test extends PHPUnit_Framework_TestCase
{
+ protected function setUp() {
+ require_once './libraries/Error_Handler.class.php';
+ $GLOBALS['error_handler'] = new PMA_Error_Handler();
+ }
+
function testMissingExtention(){
$ext = 'php_ext';
$this->setExpectedException('PHPUnit_Framework_Error',