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(); }
/** * @param int $expected */ public function __construct($expected) { parent::__construct($this->getCountOf($expected)); }
/** * @covers PHPUnit_Framework_Constraint_Count */ public function testConstraintCountFailing() { $constraint = new PHPUnit_Framework_Constraint_Count(5); try { $constraint->fail(array(1, 2), ''); } catch (PHPUnit_Framework_ExpectationFailedException $e) { $this->assertEquals('Count of 2 does not match expected count of 5.', $e->getDescription()); return; } $this->fail(); }