You are here

public function CountTest::testCountDoesNotChangeIteratorKey in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/tests/Framework/Constraint/CountTest.php \CountTest::testCountDoesNotChangeIteratorKey()

File

vendor/phpunit/phpunit/tests/Framework/Constraint/CountTest.php, line 30

Class

CountTest
@since Class available since Release 3.7.30 @covers PHPUnit_Framework_Constraint_Count

Code

public function testCountDoesNotChangeIteratorKey() {
  $countConstraint = new PHPUnit_Framework_Constraint_Count(2);

  // test with 1st implementation of Iterator
  $it = new TestIterator(array(
    1,
    2,
  ));
  $countConstraint
    ->evaluate($it, '', true);
  $this
    ->assertEquals(1, $it
    ->current());
  $it
    ->next();
  $countConstraint
    ->evaluate($it, '', true);
  $this
    ->assertEquals(2, $it
    ->current());
  $it
    ->next();
  $countConstraint
    ->evaluate($it, '', true);
  $this
    ->assertFalse($it
    ->valid());

  // test with 2nd implementation of Iterator
  $it = new TestIterator2(array(
    1,
    2,
  ));
  $countConstraint = new PHPUnit_Framework_Constraint_Count(2);
  $countConstraint
    ->evaluate($it, '', true);
  $this
    ->assertEquals(1, $it
    ->current());
  $it
    ->next();
  $countConstraint
    ->evaluate($it, '', true);
  $this
    ->assertEquals(2, $it
    ->current());
  $it
    ->next();
  $countConstraint
    ->evaluate($it, '', true);
  $this
    ->assertFalse($it
    ->valid());
}