Skip to content

Commit

Permalink
test: Update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Oct 18, 2020
1 parent b3b3c62 commit 693e7a6
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
63 changes: 63 additions & 0 deletions spec/loophp/collection/Iterator/CacheIteratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,76 @@

namespace spec\loophp\collection\Iterator;

use ArrayIterator;
use Iterator;
use loophp\collection\Iterator\CacheIterator;
use PhpSpec\ObjectBehavior;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\CacheItem;

class CacheIteratorSpec extends ObjectBehavior
{
public function it_can_cache_data(CacheItemPoolInterface $cache)
{
$it = new ArrayIterator(range('a', 'e'));

$this->beConstructedWith($it, $cache);

$cacheItem = new CacheItem();
$cacheItem->set('a');

$cache
->save($cacheItem)
->willReturn(true);

$cache
->getItem(0)
->willReturn($cacheItem);

$cache
->hasItem(0)
->willReturn(true);

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

$cache
->getItem(0)
->shouldHaveBeenCalledOnce();

$this->rewind();

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

$cacheItem = new CacheItem();
$cacheItem->set('b');

$cache
->save($cacheItem)
->willReturn(true);

$cache
->getItem(1)
->willReturn($cacheItem);

$cache
->hasItem(1)
->willReturn(false);

$this->next();

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

$cache
->save($cacheItem)
->shouldHaveBeenCalledOnce();
}

public function it_can_get_the_inner_iterator(Iterator $iterator, CacheItemPoolInterface $cache)
{
$this
Expand Down
33 changes: 33 additions & 0 deletions spec/loophp/collection/Operation/CurrentSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace spec\loophp\collection\Operation;

use ArrayIterator;
use loophp\collection\Operation\Current;
use PhpSpec\ObjectBehavior;

class CurrentSpec extends ObjectBehavior
{
public function it_can_get_current()
{
$input = range('a', 'e');

$iterator = new ArrayIterator($input);

$this
->__invoke()(0)($iterator)
->current()
->shouldReturn('a');

$this
->__invoke()(0)($iterator)
->shouldHaveCount(1);
}

public function it_is_initializable()
{
$this->shouldHaveType(Current::class);
}
}
48 changes: 48 additions & 0 deletions spec/loophp/collection/Operation/LimitSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace spec\loophp\collection\Operation;

use ArrayIterator;
use loophp\collection\Operation\Limit;
use PhpSpec\ObjectBehavior;

class LimitSpec extends ObjectBehavior
{
public function it_can_set_a_limit()
{
$input = range('a', 'e');

$iterator = new ArrayIterator($input);

$this
->__invoke()(1)(0)($iterator)
->shouldHaveCount(1);

$this
->__invoke()(2)(0)($iterator)
->shouldHaveCount(2);
}

public function it_can_set_an_offset()
{
$input = range('a', 'e');

$iterator = new ArrayIterator($input);

$this
->__invoke()(1)(2)($iterator)
->current()
->shouldReturn('c');

$this
->__invoke()(2)(2)($iterator)
->shouldHaveCount(2);
}

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

0 comments on commit 693e7a6

Please sign in to comment.