Skip to content

[PhpUnitBridge] Bump v7.4 to PHP >= 8.1 #61090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/phpunit-bridge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
coverage: "none"
php-version: "7.2"
php-version: "8.1"

- name: Lint
run: find ./src/Symfony/Bridge/PhpUnit -name '*.php' | grep -v -e /Tests/ -e /Attribute/ -e /Extension/ -e /Metadata/ -e ForV7 -e ForV8 -e ForV9 -e ConstraintLogicTrait -e SymfonyExtension | parallel -j 4 php -l {}
run: find ./src/Symfony/Bridge/PhpUnit -name '*.php' | grep -v -e /Tests/ -e /Attribute/ -e /Extension/ -e /Metadata/ -e ForV8 -e ForV9 -e ConstraintLogicTrait -e SymfonyExtension | parallel -j 4 php -l {}
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/PhpUnit/ClassExistsMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function trait_exists($name, $autoload = true): bool
return isset(self::$classes[$name]) ? (bool) self::$classes[$name] : \trait_exists($name, $autoload);
}

public static function enum_exists($name, $autoload = true):bool
public static function enum_exists($name, $autoload = true): bool
{
$name = ltrim($name, '\\');

Expand All @@ -77,7 +77,7 @@ public static function register($class): void
if (0 < strpos($class, '\\Tests\\')) {
$ns = str_replace('\\Tests\\', '\\', $class);
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
} elseif (0 === strpos($class, 'Tests\\')) {
} elseif (str_starts_with($class, 'Tests\\')) {
$mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6);
}
foreach ($mockedNs as $ns) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/PhpUnit/ClockMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static function register($class): void
if (0 < strpos($class, '\\Tests\\')) {
$ns = str_replace('\\Tests\\', '\\', $class);
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
} elseif (0 === strpos($class, 'Tests\\')) {
} elseif (str_starts_with($class, 'Tests\\')) {
$mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6);
}
foreach ($mockedNs as $ns) {
Expand Down
7 changes: 1 addition & 6 deletions src/Symfony/Bridge/PhpUnit/ConstraintTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
use PHPUnit\Framework\Constraint\Constraint;

$r = new \ReflectionClass(Constraint::class);
if ($r->getProperty('exporter')->isProtected()) {
trait ConstraintTrait
{
use Legacy\ConstraintTraitForV7;
}
} elseif (!$r->getMethod('evaluate')->hasReturnType()) {
if (!$r->getMethod('evaluate')->hasReturnType()) {
trait ConstraintTrait
{
use Legacy\ConstraintTraitForV8;
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Bridge/PhpUnit/CoverageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CoverageListener implements TestListener
public function __construct(?callable $sutFqcnResolver = null, bool $warningOnSutNotFound = false)
{
$this->sutFqcnResolver = $sutFqcnResolver ?? static function (Test $test): ?string {
$class = \get_class($test);
$class = $test::class;

$sutFqcn = str_replace('\\Tests\\', '\\', $class);
$sutFqcn = preg_replace('{Test$}', '', $sutFqcn);
Expand All @@ -46,7 +46,7 @@ public function startTest(Test $test): void
return;
}

$annotations = TestUtil::parseTestMethodAnnotations(\get_class($test), $test->getName(false));
$annotations = TestUtil::parseTestMethodAnnotations($test::class, $test->getName(false));

$ignoredAnnotations = ['covers', 'coversDefaultClass', 'coversNothing'];

Expand Down Expand Up @@ -90,7 +90,7 @@ private function addCoversForClassToAnnotationCache(Test $test, array $covers):

$cache = $r->getValue();
$cache = array_replace_recursive($cache, [
\get_class($test) => [
$test::class => [
'covers' => $covers,
],
]);
Expand All @@ -100,7 +100,7 @@ private function addCoversForClassToAnnotationCache(Test $test, array $covers):

private function addCoversForDocBlockInsideRegistry(Test $test, array $covers): void
{
$docBlock = Registry::getInstance()->forClassName(\get_class($test));
$docBlock = Registry::getInstance()->forClassName($test::class);

$symbolAnnotations = new \ReflectionProperty($docBlock, 'symbolAnnotations');
$symbolAnnotations->setAccessible(true);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static function collectDeprecations($outputFile)
{
$deprecations = [];
$previousErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$deprecations, &$previousErrorHandler) {
if (\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || false === strpos($msg, '" targeting switch is equivalent to "break'))) {
if (\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || !str_contains($msg, '" targeting switch is equivalent to "break'))) {
if ($previousErrorHandler) {
return $previousErrorHandler($type, $msg, $file, $line, $context);
}
Expand Down Expand Up @@ -129,7 +129,7 @@ public static function collectDeprecations($outputFile)
*/
public function handleError($type, $msg, $file, $line, $context = [])
{
if ((\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || false === strpos($msg, '" targeting switch is equivalent to "break'))) || !$this->getConfiguration()->isEnabled()) {
if ((\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || !str_contains($msg, '" targeting switch is equivalent to "break'))) || !$this->getConfiguration()->isEnabled()) {
return \call_user_func(self::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context);
}

Expand Down
30 changes: 15 additions & 15 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function __construct(string $message, array $trace, string $file, bool $l
$this->getOriginalFilesStack();
array_splice($this->originalFilesStack, 0, $j, [$this->triggeringFile]);

if (preg_match('/(?|"([^"]++)" that is deprecated|should implement method "(?:static )?([^:]++))/', $message, $m) || (false === strpos($message, '()" will return') && false === strpos($message, 'native return type declaration') && preg_match('/^(?:The|Method) "([^":]++)/', $message, $m))) {
if (preg_match('/(?|"([^"]++)" that is deprecated|should implement method "(?:static )?([^:]++))/', $message, $m) || (!str_contains($message, '()" will return') && !str_contains($message, 'native return type declaration') && preg_match('/^(?:The|Method) "([^":]++)/', $message, $m))) {
$this->triggeringFile = (new \ReflectionClass($m[1]))->getFileName();
array_unshift($this->originalFilesStack, $this->triggeringFile);
}
Expand Down Expand Up @@ -137,7 +137,7 @@ public function __construct(string $message, array $trace, string $file, bool $l
return;
}

if (!isset($line['class'], $trace[$i - 2]['function']) || 0 !== strpos($line['class'], SymfonyTestsListenerFor::class)) {
if (!isset($line['class'], $trace[$i - 2]['function']) || !str_starts_with($line['class'], SymfonyTestsListenerFor::class)) {
$this->originClass = isset($line['object']) ? \get_class($line['object']) : $line['class'];
$this->originMethod = $line['function'];

Expand All @@ -147,7 +147,7 @@ public function __construct(string $message, array $trace, string $file, bool $l
$test = $line['args'][0] ?? null;

if (($test instanceof TestCase || $test instanceof TestSuite) && ('trigger_error' !== $trace[$i - 2]['function'] || isset($trace[$i - 2]['class']))) {
$this->originClass = \get_class($test);
$this->originClass = $test::class;
$this->originMethod = $test->getName();
}
}
Expand All @@ -159,7 +159,7 @@ private function lineShouldBeSkipped(array $line): bool
}
$class = $line['class'];

return 'ReflectionMethod' === $class || 0 === strpos($class, 'PHPUnit\\');
return 'ReflectionMethod' === $class || str_starts_with($class, 'PHPUnit\\');
}

public function originatesFromDebugClassLoader(): bool
Expand Down Expand Up @@ -189,7 +189,7 @@ public function originatingClass(): string

$class = $this->originClass;

return false !== strpos($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class;
return str_contains($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class;
}

public function originatingMethod(): string
Expand All @@ -215,9 +215,9 @@ public function isLegacy(): bool
$method = $this->originatingMethod();
$groups = class_exists(Groups::class, false) ? [new Groups(), 'groups'] : [Test::class, 'getGroups'];

return 0 === strpos($method, 'testLegacy')
|| 0 === strpos($method, 'provideLegacy')
|| 0 === strpos($method, 'getLegacy')
return str_starts_with($method, 'testLegacy')
|| str_starts_with($method, 'provideLegacy')
|| str_starts_with($method, 'getLegacy')
|| strpos($this->originClass, '\Legacy')
|| \in_array('legacy', $groups($this->originClass, $method), true);
}
Expand All @@ -228,10 +228,10 @@ public function isMuted(): bool
return false;
}
if (isset($this->trace[1]['class'])) {
return 0 === strpos($this->trace[1]['class'], 'PHPUnit\\');
return str_starts_with($this->trace[1]['class'], 'PHPUnit\\');
}

return false !== strpos($this->triggeringFile, \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR.'phpunit'.\DIRECTORY_SEPARATOR);
return str_contains($this->triggeringFile, \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR.'phpunit'.\DIRECTORY_SEPARATOR);
}

/**
Expand Down Expand Up @@ -300,7 +300,7 @@ private function getPackage(string $path): string
{
$path = realpath($path) ?: $path;
foreach (self::getVendors() as $vendorRoot) {
if (0 === strpos($path, $vendorRoot)) {
if (str_starts_with($path, $vendorRoot)) {
$relativePath = substr($path, \strlen($vendorRoot) + 1);
$vendor = strstr($relativePath, \DIRECTORY_SEPARATOR, true);
if (false === $vendor) {
Expand All @@ -326,7 +326,7 @@ private static function getVendors(): array
self::$vendors[] = \dirname((new \ReflectionClass(DebugClassLoader::class))->getFileName());
}
foreach (get_declared_classes() as $class) {
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
if ('C' === $class[0] && str_starts_with($class, 'ComposerAutoloaderInit')) {
$r = new \ReflectionClass($class);
$v = \dirname($r->getFileName(), 2);
if (file_exists($v.'/composer/installed.json')) {
Expand All @@ -341,7 +341,7 @@ private static function getVendors(): array
}
foreach ($paths as $path) {
foreach (self::$vendors as $vendor) {
if (0 !== strpos($path, $vendor)) {
if (!str_starts_with($path, $vendor)) {
self::$internalPaths[] = $path;
}
}
Expand Down Expand Up @@ -371,13 +371,13 @@ private function getPathType(string $path): string
return self::PATH_TYPE_UNDETERMINED;
}
foreach (self::getVendors() as $vendor) {
if (0 === strpos($realPath, $vendor) && false !== strpbrk(substr($realPath, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) {
if (str_starts_with($realPath, $vendor) && false !== strpbrk(substr($realPath, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) {
return self::PATH_TYPE_VENDOR;
}
}

foreach (self::$internalPaths as $internalPath) {
if (0 === strpos($realPath, $internalPath)) {
if (str_starts_with($realPath, $internalPath)) {
return self::PATH_TYPE_SELF;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/PhpUnit/DnsMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public static function register($class): void
if (0 < strpos($class, '\\Tests\\')) {
$ns = str_replace('\\Tests\\', '\\', $class);
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
} elseif (0 === strpos($class, 'Tests\\')) {
} elseif (str_starts_with($class, 'Tests\\')) {
$mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6);
}
foreach ($mockedNs as $ns) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* @internal
*/
class CommandForV7 extends BaseCommand
class CommandForV8 extends BaseCommand
{
protected function createRunner(): BaseRunner
{
Expand All @@ -29,7 +29,7 @@

foreach ($this->arguments['listeners'] as $registeredListener) {
if ($registeredListener instanceof SymfonyTestsListener) {
$registeredListener->globalListenerDisabled();

Check failure on line 32 in src/Symfony/Bridge/PhpUnit/Legacy/CommandForV8.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedMethod

src/Symfony/Bridge/PhpUnit/Legacy/CommandForV8.php:32:38: UndefinedMethod: Method Symfony\Bridge\PhpUnit\SymfonyTestsListener::globalListenerDisabled does not exist (see https://psalm.dev/022)

Check failure on line 32 in src/Symfony/Bridge/PhpUnit/Legacy/CommandForV8.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedMethod

src/Symfony/Bridge/PhpUnit/Legacy/CommandForV8.php:32:38: UndefinedMethod: Method Symfony\Bridge\PhpUnit\SymfonyTestsListener::globalListenerDisabled does not exist (see https://psalm.dev/022)
$registeredLocally = true;
break;
}
Expand All @@ -37,7 +37,7 @@

if (isset($this->arguments['configuration'])) {
$configuration = $this->arguments['configuration'];
if (!$configuration instanceof Configuration) {

Check failure on line 40 in src/Symfony/Bridge/PhpUnit/Legacy/CommandForV8.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedClass

src/Symfony/Bridge/PhpUnit/Legacy/CommandForV8.php:40:44: UndefinedClass: Class, interface or enum named PHPUnit\Util\Configuration does not exist (see https://psalm.dev/019)

Check failure on line 40 in src/Symfony/Bridge/PhpUnit/Legacy/CommandForV8.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedClass

src/Symfony/Bridge/PhpUnit/Legacy/CommandForV8.php:40:44: UndefinedClass: Class, interface or enum named PHPUnit\Util\Configuration does not exist (see https://psalm.dev/019)
$configuration = Configuration::getInstance($this->arguments['configuration']);
}
foreach ($configuration->getListenerConfiguration() as $registeredListener) {
Expand Down
64 changes: 0 additions & 64 deletions src/Symfony/Bridge/PhpUnit/Legacy/ConstraintTraitForV7.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait ExpectDeprecationTraitForV8_4
public function expectDeprecation(): void
{
if (1 > \func_num_args() || !\is_string($message = func_get_arg(0))) {
throw new \InvalidArgumentException(sprintf('The "%s()" method requires the string $message argument.', __FUNCTION__));
throw new \InvalidArgumentException(\sprintf('The "%s()" method requires the string $message argument.', __FUNCTION__));
}

// Expected deprecations set by isolated tests need to be written to a file
Expand Down Expand Up @@ -52,14 +52,14 @@ public function expectDeprecation(): void
*/
public function expectDeprecationMessage(string $message): void
{
throw new \BadMethodCallException(sprintf('The "%s()" method is not supported by Symfony\'s PHPUnit Bridge ExpectDeprecationTrait, pass the message to expectDeprecation() instead.', __FUNCTION__));
throw new \BadMethodCallException(\sprintf('The "%s()" method is not supported by Symfony\'s PHPUnit Bridge ExpectDeprecationTrait, pass the message to expectDeprecation() instead.', __FUNCTION__));
}

/**
* @internal use expectDeprecation() instead
*/
public function expectDeprecationMessageMatches(string $regularExpression): void
{
throw new \BadMethodCallException(sprintf('The "%s()" method is not supported by Symfony\'s PHPUnit Bridge ExpectDeprecationTrait.', __FUNCTION__));
throw new \BadMethodCallException(\sprintf('The "%s()" method is not supported by Symfony\'s PHPUnit Bridge ExpectDeprecationTrait.', __FUNCTION__));
}
}
Loading
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy