[PhpUnitBridge] fix compat with symfony/debug

This commit is contained in:
Nicolas Grekas 2021-03-17 09:49:43 +01:00
parent a78fb1832b
commit 35dd54a654

View File

@ -11,6 +11,8 @@
namespace Symfony\Bridge\PhpUnit\DeprecationErrorHandler; namespace Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Util\Test; use PHPUnit\Util\Test;
use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerFor; use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerFor;
use Symfony\Component\Debug\DebugClassLoader as LegacyDebugClassLoader; use Symfony\Component\Debug\DebugClassLoader as LegacyDebugClassLoader;
@ -82,37 +84,41 @@ class Deprecation
} }
} }
if (isset($line['object']) || isset($line['class'])) { if (!isset($line['object']) && !isset($line['class'])) {
if (!isset($line['class'], $trace[$i - 2]['function']) || 0 !== strpos($line['class'], SymfonyTestsListenerFor::class)) { return;
$this->originClass = isset($line['object']) ? \get_class($line['object']) : $line['class']; }
$this->originMethod = $line['function'];
return; if (!isset($line['class'], $trace[$i - 2]['function']) || 0 !== strpos($line['class'], SymfonyTestsListenerFor::class)) {
} $this->originClass = isset($line['object']) ? \get_class($line['object']) : $line['class'];
$this->originMethod = $line['function'];
if ('trigger_error' !== $trace[$i - 2]['function'] || isset($trace[$i - 2]['class'])) { return;
$this->originClass = \get_class($line['args'][0]); }
$this->originMethod = $line['args'][0]->getName();
return; $test = isset($line['args'][0]) ? $line['args'][0] : null;
}
set_error_handler(function () {}); if (($test instanceof TestCase || $test instanceof TestSuite) && ('trigger_error' !== $trace[$i - 2]['function'] || isset($trace[$i - 2]['class']))) {
$parsedMsg = unserialize($this->message); $this->originClass = \get_class($line['args'][0]);
restore_error_handler(); $this->originMethod = $line['args'][0]->getName();
$this->message = $parsedMsg['deprecation'];
$this->originClass = $parsedMsg['class']; return;
$this->originMethod = $parsedMsg['method']; }
if (isset($parsedMsg['files_stack'])) {
$this->originalFilesStack = $parsedMsg['files_stack']; set_error_handler(function () {});
} $parsedMsg = unserialize($this->message);
// If the deprecation has been triggered via restore_error_handler();
// \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest() $this->message = $parsedMsg['deprecation'];
// then we need to use the serialized information to determine $this->originClass = $parsedMsg['class'];
// if the error has been triggered from vendor code. $this->originMethod = $parsedMsg['method'];
if (isset($parsedMsg['triggering_file'])) { if (isset($parsedMsg['files_stack'])) {
$this->triggeringFile = $parsedMsg['triggering_file']; $this->originalFilesStack = $parsedMsg['files_stack'];
} }
// If the deprecation has been triggered via
// \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest()
// then we need to use the serialized information to determine
// if the error has been triggered from vendor code.
if (isset($parsedMsg['triggering_file'])) {
$this->triggeringFile = $parsedMsg['triggering_file'];
} }
} }