Skip to content

Commit 723d3a0

Browse files
committed
Added regression test
1 parent b18395e commit 723d3a0

9 files changed

+293
-6
lines changed

tests/PHPStan/Rules/TooWideTypehints/TooWideClosureReturnTypehintRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ protected function getRule(): Rule
1616
return new TooWideClosureReturnTypehintRule();
1717
}
1818

19+
public function testBug10312e(): void
20+
{
21+
$this->analyse([__DIR__ . '/data/bug-10312e.php'], []);
22+
}
23+
1924
public function testRule(): void
2025
{
2126
$this->analyse([__DIR__ . '/data/tooWideClosureReturnType.php'], [

tests/PHPStan/Rules/TooWideTypehints/TooWideFunctionReturnTypehintRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,9 @@ public function testBug11980(): void
6161
]);
6262
}
6363

64+
public function testBug10312a(): void
65+
{
66+
$this->analyse([__DIR__ . '/data/bug-10312a.php'], []);
67+
}
68+
6469
}

tests/PHPStan/Rules/TooWideTypehints/TooWideMethodReturnTypehintRuleTest.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,7 @@ public function testPublicProtectedWithInheritance(): void
8888

8989
public function testBug5095(): void
9090
{
91-
$this->analyse([__DIR__ . '/data/bug-5095.php'], [
92-
[
93-
'Method Bug5095\Parser::unaryOperatorFor() never returns \'not\' so it can be removed from the return type.',
94-
21,
95-
],
96-
]);
91+
$this->analyse([__DIR__ . '/data/bug-5095.php'], []);
9792
}
9893

9994
#[RequiresPhp('>= 8.0')]
@@ -199,4 +194,28 @@ public function testBug11980(): void
199194
]);
200195
}
201196

197+
public function testBug10312(): void
198+
{
199+
$this->checkProtectedAndPublicMethods = true;
200+
$this->analyse([__DIR__ . '/data/bug-10312.php'], []);
201+
}
202+
203+
public function testBug10312b(): void
204+
{
205+
$this->checkProtectedAndPublicMethods = true;
206+
$this->analyse([__DIR__ . '/data/bug-10312b.php'], []);
207+
}
208+
209+
public function testBug10312c(): void
210+
{
211+
$this->checkProtectedAndPublicMethods = true;
212+
$this->analyse([__DIR__ . '/data/bug-10312c.php'], []);
213+
}
214+
215+
public function testBug10312d(): void
216+
{
217+
$this->checkProtectedAndPublicMethods = true;
218+
$this->analyse([__DIR__ . '/data/bug-10312d.php'], []);
219+
}
220+
202221
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Bug10312;
4+
5+
class Cmsissue
6+
{
7+
public const LANE_BACKLOG = 'Backlog';
8+
9+
public const LANE_READY_FOR_IMPL = 'Bereit zur Entwicklung';
10+
11+
public const LANE_IN_IMPL = 'In Entwicklung';
12+
13+
public const LANE_READY_FOR_UAT = 'Bereit zur Abnahme';
14+
15+
public const LANE_READY_FOR_UAT_KANBAN = 'Test';
16+
17+
public const LANE_PROJECT_BACKLOG = 'Backlog';
18+
19+
public const LANE_PROJECT_IN_IMPL = 'Projekt in Umsetzung';
20+
21+
public const LANE_SKIP = '';
22+
}
23+
24+
25+
final class Mapper
26+
{
27+
28+
/**
29+
* @return Cmsissue::LANE_*
30+
*/
31+
public function mapIssueStatus(): string
32+
{
33+
if (rand(0,1) === 0) {
34+
return Cmsissue::LANE_BACKLOG;
35+
}
36+
if (rand(0,1) === 0) {
37+
return Cmsissue::LANE_READY_FOR_IMPL;
38+
}
39+
if (rand(0,1) === 0) {
40+
return Cmsissue::LANE_IN_IMPL;
41+
}
42+
if (rand(0,1) === 0) {
43+
return Cmsissue::LANE_READY_FOR_UAT;
44+
}
45+
46+
return Cmsissue::LANE_SKIP;
47+
}
48+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Bug10312a;
4+
5+
class Cmsissue
6+
{
7+
public const LANE_BACKLOG = 'Backlog';
8+
9+
public const LANE_READY_FOR_IMPL = 'Bereit zur Entwicklung';
10+
11+
public const LANE_IN_IMPL = 'In Entwicklung';
12+
13+
public const LANE_READY_FOR_UAT = 'Bereit zur Abnahme';
14+
15+
public const LANE_READY_FOR_UAT_KANBAN = 'Test';
16+
17+
public const LANE_PROJECT_BACKLOG = 'Backlog';
18+
19+
public const LANE_PROJECT_IN_IMPL = 'Projekt in Umsetzung';
20+
21+
public const LANE_SKIP = '';
22+
}
23+
24+
25+
/**
26+
* @return Cmsissue::LANE_*
27+
*/
28+
function mapIssueStatus(): string
29+
{
30+
if (rand(0,1) === 0) {
31+
return Cmsissue::LANE_BACKLOG;
32+
}
33+
if (rand(0,1) === 0) {
34+
return Cmsissue::LANE_READY_FOR_IMPL;
35+
}
36+
if (rand(0,1) === 0) {
37+
return Cmsissue::LANE_IN_IMPL;
38+
}
39+
if (rand(0,1) === 0) {
40+
return Cmsissue::LANE_READY_FOR_UAT;
41+
}
42+
43+
return Cmsissue::LANE_SKIP;
44+
}
45+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Bug10312b;
4+
5+
interface MinPhpVersionInterface
6+
{
7+
/**
8+
* @return PhpVersion::*
9+
*/
10+
public function provideMinPhpVersion() : int;
11+
}
12+
13+
final class PhpVersion
14+
{
15+
/**
16+
* @var int
17+
*/
18+
public const PHP_52 = 50200;
19+
/**
20+
* @var int
21+
*/
22+
public const PHP_53 = 50300;
23+
/**
24+
* @var int
25+
*/
26+
public const PHP_54 = 50400;
27+
/**
28+
* @var int
29+
*/
30+
public const PHP_55 = 50500;
31+
}
32+
33+
final class TypedPropertyFromStrictConstructorReadonlyClassRector implements MinPhpVersionInterface
34+
{
35+
public function provideMinPhpVersion(): int
36+
{
37+
return PhpVersion::PHP_55;
38+
}
39+
40+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug10312c;
4+
5+
enum Foo: int
6+
{
7+
case BAR = 1;
8+
case BAZ = 2;
9+
}
10+
11+
interface ReturnsFoo
12+
{
13+
/** @return value-of<Foo> */
14+
public function returnsFooValue(): int;
15+
}
16+
17+
class ReturnsBar implements ReturnsFoo
18+
{
19+
#[\Override]
20+
public function returnsFooValue(): int
21+
{
22+
return Foo::BAR->value;
23+
}
24+
}
25+
26+
class ReturnsBarWithFinalMethod implements ReturnsFoo
27+
{
28+
#[\Override]
29+
final public function returnsFooValue(): int
30+
{
31+
return Foo::BAR->value;
32+
}
33+
}
34+
35+
final class ReturnsBaz implements ReturnsFoo
36+
{
37+
#[\Override]
38+
public function returnsFooValue(): int
39+
{
40+
return Foo::BAZ->value;
41+
}
42+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug10312d;
4+
5+
enum Foo: int
6+
{
7+
case BAR = 1;
8+
case BAZ = 2;
9+
}
10+
11+
class FooBar {
12+
public ?Foo $foo = null;
13+
}
14+
15+
interface ReturnsFoo
16+
{
17+
/** @return value-of<Foo> */
18+
public function returnsFooValue(): int;
19+
20+
/** @return value-of<Foo>|null */
21+
public function returnsFooOrNullValue(): ?int;
22+
}
23+
24+
final class ReturnsNullsafeBaz implements ReturnsFoo
25+
{
26+
#[\Override]
27+
public function returnsFooValue(): int
28+
{
29+
$f = new FooBar();
30+
return $f->foo?->value;
31+
}
32+
33+
#[\Override]
34+
public function returnsFooOrNullValue(): ?int
35+
{
36+
$f = new FooBar();
37+
return $f->foo?->value;
38+
}
39+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Bug10312a;
4+
5+
class Cmsissue
6+
{
7+
public const LANE_BACKLOG = 'Backlog';
8+
9+
public const LANE_READY_FOR_IMPL = 'Bereit zur Entwicklung';
10+
11+
public const LANE_IN_IMPL = 'In Entwicklung';
12+
13+
public const LANE_READY_FOR_UAT = 'Bereit zur Abnahme';
14+
15+
public const LANE_READY_FOR_UAT_KANBAN = 'Test';
16+
17+
public const LANE_PROJECT_BACKLOG = 'Backlog';
18+
19+
public const LANE_PROJECT_IN_IMPL = 'Projekt in Umsetzung';
20+
21+
public const LANE_SKIP = '';
22+
}
23+
24+
25+
/**
26+
* @return Cmsissue::LANE_*
27+
*/
28+
$x = function(): string
29+
{
30+
if (rand(0,1) === 0) {
31+
return Cmsissue::LANE_BACKLOG;
32+
}
33+
if (rand(0,1) === 0) {
34+
return Cmsissue::LANE_READY_FOR_IMPL;
35+
}
36+
if (rand(0,1) === 0) {
37+
return Cmsissue::LANE_IN_IMPL;
38+
}
39+
if (rand(0,1) === 0) {
40+
return Cmsissue::LANE_READY_FOR_UAT;
41+
}
42+
43+
return Cmsissue::LANE_SKIP;
44+
};

0 commit comments

Comments
 (0)