public function assertMismatchDescription($expected, Hamcrest_Matcher $matcher, $arg) { $description = new Hamcrest_StringDescription(); $this->assertFalse($matcher->matches($arg), 'Precondtion: Matcher should not match item'); $matcher->describeMismatch($arg, $description); $this->assertEquals($expected, (string) $description, 'Expected mismatch description'); }
private function _describeMismatch(Hamcrest_Matcher $matcher, $item) { $this->_mismatchDescription->appendText('item with key ' . $this->_nextMatchKey . ': '); $matcher->describeMismatch($item, $this->_mismatchDescription); }
/** * Performs the actual assertion logic. * * If <code>$matcher</code> doesn't match <code>$actual</code>, * throws a {@link Hamcrest_AssertionError} with a description * of the failure along with the optional <code>$identifier</code>. * * @param string $identifier added to the message upon failure * @param mixed $actual value to compare against <code>$matcher</code> * @param Hamcrest_Matcher $matcher applied to <code>$actual</code> */ private static function doAssert($identifier, $actual, Hamcrest_Matcher $matcher) { if (!$matcher->matches($actual)) { $description = new Hamcrest_StringDescription(); if (!empty($identifier)) { $description->appendText($identifier . PHP_EOL); } $description->appendText('Expected: ')->appendDescriptionOf($matcher)->appendText(PHP_EOL . ' but: '); $matcher->describeMismatch($actual, $description); throw new Hamcrest_AssertionError((string) $description); } }
/** * Perform the assertion for the configured expression. * * @throws \RuntimeException */ public function doAssert() { $matcher = $this->expression->build(); $this->subject->doAssert($matcher, $this->message); }
public function __toString() { return $this->matcher->__toString(); }
/** * Tests that calls to matches are forwarded to hamcrest's matcher method */ public function testMatchesCallsForwarded() { $this->matcher->expects($this->once())->method('matches')->with($this->equalTo('foo'))->will($this->returnValue(true)); $value = 'foo'; $this->assertTrue($this->adapter->matches($value)); }