Skip to content

Commit dc793e9

Browse files
committed
Add tests
1 parent 1c25bde commit dc793e9

File tree

2 files changed

+59
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)