From 94324f6e50b2b4766ac2b54ee61470b9eca28e73 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 30 Oct 2023 16:15:34 +0100 Subject: [PATCH] add chained test --- src/Resources/LazyCollection.php | 8 +++++--- tests/Mollie/API/Resources/LazyCollectionTest.php | 13 +++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Resources/LazyCollection.php b/src/Resources/LazyCollection.php index 3625aecf..0fc90f08 100644 --- a/src/Resources/LazyCollection.php +++ b/src/Resources/LazyCollection.php @@ -8,6 +8,8 @@ /** * @template TKey of array-key * @template TValue + * + * @implements IteratorAggregate */ class LazyCollection implements IteratorAggregate { @@ -37,8 +39,8 @@ public function all(): array /** * Get an item from the collection by key. * - * @param int|string $key - * @return mixed|null + * @param TKey $key + * @return TValue|null */ public function get($key) { @@ -113,7 +115,7 @@ public function map(callable $callback): self } /** - * Take the first or last {$limit} items. + * Take the first {$limit} items. * * @param int $limit * @return static diff --git a/tests/Mollie/API/Resources/LazyCollectionTest.php b/tests/Mollie/API/Resources/LazyCollectionTest.php index 310ed190..726c76bc 100644 --- a/tests/Mollie/API/Resources/LazyCollectionTest.php +++ b/tests/Mollie/API/Resources/LazyCollectionTest.php @@ -84,4 +84,17 @@ public function testEvery() return $value > 1; })); } + + public function testChainedUsage() + { + $result = $this->collection + ->filter(function ($value) { + return $value > 1; + })->map(function ($value) { + return $value * 2; + })->take(1); + + $this->assertEquals(1, $result->count()); + $this->assertEquals(4, $result->first()); + } }