Last active
August 29, 2015 13:57
-
-
Save shrikeh/9828880 to your computer and use it in GitHub Desktop.
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
<?php | |
namespace TabletopWargaming\ValueObject\Army\ArmyList; | |
use \FilterIterator; | |
use \Iterator; | |
use \TabletopWargaming\ValueObject\Army\ArmyList; | |
class ListIterator extends FilterIterator | |
{ | |
public function __construct(Iterator $iterator, Filter $filter = null) { | |
$this->filter = $filter; | |
parent::__construct($iterator); | |
} | |
public function accept() | |
{ | |
$accept = true; | |
$unit = $this->current(); | |
if ($filter = $this->getFilter()) { | |
$accept = $filter->filter($unit); | |
} | |
return $accept; | |
} | |
public function getFilter() | |
{ | |
return $this->filter; | |
} | |
public function current() | |
{ | |
return $this->getInnerIterator()->current(); | |
} | |
public function key() { | |
return $this->getInnerIterator()->key(); | |
} | |
public function next() | |
{ | |
return $this->getInnerIterator()->next(); | |
} | |
public function rewind() | |
{ | |
return $this->getInnerIterator()->rewind(); | |
} | |
public function valid() | |
{ | |
return $this->getInnerIterator()->valid(); | |
} | |
} |
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
<?php | |
namespace spec\TabletopWargaming\ValueObject\Army\ArmyList; | |
use \ArrayIterator; | |
use \RecursiveIterator; | |
use \PhpSpec\ObjectBehavior; | |
use \Prophecy\Argument; | |
use \TabletopWargaming\ValueObject\Army\ArmyList\Filter; | |
use \TabletopWargaming\ValueObject\Army\ArmyList\ListIterator; | |
use \TabletopWargaming\ValueObject\Unit; | |
class ListIteratorSpec extends ObjectBehavior | |
{ | |
function it_does_filter(ArrayIterator $it, Filter $filter, Unit $unit) | |
{ | |
$it->current()->willReturn($unit); | |
$filter->filter($unit)->willReturn(false); | |
$this->beConstructedWith($it, $filter); | |
$this->accept()->shouldReturn(false); | |
} | |
function it_iterates_over_units(ArrayIterator $it, Unit $unit) | |
{ | |
$it->current()->willReturn($unit); | |
$this->beConstructedWith($it); | |
$this->current()->shouldReturn($unit); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment