Skip to content

Commit 6851343

Browse files
committed
Auto-apply fixes about #[RequiresPhp]
1 parent 0f86911 commit 6851343

File tree

173 files changed

+694
-2200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+694
-2200
lines changed

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 44 additions & 171 deletions
Large diffs are not rendered by default.

tests/PHPStan/Analyser/AnalyserTraitsIntegrationTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
use Override;
66
use PHPStan\File\FileHelper;
77
use PHPStan\Testing\PHPStanTestCase;
8+
use PHPUnit\Framework\Attributes\RequiresPhp;
89
use function array_map;
910
use function array_merge;
1011
use function array_unique;
1112
use function sprintf;
1213
use function usort;
13-
use const PHP_VERSION_ID;
1414

1515
class AnalyserTraitsIntegrationTest extends PHPStanTestCase
1616
{
@@ -171,12 +171,9 @@ public function testMissingReturnInAbstractTraitMethod(): void
171171
$this->assertNoErrors($errors);
172172
}
173173

174+
#[RequiresPhp('>= 8.1')]
174175
public function testUnititializedReadonlyPropertyAccessedInTrait(): void
175176
{
176-
if (PHP_VERSION_ID < 80100) {
177-
$this->markTestSkipped();
178-
}
179-
180177
$errors = $this->runAnalyse([
181178
__DIR__ . '/traits/uninitializedProperty/FooClass.php',
182179
__DIR__ . '/traits/uninitializedProperty/FooTrait.php',

tests/PHPStan/Analyser/ArgumentsNormalizerLegacyTest.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,17 @@
1313
use PHPStan\ShouldNotHappenException;
1414
use PHPStan\Testing\PHPStanTestCase;
1515
use PHPStan\Type\Constant\ConstantIntegerType;
16-
use const PHP_VERSION_ID;
16+
use PHPUnit\Framework\Attributes\RequiresPhp;
1717

1818
final class ArgumentsNormalizerLegacyTest extends PHPStanTestCase
1919
{
2020

2121
/**
2222
* function call, all arguments named and given in order
2323
*/
24+
#[RequiresPhp('>= 8.0')]
2425
public function testArgumentReorderAllNamed(): void
2526
{
26-
if (PHP_VERSION_ID < 80000) {
27-
$this->markTestSkipped('Test requires PHP 8.0.');
28-
}
29-
3027
$funcName = new Name('json_encode');
3128
$reflectionProvider = self::getContainer()->getByType(NativeFunctionReflectionProvider::class);
3229
$functionReflection = $reflectionProvider->findFunctionReflection('json_encode');
@@ -65,12 +62,9 @@ public function testArgumentReorderAllNamed(): void
6562
/**
6663
* function call, all args named, not in order
6764
*/
65+
#[RequiresPhp('>= 8.0')]
6866
public function testArgumentReorderAllNamedWithSkipped(): void
6967
{
70-
if (PHP_VERSION_ID < 80000) {
71-
$this->markTestSkipped('Test requires PHP 8.0.');
72-
}
73-
7468
$funcName = new Name('json_encode');
7569
$reflectionProvider = self::getContainer()->getByType(NativeFunctionReflectionProvider::class);
7670
$functionReflection = $reflectionProvider->findFunctionReflection('json_encode');
@@ -112,12 +106,9 @@ public function testArgumentReorderAllNamedWithSkipped(): void
112106
$this->assertSame(128, $reorderedArgs[2]->value->value);
113107
}
114108

109+
#[RequiresPhp('>= 8.0')]
115110
public function testMissingRequiredParameter(): void
116111
{
117-
if (PHP_VERSION_ID < 80000) {
118-
$this->markTestSkipped('Test requires PHP 8.0.');
119-
}
120-
121112
$funcName = new Name('json_encode');
122113
$reflectionProvider = self::getContainer()->getByType(NativeFunctionReflectionProvider::class);
123114
$functionReflection = $reflectionProvider->findFunctionReflection('json_encode');

tests/PHPStan/Analyser/InstanceMethodsParameterScopeFunctionTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use PHPStan\Rules\Rule;
66
use PHPStan\Testing\RuleTestCase;
7-
use const PHP_VERSION_ID;
7+
use PHPUnit\Framework\Attributes\RequiresPhp;
88

99
/**
1010
* @extends RuleTestCase<InstanceMethodsParameterScopeFunctionRule>
@@ -22,12 +22,9 @@ protected function shouldNarrowMethodScopeFromConstructor(): bool
2222
return true;
2323
}
2424

25+
#[RequiresPhp('>= 8.0')]
2526
public function testRule(): void
2627
{
27-
if (PHP_VERSION_ID < 80000) {
28-
$this->markTestSkipped('Test requires PHP 8.0.');
29-
}
30-
3128
$this->analyse([__DIR__ . '/data/instance-methods-parameter-scope.php'], [
3229
[
3330
'Name DateTime found in function scope null',

tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PHPStan\Type\Constant\ConstantStringType;
1717
use PHPStan\Type\Type;
1818
use PHPStan\Type\VerbosityLevel;
19+
use PHPUnit\Framework\Attributes\RequiresPhp;
1920
use SomeNodeScopeResolverNamespace\Foo;
2021
use function define;
2122
use function defined;
@@ -8542,15 +8543,12 @@ public static function dataDynamicConstantsWithNativeTypes(): array
85428543
/**
85438544
* @dataProvider dataDynamicConstantsWithNativeTypes
85448545
*/
8546+
#[RequiresPhp('>= 8.3')]
85458547
public function testDynamicConstantsWithNativeTypes(
85468548
string $description,
85478549
string $expression,
85488550
): void
85498551
{
8550-
if (PHP_VERSION_ID < 80300) {
8551-
$this->markTestSkipped('Test requires PHP 8.3.');
8552-
}
8553-
85548552
$this->assertTypes(
85558553
__DIR__ . '/data/dynamic-constant-native-types.php',
85568554
$description,

tests/PHPStan/Build/NamedArgumentsRuleTest.php

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPStan\Php\PhpVersion;
66
use PHPStan\Rules\Rule;
77
use PHPStan\Testing\RuleTestCase;
8+
use PHPUnit\Framework\Attributes\RequiresPhp;
89
use const PHP_VERSION_ID;
910

1011
/**
@@ -18,12 +19,9 @@ protected function getRule(): Rule
1819
return new NamedArgumentsRule(self::createReflectionProvider(), new PhpVersion(PHP_VERSION_ID));
1920
}
2021

22+
#[RequiresPhp('>= 8.0')]
2123
public function testRule(): void
2224
{
23-
if (PHP_VERSION_ID < 80000) {
24-
$this->markTestSkipped('Test requires PHP 8.0.');
25-
}
26-
2725
$this->analyse([__DIR__ . '/data/named-arguments.php'], [
2826
[
2927
'You\'re passing a non-default value Exception to parameter $previous but previous argument is passing default value to its parameter ($code). You can skip it and use named argument for $previous instead.',
@@ -48,48 +46,36 @@ public function testRule(): void
4846
]);
4947
}
5048

49+
#[RequiresPhp('>= 8.0')]
5150
public function testNoFix(): void
5251
{
53-
if (PHP_VERSION_ID < 80000) {
54-
$this->markTestSkipped('Test requires PHP 8.0.');
55-
}
56-
5752
$this->fix(
5853
__DIR__ . '/data/named-arguments-no-errors.php',
5954
__DIR__ . '/data/named-arguments-no-errors.php',
6055
);
6156
}
6257

58+
#[RequiresPhp('>= 8.0')]
6359
public function testFix(): void
6460
{
65-
if (PHP_VERSION_ID < 80000) {
66-
$this->markTestSkipped('Test requires PHP 8.0.');
67-
}
68-
6961
$this->fix(
7062
__DIR__ . '/data/named-arguments.php',
7163
__DIR__ . '/data/named-arguments.php.fixed',
7264
);
7365
}
7466

67+
#[RequiresPhp('>= 8.0')]
7568
public function testFixFileWithMatch(): void
7669
{
77-
if (PHP_VERSION_ID < 80000) {
78-
$this->markTestSkipped('Test requires PHP 8.0.');
79-
}
80-
8170
$this->fix(
8271
__DIR__ . '/data/named-arguments-match.php',
8372
__DIR__ . '/data/named-arguments-match.php.fixed',
8473
);
8574
}
8675

76+
#[RequiresPhp('>= 8.1')]
8777
public function testNewInInitializer(): void
8878
{
89-
if (PHP_VERSION_ID < 80100) {
90-
$this->markTestSkipped('Test requires PHP 8.1.');
91-
}
92-
9379
$this->analyse([__DIR__ . '/data/named-arguments-new.php'], [
9480
[
9581
'You\'re passing a non-default value \'bar\' to parameter $d but previous argument is passing default value to its parameter ($c). You can skip it and use named argument for $d instead.',
@@ -98,12 +84,9 @@ public function testNewInInitializer(): void
9884
]);
9985
}
10086

87+
#[RequiresPhp('>= 8.1')]
10188
public function testFixNewInInitializer(): void
10289
{
103-
if (PHP_VERSION_ID < 80100) {
104-
$this->markTestSkipped('Test requires PHP 8.1.');
105-
}
106-
10790
$this->fix(__DIR__ . '/data/named-arguments-new.php', __DIR__ . '/data/named-arguments-new.php.fixed');
10891
}
10992

tests/PHPStan/Node/AttributeArgRuleTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PhpParser\Node;
66
use PHPStan\Rules\Rule;
77
use PHPStan\Testing\RuleTestCase;
8-
use const PHP_VERSION_ID;
8+
use PHPUnit\Framework\Attributes\RequiresPhp;
99

1010
/**
1111
* @extends RuleTestCase<Rule>
@@ -43,12 +43,9 @@ public function testRule(string $file, string $expectedError, array $lines): voi
4343
$this->analyse([$file], $errors);
4444
}
4545

46+
#[RequiresPhp('>= 8.1')]
4647
public function testEnumCaseAttribute(): void
4748
{
48-
if (PHP_VERSION_ID < 80100) {
49-
$this->markTestSkipped('Test requires PHP 8.1.');
50-
}
51-
5249
$this->analyse([__DIR__ . '/data/enum-case-attribute.php'], [
5350
[
5451
AttributeArgRule::ERROR_MESSAGE,

tests/PHPStan/Reflection/Annotations/DeprecatedAnnotationsTest.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PHPStan\Analyser\Scope;
1717
use PHPStan\Testing\PHPStanTestCase;
1818
use PHPStan\TrinaryLogic;
19+
use PHPUnit\Framework\Attributes\RequiresPhp;
1920
use const PHP_VERSION_ID;
2021

2122
class DeprecatedAnnotationsTest extends PHPStanTestCase
@@ -331,12 +332,9 @@ public static function dataDeprecatedAttributeAboveEnumCase(): iterable
331332
/**
332333
* @dataProvider dataDeprecatedAttributeAboveEnumCase
333334
*/
335+
#[RequiresPhp('>= 8.1')]
334336
public function testDeprecatedAttributeAboveEnumCase(string $className, string $caseName, TrinaryLogic $isDeprecated, ?string $deprecatedDescription): void
335337
{
336-
if (PHP_VERSION_ID < 80100) {
337-
$this->markTestSkipped('Test requires PHP 8.1.');
338-
}
339-
340338
$reflectionProvider = self::createReflectionProvider();
341339
$class = $reflectionProvider->getClass($className);
342340
$case = $class->getEnumCase($caseName);
@@ -387,12 +385,9 @@ public static function dataDeprecatedAttributeAbovePropertyHook(): iterable
387385
* @dataProvider dataDeprecatedAttributeAbovePropertyHook
388386
* @param 'get'|'set' $hookName
389387
*/
388+
#[RequiresPhp('>= 8.4')]
390389
public function testDeprecatedAttributeAbovePropertyHook(string $className, string $propertyName, string $hookName, TrinaryLogic $isDeprecated, ?string $deprecatedDescription): void
391390
{
392-
if (PHP_VERSION_ID < 80400) {
393-
$this->markTestSkipped('Test requires PHP 8.4.');
394-
}
395-
396391
$reflectionProvider = self::createReflectionProvider();
397392
$class = $reflectionProvider->getClass($className);
398393
$property = $class->getNativeProperty($propertyName);

tests/PHPStan/Reflection/Annotations/DeprecatedAttributePhpFunctionFromParserReflectionRuleTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
use PHPStan\Rules\Rule;
1111
use PHPStan\Rules\RuleErrorBuilder;
1212
use PHPStan\Testing\RuleTestCase;
13+
use PHPUnit\Framework\Attributes\RequiresPhp;
1314
use function sprintf;
14-
use const PHP_VERSION_ID;
1515

1616
/**
1717
* @extends RuleTestCase<Rule>
@@ -112,12 +112,9 @@ public function testMethodRule(): void
112112
]);
113113
}
114114

115+
#[RequiresPhp('>= 8.4')]
115116
public function testPropertyHookRule(): void
116117
{
117-
if (PHP_VERSION_ID < 80400) {
118-
$this->markTestSkipped('Test requires PHP 8.4.');
119-
}
120-
121118
$this->analyse([__DIR__ . '/data/deprecated-attribute-property-hooks.php'], [
122119
[
123120
'Not deprecated',

tests/PHPStan/Reflection/AttributeReflectionFromNodeRuleTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
use PHPStan\Rules\RuleErrorBuilder;
1212
use PHPStan\Testing\RuleTestCase;
1313
use PHPStan\Type\VerbosityLevel;
14+
use PHPUnit\Framework\Attributes\RequiresPhp;
1415
use function count;
1516
use function implode;
1617
use function sprintf;
17-
use const PHP_VERSION_ID;
1818

1919
/**
2020
* @extends RuleTestCase<Rule<NodeAbstract>>
@@ -80,12 +80,9 @@ public function processNode(Node $node, Scope $scope): array
8080
};
8181
}
8282

83+
#[RequiresPhp('>= 8.0')]
8384
public function testRule(): void
8485
{
85-
if (PHP_VERSION_ID < 80000) {
86-
self::markTestSkipped('Test requires PHP 8.0');
87-
}
88-
8986
$this->analyse([__DIR__ . '/data/attribute-reflection.php'], [
9087
[
9188
'#[AttributeReflectionTest\MyAttr(one: 7, two: 8)], $test: #[AttributeReflectionTest\MyAttr(one: 9, two: 10)]',

tests/PHPStan/Reflection/AttributeReflectionTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\Node\Name;
88
use PHPStan\Testing\PHPStanTestCase;
99
use PHPStan\Type\VerbosityLevel;
10+
use PHPUnit\Framework\Attributes\RequiresPhp;
1011
use function count;
1112
use const PHP_VERSION_ID;
1213

@@ -152,15 +153,12 @@ public static function dataAttributeReflections(): iterable
152153
* @param list<AttributeReflection> $attributeReflections
153154
* @param list<array{string, array<string, string>}> $expectations
154155
*/
156+
#[RequiresPhp('>= 8.0')]
155157
public function testAttributeReflections(
156158
array $attributeReflections,
157159
array $expectations,
158160
): void
159161
{
160-
if (PHP_VERSION_ID < 80000) {
161-
self::markTestSkipped('Test requires PHP 8.0');
162-
}
163-
164162
$this->assertCount(count($expectations), $attributeReflections);
165163
foreach ($expectations as $i => [$name, $argumentTypes]) {
166164
$attribute = $attributeReflections[$i];

tests/PHPStan/Reflection/ClassReflectionTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
use PHPStan\Testing\PHPStanTestCase;
3131
use PHPStan\Testing\RuleTestCase;
3232
use PHPStan\Type\IntegerType;
33+
use PHPUnit\Framework\Attributes\RequiresPhp;
3334
use PHPUnit\Framework\TestCase;
3435
use ReflectionClass;
3536
use WrongClassConstantFile\SecuredRouter;
3637
use function array_map;
3738
use function array_values;
38-
use const PHP_VERSION_ID;
3939

4040
class ClassReflectionTest extends PHPStanTestCase
4141
{
@@ -284,12 +284,9 @@ public static function dataNestedRecursiveTraits(): array
284284
];
285285
}
286286

287+
#[RequiresPhp('>= 8.1')]
287288
public function testEnumIsFinal(): void
288289
{
289-
if (PHP_VERSION_ID < 80100) {
290-
$this->markTestSkipped('Test requires PHP 8.1.');
291-
}
292-
293290
$reflectionProvider = self::createReflectionProvider();
294291
$enum = $reflectionProvider->getClass('PHPStan\Fixture\TestEnum');
295292
$this->assertTrue($enum->isEnum());
@@ -298,12 +295,9 @@ public function testEnumIsFinal(): void
298295
$this->assertTrue($enum->isFinalByKeyword());
299296
}
300297

298+
#[RequiresPhp('>= 8.1')]
301299
public function testBackedEnumType(): void
302300
{
303-
if (PHP_VERSION_ID < 80100) {
304-
$this->markTestSkipped('Test requires PHP 8.1.');
305-
}
306-
307301
$reflectionProvider = self::createReflectionProvider();
308302
$enum = $reflectionProvider->getClass('PHPStan\Fixture\TestEnum');
309303
$this->assertInstanceOf(IntegerType::class, $enum->getBackedEnumType());

0 commit comments

Comments
 (0)