Skip to content

Commit 5515d56

Browse files
Merge branch '5.0' into 5.1
* 5.0: Parse and render anonymous classes correctly on php 8 Enable APCu for the php 8 build. [Process] Fix failing test on php 8. [HttpKernel] fix test Make PHP 8 green on Travis Revert "[Cache] allow DBAL v3" [PropertyAccessor] Added missing property path on php 8. Don't execute tests with DBAL 2.x on php 8.
2 parents 6c1ee65 + 2c7376e commit 5515d56

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

Exception/FlattenException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static function createFromThrowable(\Throwable $exception, int $statusCod
7575
$e->setStatusCode($statusCode);
7676
$e->setHeaders($headers);
7777
$e->setTraceFromThrowable($exception);
78-
$e->setClass(\get_class($exception));
78+
$e->setClass(get_debug_type($exception));
7979
$e->setFile($exception->getFile());
8080
$e->setLine($exception->getLine());
8181

Tests/ErrorHandlerTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,26 @@ public function testHandleUserError()
365365
}
366366
}
367367

368+
public function testHandleErrorWithAnonymousClass()
369+
{
370+
$handler = ErrorHandler::register();
371+
$handler->throwAt(3, true);
372+
try {
373+
$handler->handleError(3, 'foo '.\get_class(new class() extends \stdClass {
374+
}).' bar', 'foo.php', 12);
375+
$this->fail('Exception expected.');
376+
} catch (\ErrorException $e) {
377+
} finally {
378+
restore_error_handler();
379+
restore_exception_handler();
380+
}
381+
382+
$this->assertSame('foo stdClass@anonymous bar', $e->getMessage());
383+
$this->assertSame(3, $e->getSeverity());
384+
$this->assertSame('foo.php', $e->getFile());
385+
$this->assertSame(12, $e->getLine());
386+
}
387+
368388
public function testHandleDeprecation()
369389
{
370390
$logArgCheck = function ($level, $message, $context) {
@@ -433,6 +453,10 @@ public function handleExceptionProvider(): array
433453
{
434454
return [
435455
['Uncaught Exception: foo', new \Exception('foo')],
456+
['Uncaught Exception: foo', new class('foo') extends \RuntimeException {
457+
}],
458+
['Uncaught Exception: foo stdClass@anonymous bar', new \RuntimeException('foo '.\get_class(new class() extends \stdClass {
459+
}).' bar')],
436460
['Uncaught Error: bar', new \Error('bar')],
437461
['Uncaught ccc', new \ErrorException('ccc')],
438462
];

Tests/Exception/FlattenExceptionTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,11 @@ public function testAnonymousClass()
359359

360360
$this->assertSame('RuntimeException@anonymous', $flattened->getClass());
361361

362+
$flattened->setClass(\get_class(new class('Oops') extends NotFoundHttpException {
363+
}));
364+
365+
$this->assertSame('Symfony\Component\HttpKernel\Exception\NotFoundHttpException@anonymous', $flattened->getClass());
366+
362367
$flattened = FlattenException::createFromThrowable(new \Exception(sprintf('Class "%s" blah.', \get_class(new class() extends \RuntimeException {
363368
}))));
364369

0 commit comments

Comments
 (0)