Skip to content

Commit

Permalink
[ErrorHandler] Remove trigger_deprecation frame from trace (add tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyweb authored and nicolas-grekas committed Apr 6, 2020
1 parent c293aee commit d4eb4a4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/Symfony/Component/ErrorHandler/Tests/ErrorHandlerTest.php
Expand Up @@ -652,4 +652,29 @@ public function testAssertQuietEval()
$this->assertSame('warning', $logs[0][0]);
$this->assertSame('Warning: assert(): assert(false) failed', $logs[0][1]);
}

public function testHandleTriggerDeprecation()
{
try {
$handler = ErrorHandler::register();
$handler->setDefaultLogger($logger = new BufferingLogger());

$expectedLine = __LINE__ + 1;
trigger_deprecation('foo', '1.2.3', 'bar');

/** @var \ErrorException $exception */
$exception = $logger->cleanLogs()[0][2]['exception'];

$this->assertSame($expectedLine, $exception->getLine());
$this->assertSame(__FILE__, $exception->getFile());

$frame = $exception->getTrace()[0];
$this->assertSame(__CLASS__, $frame['class']);
$this->assertSame(__FUNCTION__, $frame['function']);
$this->assertSame('->', $frame['type']);
} finally {
restore_error_handler();
restore_exception_handler();
}
}
}
3 changes: 2 additions & 1 deletion src/Symfony/Component/ErrorHandler/composer.json
Expand Up @@ -23,7 +23,8 @@
},
"require-dev": {
"symfony/http-kernel": "^4.4|^5.0",
"symfony/serializer": "^4.4|^5.0"
"symfony/serializer": "^4.4|^5.0",
"symfony/deprecation-contracts": "^2.1"
},
"autoload": {
"psr-4": { "Symfony\\Component\\ErrorHandler\\": "" },
Expand Down

0 comments on commit d4eb4a4

Please sign in to comment.