Skip to content

Commit f6c5c24

Browse files
committed
Add tests
1 parent 1c25bde commit f6c5c24

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
@@ -499,4 +499,34 @@ public function testBug10248(): void
499499
$this->analyse([__DIR__ . '/data/bug-10248.php'], []);
500500
}
501501

502+
public function testClassString(): void
503+
{
504+
$this->analyse([__DIR__ . '/data/class-string.php'], [
505+
[
506+
'Parameter #1 $i of class ClassString\A constructor expects int, string given.',
507+
26,
508+
],
509+
[
510+
'Parameter #1 $i of class ClassString\A constructor expects int, string given.',
511+
27,
512+
],
513+
[
514+
'Parameter #1 $i of class ClassString\A constructor expects int, string given.',
515+
28,
516+
],
517+
[
518+
'Parameter #1 $i of class ClassString\A constructor expects int, string given.',
519+
31,
520+
],
521+
[
522+
'Parameter #1 $i of class ClassString\A constructor expects int, string given.',
523+
32,
524+
],
525+
[
526+
'Parameter #1 $i of class ClassString\A constructor expects int, string given.',
527+
34,
528+
],
529+
]);
530+
}
531+
502532
}
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)