Skip to content

Commit

Permalink
Regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 12, 2021
1 parent 3e0ecec commit 8596663
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -843,4 +843,32 @@ public function testArrayMapMultiple(bool $checkExplicitMixed): void
]);
}

public function testBug5356(): void
{
if (PHP_VERSION_ID < 70400 && !self::$useStaticReflectionProvider) {
$this->markTestSkipped('Test requires PHP 7.4.');
}

$this->analyse([__DIR__ . '/data/bug-5356.php'], [
[
'Parameter #1 $callback of function array_map expects callable(string): mixed, Closure(array): \'a\' given.',
13,
],
[
'Parameter #1 $callback of function array_map expects callable(string): mixed, Closure(array): \'a\' given.',
21,
],
]);
}

public function testBug1954(): void
{
$this->analyse([__DIR__ . '/data/bug-1954.php'], [
[
'Parameter #1 $callback of function array_map expects callable(1|stdClass): mixed, Closure(string): string given.',
7,
],
]);
}

}
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-1954.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Bug1954;

function (): void {
$a = [1, new \stdClass()];
$b = array_map(function (string $s) : string { return $s; }, $a);
};
24 changes: 24 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-5356.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php // lint >= 7.4

namespace Bug5356;

class Foo
{

public function doFoo(): void
{
/** @var array{name: string, collectors: string[]} $array */
$array = [];

array_map(static fn(array $_): string => 'a', $array['collectors']);
}

public function doBar(): void
{
/** @var array{name: string, collectors: string[]} $array */
$array = [];

array_map(static function(array $_): string { return 'a'; }, $array['collectors']);
}

}

0 comments on commit 8596663

Please sign in to comment.