Skip to content

Commit

Permalink
add chained test
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoray committed Oct 30, 2023
1 parent 9f39287 commit 94324f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Resources/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
/**
* @template TKey of array-key
* @template TValue
*
* @implements IteratorAggregate<TKey, TValue>
*/
class LazyCollection implements IteratorAggregate
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions tests/Mollie/API/Resources/LazyCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 94324f6

Please sign in to comment.