diff --git a/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php b/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php index da1defc264..fc909c4369 100644 --- a/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php +++ b/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php @@ -384,4 +384,14 @@ public function testEnumInstantiation(): void ]); } + public function testBug6370(): void + { + $this->analyse([__DIR__ . '/data/bug-6370.php'], [ + [ + 'Parameter #1 $something of class Bug6370\A constructor expects string, int given.', + 45, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Classes/data/bug-6370.php b/tests/PHPStan/Rules/Classes/data/bug-6370.php new file mode 100644 index 0000000000..5744316ed3 --- /dev/null +++ b/tests/PHPStan/Rules/Classes/data/bug-6370.php @@ -0,0 +1,53 @@ +analyse([__DIR__ . '/data/first-class-callables.php'], []); } + public function testBug4413(): void + { + require_once __DIR__ . '/data/bug-4413.php'; + $this->analyse([__DIR__ . '/data/bug-4413.php'], [ + [ + 'Parameter #1 $date of function Bug4413\takesDate expects class-string, string given.', + 18, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Functions/data/bug-4413.php b/tests/PHPStan/Rules/Functions/data/bug-4413.php new file mode 100644 index 0000000000..3c8b1ffda7 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/bug-4413.php @@ -0,0 +1,21 @@ + $date + */ +function takesDate(string $date): void {} + +function input(string $in): void { + switch ($in) { + case DateTime::class : + takesDate($in); + break; + case \stdClass::class : + takesDate($in); + break; + } +}