Skip to content

Commit 850e71f

Browse files
Merge branch '4.3' into 4.4
* 4.3: Minor fixes [HttpClient] Minor fixes Use namespaced Phpunit classes [Messenger] Fixed ConsumeMessagesCommand configuration [Form] remove leftover int child phpdoc Support DateTimeInterface in IntlDateFormatter::format [PhpUnitBridge] fixed PHPUnit 8.3 compatibility: method handleError was renamed to __invoke fixed phpdocs Use PHPunit assertion [Intl] Order alpha2 to alpha3 mapping + phpdoc fixes
2 parents 30925f5 + e425b6a commit 850e71f

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

DeprecationErrorHandler.php

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

1212
namespace Symfony\Bridge\PhpUnit;
1313

14+
use PHPUnit\Framework\TestResult;
1415
use PHPUnit\Util\ErrorHandler;
1516
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Configuration;
1617
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation;
@@ -49,6 +50,7 @@ class DeprecationErrorHandler
4950
];
5051

5152
private static $isRegistered = false;
53+
private static $isAtLeastPhpUnit83;
5254

5355
/**
5456
* Registers and configures the deprecation handler.
@@ -72,13 +74,15 @@ public static function register($mode = 0)
7274
return;
7375
}
7476

77+
self::$isAtLeastPhpUnit83 = !class_exists('PHPUnit_Util_ErrorHandler') && method_exists(ErrorHandler::class, '__invoke');
78+
7579
$handler = new self();
7680
$oldErrorHandler = set_error_handler([$handler, 'handleError']);
7781

7882
if (null !== $oldErrorHandler) {
7983
restore_error_handler();
8084

81-
if ([ErrorHandler::class, 'handleError'] === $oldErrorHandler) {
85+
if ($oldErrorHandler instanceof ErrorHandler || [ErrorHandler::class, 'handleError'] === $oldErrorHandler) {
8286
restore_error_handler();
8387
self::register($mode);
8488
}
@@ -98,7 +102,7 @@ public static function collectDeprecations($outputFile)
98102
return $previousErrorHandler($type, $msg, $file, $line, $context);
99103
}
100104

101-
return ErrorHandler::handleError($type, $msg, $file, $line, $context);
105+
return \call_user_func(self::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context);
102106
}
103107

104108
$deprecations[] = [error_reporting(), $msg, $file];
@@ -115,7 +119,7 @@ public static function collectDeprecations($outputFile)
115119
public function handleError($type, $msg, $file, $line, $context = [])
116120
{
117121
if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || !$this->getConfiguration()->isEnabled()) {
118-
return ErrorHandler::handleError($type, $msg, $file, $line, $context);
122+
return \call_user_func(self::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context);
119123
}
120124

121125
$deprecation = new Deprecation($msg, debug_backtrace(), $file);
@@ -310,6 +314,26 @@ private function displayDeprecations($groups, $configuration)
310314
}
311315
}
312316

317+
private static function getPhpUnitErrorHandler()
318+
{
319+
if (!self::$isAtLeastPhpUnit83) {
320+
return 'PHPUnit\Util\ErrorHandler::handleError';
321+
}
322+
323+
foreach (debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) {
324+
if (isset($frame['object']) && $frame['object'] instanceof TestResult) {
325+
return new ErrorHandler(
326+
$frame['object']->getConvertDeprecationsToExceptions(),
327+
$frame['object']->getConvertErrorsToExceptions(),
328+
$frame['object']->getConvertNoticesToExceptions(),
329+
$frame['object']->getConvertWarningsToExceptions()
330+
);
331+
}
332+
}
333+
334+
return function () { return false; };
335+
}
336+
313337
/**
314338
* Returns true if STDOUT is defined and supports colorization.
315339
*

Legacy/PolyfillTestCaseTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616

1717
/**
18-
* This trait is @internal
18+
* This trait is @internal.
1919
*/
2020
trait PolyfillTestCaseTrait
2121
{

Tests/ProcessIsolationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testIsolation()
2424

2525
public function testCallingOtherErrorHandler()
2626
{
27-
$this->expectException(\class_exists('PHPUnit_Framework_Exception') ? 'PHPUnit_Framework_Exception' : 'PHPUnit\Framework\Exception');
27+
$this->expectException('PHPUnit\Framework\Exception');
2828
$this->expectExceptionMessage('Test that PHPUnit\'s error handler fires.');
2929

3030
trigger_error('Test that PHPUnit\'s error handler fires.', E_USER_WARNING);

0 commit comments

Comments
 (0)