Compare commits

..

14 Commits

Author SHA1 Message Date
Fabien Potencier
993f4c9cfc fixed CS 2014-09-22 10:32:35 +02:00
Christian Raue
91e3a1480c removed defaults from PHPUnit configuration 2014-07-07 12:13:42 +02:00
Christian Raue
732b41060b added XSD to PHPUnit configuration 2014-07-07 11:57:21 +02:00
Nicolas Grekas
ca764f8af9 [Debug] fix #10313: FlattenException not found because of https://bugs.php.net/42098 2014-04-29 21:42:43 +02:00
Nicolas Grekas
9fb191fa62 [Debug] fix ErrorHandlerTest when context is not an array 2014-04-28 20:50:14 +02:00
Nicolas Grekas
b2e922174d [Debug] ErrorHandler: remove $GLOBALS from context in PHP5.3 fix #10292 2014-04-28 18:43:50 +02:00
Fabien Potencier
bdfb718a6c made phpdoc types consistent with those defined in Hack 2014-04-15 07:41:45 +02:00
Jerome TAMARELLE
3c1b5f218d Check headers sent before sending PHP response
If the response contents has been sent before an error occurs, PHP
triggers the warning "Cannot modify header information - headers already sent"

This change ensure that the error message is echoed, while it's impossible
to change the HTTP status code and headers.
2014-03-26 19:06:50 +01:00
Fabien Potencier
78dc94dce6 changed some PHPUnit assertions to more specific ones 2014-03-01 18:25:29 +01:00
Fabien Potencier
4885c636af fixed various inconsistencies 2014-02-11 11:29:24 +01:00
sun
6a55635898 Fixed recursion level incrementing in FlattenException::flattenArgs(). 2014-02-04 08:06:39 +01:00
Luis Cordova
7f875d2aae update year on licenses 2014-01-07 08:19:25 -05:00
Pascal Borreli
13d5fe432f Fixed typo 2013-12-28 12:31:17 +01:00
Fabien Potencier
89151cc3fe fixed CS for lambdas 2013-12-28 08:46:05 +01:00
9 changed files with 47 additions and 44 deletions

View File

@@ -30,8 +30,8 @@ class Debug
* If the Symfony ClassLoader component is available, a special
* class loader is also registered.
*
* @param integer $errorReportingLevel The level of error reporting you want
* @param Boolean $displayErrors Whether to display errors (for development) or just log them (for production)
* @param int $errorReportingLevel The level of error reporting you want
* @param bool $displayErrors Whether to display errors (for development) or just log them (for production)
*/
public static function enable($errorReportingLevel = null, $displayErrors = true)
{

View File

@@ -56,8 +56,8 @@ class ErrorHandler
/**
* Registers the error handler.
*
* @param integer $level The level at which the conversion to Exception is done (null to use the error_reporting() value and 0 to disable)
* @param Boolean $displayErrors Display errors (for dev environment) or just log they (production usage)
* @param int $level The level at which the conversion to Exception is done (null to use the error_reporting() value and 0 to disable)
* @param bool $displayErrors Display errors (for dev environment) or just log they (production usage)
*
* @return ErrorHandler The registered error handler
*/
@@ -125,6 +125,13 @@ class ErrorHandler
if (!class_exists('Symfony\Component\Debug\Exception\ContextErrorException')) {
require __DIR__.'/Exception/ContextErrorException.php';
}
if (!class_exists('Symfony\Component\Debug\Exception\FlattenException')) {
require __DIR__.'/Exception/FlattenException.php';
}
if (PHP_VERSION_ID < 50400 && isset($context['GLOBALS']) && is_array($context)) {
unset($context['GLOBALS']);
}
$exception = new ContextErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line), 0, $level, $file, $line, $context);
@@ -142,10 +149,10 @@ class ErrorHandler
// we must stop the PHP script execution, as the exception has
// already been dealt with, so, let's throw an exception that
// will be catched by a dummy exception handler
// will be caught by a dummy exception handler
set_exception_handler(function (\Exception $e) use ($exceptionHandler) {
if (!$e instanceof DummyException) {
// happens if our dummy exception is catched by a
// happens if our dummy exception is caught by a
// catch-all from user code, in which case, let's the
// current handler handle this "new" exception
call_user_func($exceptionHandler, $e);
@@ -186,7 +193,7 @@ class ErrorHandler
}
// get current exception handler
$exceptionHandler = set_exception_handler(function() {});
$exceptionHandler = set_exception_handler(function () {});
restore_exception_handler();
if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandler) {

View File

@@ -249,7 +249,7 @@ class FlattenException
if ($level > 10) {
$result[$key] = array('array', '*DEEP NESTED ARRAY*');
} else {
$result[$key] = array('array', $this->flattenArgs($value, ++$level));
$result[$key] = array('array', $this->flattenArgs($value, $level + 1));
}
} elseif (null === $value) {
$result[$key] = array('null', null);

View File

@@ -43,7 +43,7 @@ class ExceptionHandler
/**
* Registers the exception handler.
*
* @param Boolean $debug
* @param bool $debug
*
* @return ExceptionHandler The registered exception handler
*/
@@ -91,9 +91,11 @@ class ExceptionHandler
$exception = FlattenException::create($exception);
}
header(sprintf('HTTP/1.0 %s', $exception->getStatusCode()));
foreach ($exception->getHeaders() as $name => $value) {
header($name.': '.$value, false);
if (!headers_sent()) {
header(sprintf('HTTP/1.0 %s', $exception->getStatusCode()));
foreach ($exception->getHeaders() as $name => $value) {
header($name.': '.$value, false);
}
}
echo $this->decorate($this->getContent($exception), $this->getStylesheet($exception));

View File

@@ -1,4 +1,4 @@
Copyright (c) 2004-2013 Fabien Potencier
Copyright (c) 2004-2014 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -104,7 +104,7 @@ PHP
set_exception_handler(array($exceptionHandler, 'handle'));
$that = $this;
$exceptionCheck = function($exception) use ($that) {
$exceptionCheck = function ($exception) use ($that) {
$that->assertInstanceOf('Symfony\Component\Debug\Exception\ContextErrorException', $exception);
$that->assertEquals(E_NOTICE, $exception->getSeverity());
$that->assertEquals(__LINE__ + 40, $exception->getLine());
@@ -165,18 +165,18 @@ PHP
public function testHandle()
{
$handler = ErrorHandler::register(0);
$this->assertFalse($handler->handle(0, 'foo', 'foo.php', 12, 'foo'));
$this->assertFalse($handler->handle(0, 'foo', 'foo.php', 12, array()));
restore_error_handler();
$handler = ErrorHandler::register(3);
$this->assertFalse($handler->handle(4, 'foo', 'foo.php', 12, 'foo'));
$this->assertFalse($handler->handle(4, 'foo', 'foo.php', 12, array()));
restore_error_handler();
$handler = ErrorHandler::register(3);
try {
$handler->handle(111, 'foo', 'foo.php', 12, 'foo');
$handler->handle(111, 'foo', 'foo.php', 12, array());
} catch (\ErrorException $e) {
$this->assertSame('111: foo in foo.php line 12', $e->getMessage());
$this->assertSame(111, $e->getSeverity());
@@ -187,19 +187,19 @@ PHP
restore_error_handler();
$handler = ErrorHandler::register(E_USER_DEPRECATED);
$this->assertTrue($handler->handle(E_USER_DEPRECATED, 'foo', 'foo.php', 12, 'foo'));
$this->assertTrue($handler->handle(E_USER_DEPRECATED, 'foo', 'foo.php', 12, array()));
restore_error_handler();
$handler = ErrorHandler::register(E_DEPRECATED);
$this->assertTrue($handler->handle(E_DEPRECATED, 'foo', 'foo.php', 12, 'foo'));
$this->assertTrue($handler->handle(E_DEPRECATED, 'foo', 'foo.php', 12, array()));
restore_error_handler();
$logger = $this->getMock('Psr\Log\LoggerInterface');
$that = $this;
$warnArgCheck = function($message, $context) use ($that) {
$warnArgCheck = function ($message, $context) use ($that) {
$that->assertEquals('foo', $message);
$that->assertArrayHasKey('type', $context);
$that->assertEquals($context['type'], ErrorHandler::TYPE_DEPRECATION);
@@ -215,7 +215,7 @@ PHP
$handler = ErrorHandler::register(E_USER_DEPRECATED);
$handler->setLogger($logger);
$handler->handle(E_USER_DEPRECATED, 'foo', 'foo.php', 12, 'foo');
$handler->handle(E_USER_DEPRECATED, 'foo', 'foo.php', 12, array());
restore_error_handler();
}

View File

@@ -113,8 +113,7 @@ class FlattenExceptionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($exception->getMessage(), $flattened->getMessage(), 'The message is copied from the original exception.');
$this->assertEquals($exception->getCode(), $flattened->getCode(), 'The code is copied from the original exception.');
$this->assertEquals(get_class($exception), $flattened->getClass(), 'The class is set to the class of the original exception');
$this->assertInstanceOf($flattened->getClass(), $exception, 'The class is set to the class of the original exception');
}
/**
@@ -160,13 +159,13 @@ class FlattenExceptionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array(
array(
'message'=> 'test',
'class'=>'Exception',
'trace'=>array(array(
'message' => 'test',
'class' => 'Exception',
'trace' => array(array(
'namespace' => '', 'short_class' => '', 'class' => '','type' => '','function' => '', 'file' => 'foo.php', 'line' => 123,
'args' => array()
'args' => array(),
)),
)
),
), $flattened->toArray());
}
@@ -202,7 +201,7 @@ class FlattenExceptionTest extends \PHPUnit_Framework_TestCase
'line' => 123,
'function' => 'test',
'args' => array(
unserialize('O:14:"BogusTestClass":0:{}')
unserialize('O:14:"BogusTestClass":0:{}'),
),
),
),
@@ -211,9 +210,9 @@ class FlattenExceptionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array(
array(
'message'=> 'test',
'class'=>'Exception',
'trace'=>array(
'message' => 'test',
'class' => 'Exception',
'trace' => array(
array(
'namespace' => '', 'short_class' => '', 'class' => '','type' => '','function' => '',
'file' => 'foo.php', 'line' => 123,
@@ -224,12 +223,12 @@ class FlattenExceptionTest extends \PHPUnit_Framework_TestCase
'file' => __FILE__, 'line' => 123,
'args' => array(
array(
'incomplete-object', 'BogusTestClass'
'incomplete-object', 'BogusTestClass',
),
),
)
),
),
)
),
), $flattened->toArray());
}
}

View File

@@ -64,6 +64,6 @@ class ExceptionHandlerTest extends \PHPUnit_Framework_TestCase
public function testNestedExceptions()
{
$handler = new ExceptionHandler(true);
$response = $handler->createResponse(new \RuntimeException('Foo', null, new \RuntimeException('Bar')));
$response = $handler->createResponse(new \RuntimeException('Foo', 0, new \RuntimeException('Bar')));
}
}

View File

@@ -1,14 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>