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