2011-03-05 19:23:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-03-05 19:23:35 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2012-03-28 14:43:52 +01:00
|
|
|
namespace Symfony\Component\HttpKernel\Tests\Debug;
|
2011-03-05 19:23:35 +00:00
|
|
|
|
|
|
|
use Symfony\Component\HttpKernel\Debug\ErrorHandler;
|
|
|
|
use Symfony\Component\HttpKernel\Debug\ErrorException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ErrorHandlerTest
|
|
|
|
*
|
|
|
|
* @author Robert Schönthal <seroscho@googlemail.com>
|
|
|
|
*/
|
|
|
|
class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2011-03-05 19:23:35 +00:00
|
|
|
public function testConstruct()
|
|
|
|
{
|
2011-05-05 07:46:20 +01:00
|
|
|
$handler = ErrorHandler::register(3);
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2011-05-05 07:46:20 +01:00
|
|
|
$level = new \ReflectionProperty($handler, 'level');
|
2011-03-05 19:23:35 +00:00
|
|
|
$level->setAccessible(true);
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2011-05-05 07:46:20 +01:00
|
|
|
$this->assertEquals(3, $level->getValue($handler));
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2011-05-05 07:46:20 +01:00
|
|
|
restore_error_handler();
|
2011-03-05 19:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testHandle()
|
|
|
|
{
|
2011-05-05 07:46:20 +01:00
|
|
|
$handler = ErrorHandler::register(0);
|
|
|
|
$this->assertFalse($handler->handle(0, 'foo', 'foo.php', 12, 'foo'));
|
|
|
|
|
|
|
|
restore_error_handler();
|
|
|
|
|
|
|
|
$handler = ErrorHandler::register(3);
|
|
|
|
$this->assertFalse($handler->handle(4, 'foo', 'foo.php', 12, 'foo'));
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2011-05-05 07:46:20 +01:00
|
|
|
restore_error_handler();
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2011-05-05 07:46:20 +01:00
|
|
|
$handler = ErrorHandler::register(3);
|
|
|
|
try {
|
|
|
|
$handler->handle(1, 'foo', 'foo.php', 12, 'foo');
|
|
|
|
} catch (\ErrorException $e) {
|
|
|
|
$this->assertSame('1: foo in foo.php line 12', $e->getMessage());
|
2011-03-05 19:23:35 +00:00
|
|
|
}
|
|
|
|
|
2011-05-05 07:46:20 +01:00
|
|
|
restore_error_handler();
|
|
|
|
}
|
2011-03-05 19:23:35 +00:00
|
|
|
}
|