Skip to content

Commit 6d5c6fe

Browse files
committed
Fix
1 parent ac0cfd0 commit 6d5c6fe

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,17 @@ public function testCollectWarnings(): void
174174
restore_error_handler();
175175
$errors = $this->runAnalyse(__DIR__ . '/data/declaration-warning.php');
176176
if (self::$useStaticReflectionProvider) {
177-
$this->assertCount(0, $errors);
177+
$this->assertCount(1, $errors);
178+
$this->assertSame('Parameter #1 $i of method DeclarationWarning\Bar::doFoo() is not optional.', $errors[0]->getMessage());
179+
$this->assertSame(22, $errors[0]->getLine());
178180
return;
179181
}
180-
$this->assertCount(1, $errors);
182+
$this->assertCount(2, $errors);
181183
$this->assertSame('Declaration of DeclarationWarning\Bar::doFoo(int $i): void should be compatible with DeclarationWarning\Foo::doFoo(): void', $errors[0]->getMessage());
182184
$this->assertSame(__DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'declaration-warning.php', $errors[0]->getFile());
183185
$this->assertSame(PHP_VERSION_ID >= 70400 ? 22 : 27, $errors[0]->getLine());
186+
$this->assertSame('Parameter #1 $i of method DeclarationWarning\Bar::doFoo() is not optional.', $errors[1]->getMessage());
187+
$this->assertSame(22, $errors[1]->getLine());
184188
}
185189

186190
public function testPropertyAssignIntersectionStaticTypeBug(): void

tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PHPStan\Php\PhpVersion;
66
use PHPStan\Rules\Rule;
77
use PHPStan\Testing\RuleTestCase;
8-
use const PHP_VERSION_ID;
98

109
/**
1110
* @extends RuleTestCase<OverridingMethodRule>
@@ -21,13 +20,32 @@ protected function getRule(): Rule
2120
return new OverridingMethodRule(new PhpVersion($this->phpVersionId));
2221
}
2322

24-
public function testOverridingFinalMethod(): void
23+
public function dataOverridingFinalMethod(): array
24+
{
25+
return [
26+
[
27+
70300,
28+
'compatible',
29+
],
30+
[
31+
70400,
32+
'contravariant',
33+
],
34+
];
35+
}
36+
37+
/**
38+
* @dataProvider dataOverridingFinalMethod
39+
* @param int $phpVersion
40+
* @param string $message
41+
*/
42+
public function testOverridingFinalMethod(int $phpVersion, string $message): void
2543
{
2644
if (!self::$useStaticReflectionProvider) {
2745
$this->markTestSkipped('Test requires static reflection.');
2846
}
2947

30-
$this->phpVersionId = PHP_VERSION_ID;
48+
$this->phpVersionId = $phpVersion;
3149
$this->analyse([__DIR__ . '/data/overriding-method.php'], [
3250
[
3351
'Method OverridingFinalMethod\Bar::doFoo() overrides final method OverridingFinalMethod\Foo::doFoo().',
@@ -54,15 +72,15 @@ public function testOverridingFinalMethod(): void
5472
68,
5573
],
5674
[
57-
'Parameter #1 $s (string) of method OverridingFinalMethod\Dolor::__construct() is not contravariant with parameter #1 $i (int) of method OverridingFinalMethod\Ipsum::__construct().',
75+
'Parameter #1 $s (string) of method OverridingFinalMethod\Dolor::__construct() is not ' . $message . ' with parameter #1 $i (int) of method OverridingFinalMethod\Ipsum::__construct().',
5876
110,
5977
],
6078
[
6179
'Method OverridingFinalMethod\Dolor::doFoo() overrides method OverridingFinalMethod\Ipsum::doFoo() but misses parameter #1 $i.',
6280
115,
6381
],
6482
[
65-
'Parameter #1 $size (string) of method OverridingFinalMethod\FixedArray::setSize() is not contravariant with parameter #1 $size (int) of method SplFixedArray::setSize().',
83+
'Parameter #1 $size (string) of method OverridingFinalMethod\FixedArray::setSize() is not ' . $message . ' with parameter #1 $size (int) of method SplFixedArray::setSize().',
6684
125,
6785
],
6886
[

0 commit comments

Comments
 (0)