Skip to content

Commit eb2f23a

Browse files
Add tests
1 parent e947287 commit eb2f23a

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,4 +987,16 @@ public function testBug13151(): void
987987
$this->analyse([__DIR__ . '/data/bug-13151.php'], []);
988988
}
989989

990+
public function testBug8818(): void
991+
{
992+
$this->treatPhpDocTypesAsCertain = true;
993+
$this->analyse([__DIR__ . '/data/bug-8818.php'], []);
994+
}
995+
996+
public function testBug12755(): void
997+
{
998+
$this->treatPhpDocTypesAsCertain = true;
999+
$this->analyse([__DIR__ . '/data/bug-12755.php'], []);
1000+
}
1001+
9901002
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug12755;
4+
5+
class HelloWorld
6+
{
7+
/**
8+
* @param array{
9+
* key1: ?int,
10+
* key2: ?string,
11+
* } $myArray
12+
*/
13+
public function testOther(array $myArray): ?\stdClass
14+
{
15+
if (\in_array(null, $myArray, true)) {
16+
return null;
17+
}
18+
19+
return (object) $myArray;
20+
}
21+
22+
/**
23+
* @param array{
24+
* key1: ?bool,
25+
* } $myArray
26+
*/
27+
public function testBool(array $myArray): ?\stdClass
28+
{
29+
if (\in_array(null, $myArray, true)) {
30+
return null;
31+
}
32+
33+
return (object) $myArray;
34+
}
35+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug8818;
4+
5+
class MyEnum {
6+
public const ONE = 'one';
7+
public const TWO = 'two';
8+
public const THREE = 'three';
9+
}
10+
11+
class HelloWorld
12+
{
13+
/**
14+
* @param list<MyEnum::*> $stack
15+
*/
16+
public function sayHello(array $stack): bool
17+
{
18+
return count($stack) === 1 && in_array(MyEnum::ONE, $stack, true);
19+
}
20+
}

0 commit comments

Comments
 (0)