Skip to content

Commit d4ef079

Browse files
[PhpUnitBridge] Bump v7.4 to PHP >= 8.1
1 parent 36d8d5d commit d4ef079

40 files changed

+232
-179
lines changed

.github/workflows/phpunit-bridge.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
uses: shivammathur/setup-php@v2
3333
with:
3434
coverage: "none"
35-
php-version: "7.2"
35+
php-version: "8.1"
3636

3737
- name: Lint
38-
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 {}
38+
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 {}

src/Symfony/Bridge/PhpUnit/ClassExistsMock.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static function trait_exists($name, $autoload = true): bool
6262
return isset(self::$classes[$name]) ? (bool) self::$classes[$name] : \trait_exists($name, $autoload);
6363
}
6464

65-
public static function enum_exists($name, $autoload = true):bool
65+
public static function enum_exists($name, $autoload = true): bool
6666
{
6767
$name = ltrim($name, '\\');
6868

@@ -77,7 +77,7 @@ public static function register($class): void
7777
if (0 < strpos($class, '\\Tests\\')) {
7878
$ns = str_replace('\\Tests\\', '\\', $class);
7979
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
80-
} elseif (0 === strpos($class, 'Tests\\')) {
80+
} elseif (str_starts_with($class, 'Tests\\')) {
8181
$mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6);
8282
}
8383
foreach ($mockedNs as $ns) {

src/Symfony/Bridge/PhpUnit/ClockMock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public static function register($class): void
129129
if (0 < strpos($class, '\\Tests\\')) {
130130
$ns = str_replace('\\Tests\\', '\\', $class);
131131
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
132-
} elseif (0 === strpos($class, 'Tests\\')) {
132+
} elseif (str_starts_with($class, 'Tests\\')) {
133133
$mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6);
134134
}
135135
foreach ($mockedNs as $ns) {

src/Symfony/Bridge/PhpUnit/ConstraintTrait.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@
1414
use PHPUnit\Framework\Constraint\Constraint;
1515

1616
$r = new \ReflectionClass(Constraint::class);
17-
if ($r->getProperty('exporter')->isProtected()) {
18-
trait ConstraintTrait
19-
{
20-
use Legacy\ConstraintTraitForV7;
21-
}
22-
} elseif (!$r->getMethod('evaluate')->hasReturnType()) {
17+
if (!$r->getMethod('evaluate')->hasReturnType()) {
2318
trait ConstraintTrait
2419
{
2520
use Legacy\ConstraintTraitForV8;

src/Symfony/Bridge/PhpUnit/CoverageListener.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CoverageListener implements TestListener
2929
public function __construct(?callable $sutFqcnResolver = null, bool $warningOnSutNotFound = false)
3030
{
3131
$this->sutFqcnResolver = $sutFqcnResolver ?? static function (Test $test): ?string {
32-
$class = \get_class($test);
32+
$class = $test::class;
3333

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

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

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

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

9191
$cache = $r->getValue();
9292
$cache = array_replace_recursive($cache, [
93-
\get_class($test) => [
93+
$test::class => [
9494
'covers' => $covers,
9595
],
9696
]);
@@ -100,7 +100,7 @@ private function addCoversForClassToAnnotationCache(Test $test, array $covers):
100100

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

105105
$symbolAnnotations = new \ReflectionProperty($docBlock, 'symbolAnnotations');
106106
$symbolAnnotations->setAccessible(true);

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static function collectDeprecations($outputFile)
9797
{
9898
$deprecations = [];
9999
$previousErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$deprecations, &$previousErrorHandler) {
100-
if (\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || false === strpos($msg, '" targeting switch is equivalent to "break'))) {
100+
if (\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || !str_contains($msg, '" targeting switch is equivalent to "break'))) {
101101
if ($previousErrorHandler) {
102102
return $previousErrorHandler($type, $msg, $file, $line, $context);
103103
}
@@ -129,7 +129,7 @@ public static function collectDeprecations($outputFile)
129129
*/
130130
public function handleError($type, $msg, $file, $line, $context = [])
131131
{
132-
if ((\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || false === strpos($msg, '" targeting switch is equivalent to "break'))) || !$this->getConfiguration()->isEnabled()) {
132+
if ((\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || !str_contains($msg, '" targeting switch is equivalent to "break'))) || !$this->getConfiguration()->isEnabled()) {
133133
return \call_user_func(self::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context);
134134
}
135135

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function __construct(string $message, array $trace, string $file, bool $l
9999
$this->getOriginalFilesStack();
100100
array_splice($this->originalFilesStack, 0, $j, [$this->triggeringFile]);
101101

102-
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))) {
102+
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))) {
103103
$this->triggeringFile = (new \ReflectionClass($m[1]))->getFileName();
104104
array_unshift($this->originalFilesStack, $this->triggeringFile);
105105
}
@@ -137,7 +137,7 @@ public function __construct(string $message, array $trace, string $file, bool $l
137137
return;
138138
}
139139

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

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

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

162-
return 'ReflectionMethod' === $class || 0 === strpos($class, 'PHPUnit\\');
162+
return 'ReflectionMethod' === $class || str_starts_with($class, 'PHPUnit\\');
163163
}
164164

165165
public function originatesFromDebugClassLoader(): bool
@@ -189,7 +189,7 @@ public function originatingClass(): string
189189

190190
$class = $this->originClass;
191191

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

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

218-
return 0 === strpos($method, 'testLegacy')
219-
|| 0 === strpos($method, 'provideLegacy')
220-
|| 0 === strpos($method, 'getLegacy')
218+
return str_starts_with($method, 'testLegacy')
219+
|| str_starts_with($method, 'provideLegacy')
220+
|| str_starts_with($method, 'getLegacy')
221221
|| strpos($this->originClass, '\Legacy')
222222
|| \in_array('legacy', $groups($this->originClass, $method), true);
223223
}
@@ -228,10 +228,10 @@ public function isMuted(): bool
228228
return false;
229229
}
230230
if (isset($this->trace[1]['class'])) {
231-
return 0 === strpos($this->trace[1]['class'], 'PHPUnit\\');
231+
return str_starts_with($this->trace[1]['class'], 'PHPUnit\\');
232232
}
233233

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

237237
/**
@@ -300,7 +300,7 @@ private function getPackage(string $path): string
300300
{
301301
$path = realpath($path) ?: $path;
302302
foreach (self::getVendors() as $vendorRoot) {
303-
if (0 === strpos($path, $vendorRoot)) {
303+
if (str_starts_with($path, $vendorRoot)) {
304304
$relativePath = substr($path, \strlen($vendorRoot) + 1);
305305
$vendor = strstr($relativePath, \DIRECTORY_SEPARATOR, true);
306306
if (false === $vendor) {
@@ -326,7 +326,7 @@ private static function getVendors(): array
326326
self::$vendors[] = \dirname((new \ReflectionClass(DebugClassLoader::class))->getFileName());
327327
}
328328
foreach (get_declared_classes() as $class) {
329-
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
329+
if ('C' === $class[0] && str_starts_with($class, 'ComposerAutoloaderInit')) {
330330
$r = new \ReflectionClass($class);
331331
$v = \dirname($r->getFileName(), 2);
332332
if (file_exists($v.'/composer/installed.json')) {
@@ -341,7 +341,7 @@ private static function getVendors(): array
341341
}
342342
foreach ($paths as $path) {
343343
foreach (self::$vendors as $vendor) {
344-
if (0 !== strpos($path, $vendor)) {
344+
if (!str_starts_with($path, $vendor)) {
345345
self::$internalPaths[] = $path;
346346
}
347347
}
@@ -371,13 +371,13 @@ private function getPathType(string $path): string
371371
return self::PATH_TYPE_UNDETERMINED;
372372
}
373373
foreach (self::getVendors() as $vendor) {
374-
if (0 === strpos($realPath, $vendor) && false !== strpbrk(substr($realPath, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) {
374+
if (str_starts_with($realPath, $vendor) && false !== strpbrk(substr($realPath, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) {
375375
return self::PATH_TYPE_VENDOR;
376376
}
377377
}
378378

379379
foreach (self::$internalPaths as $internalPath) {
380-
if (0 === strpos($realPath, $internalPath)) {
380+
if (str_starts_with($realPath, $internalPath)) {
381381
return self::PATH_TYPE_SELF;
382382
}
383383
}

src/Symfony/Bridge/PhpUnit/DnsMock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public static function register($class): void
170170
if (0 < strpos($class, '\\Tests\\')) {
171171
$ns = str_replace('\\Tests\\', '\\', $class);
172172
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
173-
} elseif (0 === strpos($class, 'Tests\\')) {
173+
} elseif (str_starts_with($class, 'Tests\\')) {
174174
$mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6);
175175
}
176176
foreach ($mockedNs as $ns) {

src/Symfony/Bridge/PhpUnit/Legacy/CommandForV7.php renamed to src/Symfony/Bridge/PhpUnit/Legacy/CommandForV8.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* @internal
2121
*/
22-
class CommandForV7 extends BaseCommand
22+
class CommandForV8 extends BaseCommand
2323
{
2424
protected function createRunner(): BaseRunner
2525
{

src/Symfony/Bridge/PhpUnit/Legacy/ConstraintTraitForV7.php

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)
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