-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9a5aaa
commit 84c811c
Showing
4 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the Nexus framework. | ||
* | ||
* (c) John Paul E. Balandan, CPA <paulbalandan@gmail.com> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nexus\Tests\Collection; | ||
|
||
use PHPStan\Testing\TypeInferenceTestCase; | ||
use PHPUnit\Framework\Attributes\CoversNothing; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\Attributes\Group; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[CoversNothing] | ||
#[Group('static-analysis')] | ||
final class CollectionTypeInferenceTest extends TypeInferenceTestCase | ||
{ | ||
#[DataProvider('provideFileAssertsCases')] | ||
public function testFileAsserts(string $assertType, string $file, mixed ...$args): void | ||
{ | ||
$this->assertFileAsserts($assertType, $file, ...$args); | ||
} | ||
|
||
/** | ||
* @return iterable<string, list<mixed>> | ||
*/ | ||
public static function provideFileAssertsCases(): iterable | ||
{ | ||
// @phpstan-ignore generator.valueType | ||
yield from self::gatherAssertTypesFromDirectory(__DIR__.'/data'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the Nexus framework. | ||
* | ||
* (c) John Paul E. Balandan, CPA <paulbalandan@gmail.com> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nexus\Tests\Collection; | ||
|
||
use Nexus\Collection\Collection; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
assertType( | ||
'Nexus\Collection\Collection<string, int>', | ||
new Collection(static function (): iterable { | ||
yield 'apple' => 1; | ||
}), | ||
); | ||
assertType('Nexus\Collection\Collection<int, string>', Collection::wrap(['a', 'b', 'c'])); | ||
assertType( | ||
'Nexus\Collection\Collection<string, bool>', | ||
Collection::wrap(static function (): iterable { | ||
yield 'a' => true; | ||
|
||
yield 'b' => true; | ||
|
||
yield 'c' => false; | ||
}), | ||
); | ||
assertType('Nexus\Collection\Collection<int, int>', Collection::wrap(new \ArrayIterator([1, 2]))); | ||
|
||
assertType('array<int>', Collection::wrap(['a' => 1, 'b' => 2])->all(true)); | ||
assertType('array<int, int>', Collection::wrap(['a' => 1, 'b' => 2])->all()); | ||
|
||
$collection = Collection::wrap(['apples' => 10, 'bananas' => 20]); | ||
assertType('Nexus\Collection\Collection<int, string>', $collection->keys()); | ||
assertType('Nexus\Collection\Collection<int, int>', $collection->values()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the Nexus framework. | ||
* | ||
* (c) John Paul E. Balandan, CPA <paulbalandan@gmail.com> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nexus\Tests\Collection; | ||
|
||
use Nexus\Collection\Collection; | ||
use Nexus\Collection\Iterator\ClosureIteratorAggregate; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
assertType( | ||
'Nexus\Collection\Iterator\ClosureIteratorAggregate<int, string>', | ||
ClosureIteratorAggregate::from( | ||
static fn(string $item): iterable => yield $item, | ||
'a', | ||
), | ||
); | ||
assertType( | ||
// @todo Make PHPStan understand the key is 'int' | ||
'Nexus\Collection\Iterator\ClosureIteratorAggregate<mixed, string>', | ||
ClosureIteratorAggregate::from( | ||
static function (iterable $collection): iterable { | ||
foreach ($collection as $key => $item) { | ||
assertType('int', $key); | ||
|
||
yield $key => get_debug_type($item); | ||
} | ||
}, | ||
Collection::wrap([1, new \stdClass()]), | ||
), | ||
); |