Skip to content

Commit 2b3d282

Browse files
Add non regression tests
1 parent 2b595d4 commit 2b3d282

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

tests/PHPStan/Analyser/NodeScopeResolverTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,8 @@ public function dataFileAsserts(): iterable
851851
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5262.php');
852852
}
853853

854+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-2471.php');
855+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5846.php');
854856
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6927.php');
855857

856858
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-3853.php');
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Bug2471;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class A {
8+
public function __toString()
9+
{
10+
return 'foo';
11+
}
12+
}
13+
14+
abstract class Foo {
15+
/**
16+
* @return A[]
17+
*/
18+
abstract function doFoo(): array;
19+
20+
public function test(): void
21+
{
22+
$y = $this->doFoo();
23+
24+
$x = array_fill_keys($y, null);
25+
26+
assertType('array<string, null>', $x);
27+
}
28+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Bug5846;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Foo
8+
{
9+
public function test(): void
10+
{
11+
$arr = [
12+
'a' => 1,
13+
'b' => 'bee',
14+
];
15+
$data = array_merge($arr, $arr);
16+
$data2 = array_merge($arr);
17+
18+
assertType('array{a: 1, b: \'bee\'}', $arr);
19+
assertType('array{a: 1, b: \'bee\'}', $data);
20+
assertType('array{a: 1, b: \'bee\'}', $data2);
21+
}
22+
}

tests/PHPStan/Rules/Classes/ImpossibleInstanceOfRuleTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,11 @@ public function testBug3096(): void
339339
$this->analyse([__DIR__ . '/data/bug-3096.php'], []);
340340
}
341341

342+
public function testBug6213(): void
343+
{
344+
$this->checkAlwaysTrueInstanceOf = true;
345+
$this->treatPhpDocTypesAsCertain = true;
346+
$this->analyse([__DIR__ . '/data/bug-6213.php'], []);
347+
}
348+
342349
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Bug6213;
4+
5+
use DOMDocument;
6+
use DOMText;
7+
8+
class HelloWorld
9+
{
10+
public function sayHello(): void {
11+
$document = new DOMDocument('1.0', 'utf-8');
12+
$element = $document->createElement('div', 'content');
13+
14+
// Incorrect! This is DOMNode|null not DOMElement|null
15+
// It's also possible to contain a DOMText node, which is not an instance
16+
// of DOMElement, but an instance of DOMNode!
17+
if ($element->firstChild instanceof DOMText) {
18+
// do something
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)