|
11 | 11 |
|
12 | 12 | namespace Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
|
13 | 13 |
|
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use PHPUnit\Framework\TestSuite; |
14 | 16 | use PHPUnit\Util\Test;
|
15 | 17 | use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerFor;
|
16 | 18 | use Symfony\Component\Debug\DebugClassLoader as LegacyDebugClassLoader;
|
@@ -87,41 +89,45 @@ public function __construct($message, array $trace, $file)
|
87 | 89 | }
|
88 | 90 | }
|
89 | 91 |
|
90 |
| - if (isset($line['object']) || isset($line['class'])) { |
91 |
| - set_error_handler(function () {}); |
92 |
| - $parsedMsg = unserialize($this->message); |
93 |
| - restore_error_handler(); |
94 |
| - if ($parsedMsg && isset($parsedMsg['deprecation'])) { |
95 |
| - $this->message = $parsedMsg['deprecation']; |
96 |
| - $this->originClass = $parsedMsg['class']; |
97 |
| - $this->originMethod = $parsedMsg['method']; |
98 |
| - if (isset($parsedMsg['files_stack'])) { |
99 |
| - $this->originalFilesStack = $parsedMsg['files_stack']; |
100 |
| - } |
101 |
| - // If the deprecation has been triggered via |
102 |
| - // \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest() |
103 |
| - // then we need to use the serialized information to determine |
104 |
| - // if the error has been triggered from vendor code. |
105 |
| - if (isset($parsedMsg['triggering_file'])) { |
106 |
| - $this->triggeringFile = $parsedMsg['triggering_file']; |
107 |
| - } |
| 92 | + if (!isset($line['object']) && !isset($line['class'])) { |
| 93 | + return; |
| 94 | + } |
108 | 95 |
|
109 |
| - return; |
| 96 | + set_error_handler(function () {}); |
| 97 | + $parsedMsg = unserialize($this->message); |
| 98 | + restore_error_handler(); |
| 99 | + if ($parsedMsg && isset($parsedMsg['deprecation'])) { |
| 100 | + $this->message = $parsedMsg['deprecation']; |
| 101 | + $this->originClass = $parsedMsg['class']; |
| 102 | + $this->originMethod = $parsedMsg['method']; |
| 103 | + if (isset($parsedMsg['files_stack'])) { |
| 104 | + $this->originalFilesStack = $parsedMsg['files_stack']; |
110 | 105 | }
|
| 106 | + // If the deprecation has been triggered via |
| 107 | + // \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest() |
| 108 | + // then we need to use the serialized information to determine |
| 109 | + // if the error has been triggered from vendor code. |
| 110 | + if (isset($parsedMsg['triggering_file'])) { |
| 111 | + $this->triggeringFile = $parsedMsg['triggering_file']; |
| 112 | + } |
| 113 | + |
| 114 | + return; |
| 115 | + } |
111 | 116 |
|
112 |
| - if (!isset($line['class'], $trace[$i - 2]['function']) || 0 !== strpos($line['class'], SymfonyTestsListenerFor::class)) { |
113 |
| - $this->originClass = isset($line['object']) ? \get_class($line['object']) : $line['class']; |
114 |
| - $this->originMethod = $line['function']; |
| 117 | + if (!isset($line['class'], $trace[$i - 2]['function']) || 0 !== strpos($line['class'], SymfonyTestsListenerFor::class)) { |
| 118 | + $this->originClass = isset($line['object']) ? \get_class($line['object']) : $line['class']; |
| 119 | + $this->originMethod = $line['function']; |
115 | 120 |
|
116 |
| - return; |
117 |
| - } |
| 121 | + return; |
| 122 | + } |
118 | 123 |
|
119 |
| - if ('trigger_error' !== $trace[$i - 2]['function'] || isset($trace[$i - 2]['class'])) { |
120 |
| - $this->originClass = \get_class($line['args'][0]); |
121 |
| - $this->originMethod = $line['args'][0]->getName(); |
| 124 | + $test = $line['args'][0] ?? null; |
122 | 125 |
|
123 |
| - return; |
124 |
| - } |
| 126 | + if (($test instanceof TestCase || $test instanceof TestSuite) && ('trigger_error' !== $trace[$i - 2]['function'] || isset($trace[$i - 2]['class']))) { |
| 127 | + $this->originClass = \get_class($line['args'][0]); |
| 128 | + $this->originMethod = $line['args'][0]->getName(); |
| 129 | + |
| 130 | + return; |
125 | 131 | }
|
126 | 132 | }
|
127 | 133 |
|
|
0 commit comments