protected function matches($actual) { if ($this->analyzer->isInteger($this->expected) === false) { throw new \PHPUnit_Framework_Exception('Expected value of ' . __CLASS__ . ' must be an integer'); } switch (true) { case $this->analyzer->isArray($actual): $asserter = new asserters\phpArray(null, $this->analyzer); $asserter->setWith($actual)->hasSize($this->expected); break; case $actual instanceof \countable: $asserter = new asserters\sizeOf(null, $this->analyzer); $asserter->setWith($actual)->isEqualTo($this->expected); break; case $actual instanceof \iteratorAggregate: $asserter = new asserters\integer(null, $this->analyzer); $asserter->setWith(iterator_count($actual->getIterator()))->isEqualTo($this->expected); break; case $actual instanceof \traversable: case $actual instanceof \iterator: $asserter = new asserters\integer(null, $this->analyzer); $asserter->setWith(iterator_count($actual))->isEqualTo($this->expected); break; default: throw new \PHPUnit_Framework_Exception('Actual value of ' . __CLASS__ . ' must be an array, a countable object or a traversable object'); } }
public function testSetWith() { $this->if($asserter = new sut($generator = new asserter\generator()))->then->object($asserter->setWith(array()))->isIdenticalTo($asserter)->boolean($asserter->wasSet())->isTrue()->integer($asserter->getValue())->isZero()->object($asserter->setWith($countable = range(1, rand(2, 5))))->isIdenticalTo($asserter)->boolean($asserter->wasSet())->isTrue()->integer($asserter->getValue())->isEqualTo(sizeof($countable)); }