Skip to content

Commit 4387633

Browse files
committed
cleanup tests
1 parent 8600761 commit 4387633

File tree

4 files changed

+98
-65
lines changed

4 files changed

+98
-65
lines changed

tests/PHPStan/Php/PhpVersionsTest.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,29 @@
33
namespace PHPStan\Php;
44

55
use PHPStan\TrinaryLogic;
6+
use PHPStan\Type\Constant\ConstantIntegerType;
67
use PHPStan\Type\IntegerRangeType;
78
use PHPStan\Type\Type;
8-
use PHPStan\Type\Constant\ConstantIntegerType;
99
use PHPStan\Type\UnionType;
1010
use PHPUnit\Framework\TestCase;
1111

1212
class PhpVersionsTest extends TestCase
1313
{
14+
1415
/**
1516
* @dataProvider dataProducesWarningForFinalPrivateMethods
1617
*/
17-
public function testProducesWarningForFinalPrivateMethods(TrinaryLogic $expected, Type $versionType ) {
18+
public function testProducesWarningForFinalPrivateMethods(TrinaryLogic $expected, Type $versionType): void
19+
{
1820
$phpVersions = new PhpVersions($versionType);
1921
$this->assertSame(
2022
$expected->describe(),
21-
$phpVersions->producesWarningForFinalPrivateMethods()->describe()
23+
$phpVersions->producesWarningForFinalPrivateMethods()->describe(),
2224
);
2325
}
2426

25-
public function dataProducesWarningForFinalPrivateMethods(): iterable {
27+
public function dataProducesWarningForFinalPrivateMethods(): iterable
28+
{
2629
yield [
2730
TrinaryLogic::createNo(),
2831
new ConstantIntegerType(70400),
@@ -40,25 +43,26 @@ public function dataProducesWarningForFinalPrivateMethods(): iterable {
4043

4144
yield [
4245
TrinaryLogic::createYes(),
43-
IntegerRangeType::fromInterval(80000, null)
46+
IntegerRangeType::fromInterval(80000, null),
4447
];
4548

4649
yield [
4750
TrinaryLogic::createMaybe(),
48-
IntegerRangeType::fromInterval(null, 80000)
51+
IntegerRangeType::fromInterval(null, 80000),
4952
];
5053

5154
yield [
5255
TrinaryLogic::createNo(),
53-
IntegerRangeType::fromInterval(70200, 70400)
56+
IntegerRangeType::fromInterval(70200, 70400),
5457
];
5558

5659
yield [
5760
TrinaryLogic::createMaybe(),
5861
new UnionType([
5962
IntegerRangeType::fromInterval(70200, 70400),
6063
IntegerRangeType::fromInterval(80200, 80400),
61-
])
64+
]),
6265
];
6366
}
67+
6468
}

tests/PHPStan/Rules/Methods/FinalPrivateMethodRuleTest.php

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace PHPStan\Rules\Methods;
44

5+
use PHPStan\Php\PhpVersion;
56
use PHPStan\Rules\Rule;
67
use PHPStan\Testing\RuleTestCase;
7-
use function array_merge;
88
use const PHP_VERSION_ID;
99

1010
/** @extends RuleTestCase<FinalPrivateMethodRule> */
@@ -16,34 +16,60 @@ protected function getRule(): Rule
1616
return new FinalPrivateMethodRule();
1717
}
1818

19-
public function testRule(): void
19+
public function dataRule(): array
2020
{
21-
$errors = [];
22-
if (PHP_VERSION_ID >= 80000) {
23-
$errors = [
21+
return [
22+
[
23+
70400,
24+
[],
25+
],
26+
[
27+
80000,
2428
[
25-
'Private method FinalPrivateMethod\Foo::foo() cannot be final as it is never overridden by other classes.',
26-
8,
29+
[
30+
'Private method FinalPrivateMethod\Foo::foo() cannot be final as it is never overridden by other classes.',
31+
8,
32+
],
2733
],
28-
];
34+
],
35+
];
36+
}
37+
38+
/**
39+
* @dataProvider dataRule
40+
* @param list<array{0: string, 1: int, 2?: string}> $errors
41+
*/
42+
public function testRule(int $phpVersion, array $errors): void
43+
{
44+
$testVersion = new PhpVersion($phpVersion);
45+
$runtimeVersion = new PhpVersion(PHP_VERSION_ID);
46+
47+
if (
48+
$testVersion->getMajorVersionId() !== $runtimeVersion->getMajorVersionId()
49+
|| $testVersion->getMinorVersionId() !== $runtimeVersion->getMinorVersionId()
50+
) {
51+
$this->markTestSkipped('Test requires PHP version ' . $phpVersion);
2952
}
3053

31-
$errors = array_merge($errors, [
54+
$this->analyse([__DIR__ . '/data/final-private-method.php'], $errors);
55+
}
56+
57+
public function testRulePhpVersions(): void
58+
{
59+
$this->analyse([__DIR__ . '/data/final-private-method-phpversions.php'], [
3260
[
33-
'Private method FinalPrivateMethod\FooBarPhp8orHigher::foo() cannot be final as it is never overridden by other classes.',
34-
39,
61+
'Private method FinalPrivateMethodPhpVersions\FooBarPhp8orHigher::foo() cannot be final as it is never overridden by other classes.',
62+
9,
3563
],
3664
[
37-
'Private method FinalPrivateMethod\FooBarPhp74OrHigher::foo() cannot be final as it is never overridden by other classes.',
38-
59,
65+
'Private method FinalPrivateMethodPhpVersions\FooBarPhp74OrHigher::foo() cannot be final as it is never overridden by other classes.',
66+
29,
3967
],
4068
[
41-
'Private method FinalPrivateMethod\FooBarBaz::foo() cannot be final as it is never overridden by other classes.',
42-
69,
69+
'Private method FinalPrivateMethodPhpVersions\FooBarBaz::foo() cannot be final as it is never overridden by other classes.',
70+
39,
4371
],
4472
]);
45-
46-
$this->analyse([__DIR__ . '/data/final-private-method.php'], $errors);
4773
}
4874

4975
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace FinalPrivateMethodPhpVersions;
4+
5+
if (PHP_VERSION_ID >= 80000) {
6+
class FooBarPhp8orHigher
7+
{
8+
9+
final private function foo(): void
10+
{
11+
}
12+
}
13+
}
14+
15+
if (PHP_VERSION_ID < 80000) {
16+
class FooBarPhp7
17+
{
18+
19+
final private function foo(): void
20+
{
21+
}
22+
}
23+
}
24+
25+
if (PHP_VERSION_ID > 70400) {
26+
class FooBarPhp74OrHigher
27+
{
28+
29+
final private function foo(): void
30+
{
31+
}
32+
}
33+
}
34+
35+
if (PHP_VERSION_ID < 70400 || PHP_VERSION_ID >= 80100) {
36+
class FooBarBaz
37+
{
38+
39+
final private function foo(): void
40+
{
41+
}
42+
}
43+
}

tests/PHPStan/Rules/Methods/data/final-private-method.php

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,43 +31,3 @@ final private function __construct()
3131
}
3232

3333
}
34-
35-
if (PHP_VERSION_ID >= 80000) {
36-
class FooBarPhp8orHigher
37-
{
38-
39-
final private function foo(): void
40-
{
41-
}
42-
}
43-
}
44-
45-
if (PHP_VERSION_ID < 80000) {
46-
class FooBarPhp7
47-
{
48-
49-
final private function foo(): void
50-
{
51-
}
52-
}
53-
}
54-
55-
if (PHP_VERSION_ID > 70400) {
56-
class FooBarPhp74OrHigher
57-
{
58-
59-
final private function foo(): void
60-
{
61-
}
62-
}
63-
}
64-
65-
if (PHP_VERSION_ID < 70400 || PHP_VERSION_ID >= 80100) {
66-
class FooBarBaz
67-
{
68-
69-
final private function foo(): void
70-
{
71-
}
72-
}
73-
}

0 commit comments

Comments
 (0)