[PhpUnitBridge] Fix deprecation handler with PHPUnit 10
This commit is contained in:
parent
97d48476f7
commit
5f90fb0fd6
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Bridge\PhpUnit;
|
||||
|
||||
use PHPUnit\Framework\TestResult;
|
||||
use PHPUnit\Util\Error\Handler;
|
||||
use PHPUnit\Util\ErrorHandler;
|
||||
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Configuration;
|
||||
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation;
|
||||
@ -51,7 +52,7 @@ class DeprecationErrorHandler
|
||||
];
|
||||
|
||||
private static $isRegistered = false;
|
||||
private static $isAtLeastPhpUnit83;
|
||||
private static $errorHandler;
|
||||
|
||||
/**
|
||||
* Registers and configures the deprecation handler.
|
||||
@ -335,16 +336,23 @@ class DeprecationErrorHandler
|
||||
|
||||
private static function getPhpUnitErrorHandler()
|
||||
{
|
||||
if (!isset(self::$isAtLeastPhpUnit83)) {
|
||||
self::$isAtLeastPhpUnit83 = class_exists(ErrorHandler::class) && method_exists(ErrorHandler::class, '__invoke');
|
||||
if (!$eh = self::$errorHandler) {
|
||||
if (class_exists(Handler::class)) {
|
||||
$eh = self::$errorHandler = Handler::class;
|
||||
} elseif (method_exists(ErrorHandler::class, '__invoke')) {
|
||||
$eh = self::$errorHandler = ErrorHandler::class;
|
||||
} else {
|
||||
return self::$errorHandler = 'PHPUnit\Util\ErrorHandler::handleError';
|
||||
}
|
||||
}
|
||||
if (!self::$isAtLeastPhpUnit83) {
|
||||
return 'PHPUnit\Util\ErrorHandler::handleError';
|
||||
|
||||
if ('PHPUnit\Util\ErrorHandler::handleError' === $eh) {
|
||||
return $eh;
|
||||
}
|
||||
|
||||
foreach (debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) {
|
||||
if (isset($frame['object']) && $frame['object'] instanceof TestResult) {
|
||||
return new ErrorHandler(
|
||||
return new $eh(
|
||||
$frame['object']->getConvertDeprecationsToExceptions(),
|
||||
$frame['object']->getConvertErrorsToExceptions(),
|
||||
$frame['object']->getConvertNoticesToExceptions(),
|
||||
|
@ -13,6 +13,8 @@ namespace Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\TestSuite;
|
||||
use PHPUnit\Metadata\Api\Groups;
|
||||
use PHPUnit\Util\Error\Handler;
|
||||
use PHPUnit\Util\Test;
|
||||
use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerFor;
|
||||
use Symfony\Component\Debug\DebugClassLoader as LegacyDebugClassLoader;
|
||||
@ -192,12 +194,13 @@ class Deprecation
|
||||
}
|
||||
|
||||
$method = $this->originatingMethod();
|
||||
$groups = class_exists(Groups::class) ? [new Groups(), 'groups'] : [Test::class, 'getGroups'];
|
||||
|
||||
return 0 === strpos($method, 'testLegacy')
|
||||
|| 0 === strpos($method, 'provideLegacy')
|
||||
|| 0 === strpos($method, 'getLegacy')
|
||||
|| strpos($this->originClass, '\Legacy')
|
||||
|| \in_array('legacy', Test::getGroups($this->originClass, $method), true);
|
||||
|| \in_array('legacy', $groups($this->originClass, $method), true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user