/** * 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); } }
public function assertDescription($expected, Hamcrest_Matcher $matcher) { $description = new Hamcrest_StringDescription(); $description->appendDescriptionOf($matcher); $this->assertEquals($expected, (string) $description, 'Expected description'); }
public function __toString() { return Hamcrest_StringDescription::toString($this); }