Skip to content

Commit

Permalink
tests: improve
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Mar 30, 2024
1 parent beb34a0 commit bfb637d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function asNull(): null
*
* @phpstan-assert-if-true array $this->variable
*
* @return array<mixed>
* @return (TVariable is array ? TVariable : never)
*/
public function asArray(): array
{
Expand Down
8 changes: 6 additions & 2 deletions types/AsArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@

use function PHPStan\Testing\assertType;

$variable = random_int(0, 1) !== 0 ? 'string' : [];
assertType('array', type($variable)->asArray());
/** @var array<int, int>|string $variable */
$variable = random_int(0, 1) !== 0 ? 'string' : [1, 2];
assertType('array<int, int>', type($variable)->asArray());

$variable = random_int(0, 1) !== 0 ? 'string' : [1, 2];
assertType('array{int, int}', type($variable)->asArray());

0 comments on commit bfb637d

Please sign in to comment.