Skip to content

Commit

Permalink
fix: Fix RandomIterator::rewind().
Browse files Browse the repository at this point in the history
Signed-off-by: Pol Dellaiera <[email protected]>
  • Loading branch information
drupol committed Oct 11, 2020
1 parent 053cb80 commit c3c1dd0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
34 changes: 33 additions & 1 deletion spec/loophp/collection/Iterator/RandomIteratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,46 @@ public function it_can_get_the_innerIterator()
$this->getInnerIterator()->shouldBeAnInstanceOf(ArrayIterator::class);
}

public function it_can_rewind()
{
$iterator = new ArrayIterator(['a']);

$this->beConstructedWith($iterator);

$this
->valid()
->shouldReturn(true);

$this
->current()
->shouldReturn('a');

$this->next();

$this
->valid()
->shouldReturn(false);

$this
->rewind();

$this
->valid()
->shouldReturn(true);

$this
->current()
->shouldReturn('a');
}

public function it_is_initializable()
{
$this->shouldHaveType(RandomIterator::class);
}

public function let()
{
$iterator = new ArrayIterator(range(0, 4));
$iterator = new ArrayIterator(range('a', 'c'));

$this->beConstructedWith($iterator);
}
Expand Down
1 change: 1 addition & 0 deletions src/Iterator/RandomIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function next(): void

public function rewind()
{
$this->indexes = array_keys($this->iterator->getArrayCopy());
$this->iterator->rewind();
}

Expand Down

0 comments on commit c3c1dd0

Please sign in to comment.