Skip to content

Commit

Permalink
Add allKeyExists tests
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm authored and ondrejmirtes committed Nov 29, 2021
1 parent a00dad3 commit 6371a58
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class AssertTypeSpecifyingExtensionTest extends TypeInferenceTestCase
public function dataFileAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__ . '/data/array.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/collection.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/data.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/string.php');
}
Expand Down
27 changes: 27 additions & 0 deletions tests/Type/WebMozartAssert/data/collection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types = 1);

namespace PHPStan\Type\WebMozartAssert;

use Webmozart\Assert\Assert;

class Foo
{

/**
* @param array<array{id?: int}> $a
* @param array<int, array<string, mixed>> $b
*
*/
public function allKeyExists(array $a, array $b, array $c): void
{
Assert::allKeyExists($a, 'id');
\PHPStan\Testing\assertType('array<array{id: int}>', $a);

Assert::allKeyExists($b, 'id');
\PHPStan\Testing\assertType('array<int, array<string, mixed>&hasOffset(\'id\')>', $b);

Assert::allKeyExists($c, 'id');
\PHPStan\Testing\assertType('array<array&hasOffset(\'id\')>', $c);
}

}

0 comments on commit 6371a58

Please sign in to comment.