Skip to content

Commit 49e1f32

Browse files
Merge branch '4.4' into 5.2
* 4.4: [Console] Fix line wrapping for decorated text in block output [Inflector] Fixed pluralize "coupon" [PhpUnitBridge] fix compat with symfony/debug [VarDumper] Adds support for ReflectionUnionType to VarDumper Correctly clear lines for multi-line progress bar messages.
2 parents 9d85d90 + 6691b31 commit 49e1f32

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

DeprecationErrorHandler/Deprecation.php

+35-29
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;
@@ -87,41 +89,45 @@ public function __construct($message, array $trace, $file)
8789
}
8890
}
8991

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+
}
10895

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'];
110105
}
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+
}
111116

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'];
115120

116-
return;
117-
}
121+
return;
122+
}
118123

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;
122125

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;
125131
}
126132
}
127133

0 commit comments

Comments
 (0)