Skip to content

Commit a59fc5d

Browse files
committed
Add tests
1 parent e5d182f commit a59fc5d

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

tests/PHPStan/Rules/Classes/InstantiationRuleTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,4 +504,34 @@ public function testBug11815(): void
504504
$this->analyse([__DIR__ . '/data/bug-11815.php'], []);
505505
}
506506

507+
public function testClassString(): void
508+
{
509+
$this->analyse([__DIR__ . '/data/class-string.php'], [
510+
[
511+
'Parameter #1 $i of class ClassString\A constructor expects int, string given.',
512+
26,
513+
],
514+
[
515+
'Parameter #1 $i of class ClassString\A constructor expects int, string given.',
516+
27,
517+
],
518+
[
519+
'Parameter #1 $i of class ClassString\A constructor expects int, string given.',
520+
28,
521+
],
522+
[
523+
'Parameter #1 $i of class ClassString\A constructor expects int, string given.',
524+
31,
525+
],
526+
[
527+
'Parameter #1 $i of class ClassString\A constructor expects int, string given.',
528+
32,
529+
],
530+
[
531+
'Parameter #1 $i of class ClassString\A constructor expects int, string given.',
532+
34,
533+
],
534+
]);
535+
}
536+
507537
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php // lint >= 8.0
2+
3+
declare(strict_types = 1);
4+
5+
namespace ClassString;
6+
7+
class A
8+
{
9+
public function __construct(public int $i)
10+
{
11+
}
12+
}
13+
14+
class HelloWorld
15+
{
16+
/**
17+
* @return class-string<A>
18+
*/
19+
public static function sayHelloBug(): string
20+
{
21+
return A::class;
22+
}
23+
}
24+
25+
$classString = HelloWorld::sayHelloBug();
26+
$bug = new (HelloWorld::sayHelloBug())('O_O');
27+
$bug = new ($classString)('O_O');
28+
$bug = new $classString('O_O');
29+
30+
$className = A::class;
31+
$ok = new ($className)('O_O');
32+
$ok = new $className('O_O');
33+
34+
$ok = new A('O_O');

0 commit comments

Comments
 (0)