Skip to content

Commit

Permalink
Added regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored and ondrejmirtes committed Oct 9, 2024
1 parent 4a8d584 commit ee6e0ef
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,16 @@ public function testBug11549(): void
$this->analyse([__DIR__ . '/data/bug-11549.php'], []);
}

public function testBug11301(): void
{
$this->checkExplicitMixed = true;
$this->checkNullables = true;
$this->analyse([__DIR__ . '/data/bug-11301.php'], [
[
'Function Bug11301\cString() should return array<string, string> but returns array<int, string>.',
35,
],
]);
}

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

namespace Bug11301;

/**
* @return array<int, string>
*/
function cInt(): array
{
$a = ['12345'];
$b = ['abc'];

return array_combine($a, $b);
}

/**
* @return array<int, string>
*/
function cInt2(): array
{
$a = ['12345', 123];
$b = ['abc', 'def'];

return array_combine($a, $b);
}

/**
* @return array<string, string>
*/
function cString(): array
{
$a = ['12345'];
$b = ['abc'];

return array_combine($a, $b);
}


/**
* @return array<int|string, string>
*/
function cString2(): array
{
$a = ['12345', 123, 'a'];
$b = ['abc', 'def', 'xy'];

return array_combine($a, $b);
}

0 comments on commit ee6e0ef

Please sign in to comment.