Skip to content

Commit 6691b31

Browse files
[PhpUnitBridge] fix compat with symfony/debug
1 parent 847101d commit 6691b31

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

DeprecationErrorHandler/Deprecation.php

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
1313

14+
use PHPUnit\Framework\TestCase;
15+
use PHPUnit\Framework\TestSuite;
1416
use PHPUnit\Util\Test;
1517
use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerFor;
1618
use Symfony\Component\Debug\DebugClassLoader as LegacyDebugClassLoader;
@@ -82,37 +84,41 @@ public function __construct($message, array $trace, $file)
8284
}
8385
}
8486

85-
if (isset($line['object']) || isset($line['class'])) {
86-
if (!isset($line['class'], $trace[$i - 2]['function']) || 0 !== strpos($line['class'], SymfonyTestsListenerFor::class)) {
87-
$this->originClass = isset($line['object']) ? \get_class($line['object']) : $line['class'];
88-
$this->originMethod = $line['function'];
87+
if (!isset($line['object']) && !isset($line['class'])) {
88+
return;
89+
}
8990

90-
return;
91-
}
91+
if (!isset($line['class'], $trace[$i - 2]['function']) || 0 !== strpos($line['class'], SymfonyTestsListenerFor::class)) {
92+
$this->originClass = isset($line['object']) ? \get_class($line['object']) : $line['class'];
93+
$this->originMethod = $line['function'];
9294

93-
if ('trigger_error' !== $trace[$i - 2]['function'] || isset($trace[$i - 2]['class'])) {
94-
$this->originClass = \get_class($line['args'][0]);
95-
$this->originMethod = $line['args'][0]->getName();
95+
return;
96+
}
9697

97-
return;
98-
}
98+
$test = isset($line['args'][0]) ? $line['args'][0] : null;
9999

100-
set_error_handler(function () {});
101-
$parsedMsg = unserialize($this->message);
102-
restore_error_handler();
103-
$this->message = $parsedMsg['deprecation'];
104-
$this->originClass = $parsedMsg['class'];
105-
$this->originMethod = $parsedMsg['method'];
106-
if (isset($parsedMsg['files_stack'])) {
107-
$this->originalFilesStack = $parsedMsg['files_stack'];
108-
}
109-
// If the deprecation has been triggered via
110-
// \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest()
111-
// then we need to use the serialized information to determine
112-
// if the error has been triggered from vendor code.
113-
if (isset($parsedMsg['triggering_file'])) {
114-
$this->triggeringFile = $parsedMsg['triggering_file'];
115-
}
100+
if (($test instanceof TestCase || $test instanceof TestSuite) && ('trigger_error' !== $trace[$i - 2]['function'] || isset($trace[$i - 2]['class']))) {
101+
$this->originClass = \get_class($line['args'][0]);
102+
$this->originMethod = $line['args'][0]->getName();
103+
104+
return;
105+
}
106+
107+
set_error_handler(function () {});
108+
$parsedMsg = unserialize($this->message);
109+
restore_error_handler();
110+
$this->message = $parsedMsg['deprecation'];
111+
$this->originClass = $parsedMsg['class'];
112+
$this->originMethod = $parsedMsg['method'];
113+
if (isset($parsedMsg['files_stack'])) {
114+
$this->originalFilesStack = $parsedMsg['files_stack'];
115+
}
116+
// If the deprecation has been triggered via
117+
// \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest()
118+
// then we need to use the serialized information to determine
119+
// if the error has been triggered from vendor code.
120+
if (isset($parsedMsg['triggering_file'])) {
121+
$this->triggeringFile = $parsedMsg['triggering_file'];
116122
}
117123
}
118124

0 commit comments

Comments
 (0)