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()); }
/** * @covers PHPUnit_Framework_Constraint_Count * @covers PHPUnit_Framework_TestFailure::exceptionToString */ public function testConstraintCountFailing() { $constraint = new PHPUnit_Framework_Constraint_Count(5); try { $constraint->evaluate(array(1, 2)); } catch (PHPUnit_Framework_ExpectationFailedException $e) { $this->assertEquals(<<<EOF Failed asserting that actual size 2 matches expected size 5. EOF , PHPUnit_Framework_TestFailure::exceptionToString($e)); return; } $this->fail(); }
/** * @covers PHPUnit_Framework_Constraint_Count */ public function testConstraintCountWithAnObjectImplementingCountable() { $constraint = new PHPUnit_Framework_Constraint_Count(5); $this->assertTrue($constraint->evaluate(new ArrayObject(array(1, 2, 3, 4, 5)))); $this->assertFalse($constraint->evaluate(new ArrayObject(array(1, 2, 3, 4)))); }