コード例 #1
0
 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');
 }
コード例 #2
0
 private function _describeMismatch(Hamcrest_Matcher $matcher, $item)
 {
     $this->_mismatchDescription->appendText('item with key ' . $this->_nextMatchKey . ': ');
     $matcher->describeMismatch($item, $this->_mismatchDescription);
 }
コード例 #3
0
 /**
  * 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);
     }
 }
コード例 #4
0
ファイル: Expect.php プロジェクト: rafeca/Spec-PHP
 /**
  * Perform the assertion for the configured expression.
  *
  * @throws \RuntimeException
  */
 public function doAssert()
 {
     $matcher = $this->expression->build();
     $this->subject->doAssert($matcher, $this->message);
 }
コード例 #5
0
 public function __toString()
 {
     return $this->matcher->__toString();
 }
コード例 #6
0
 /**
  * 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));
 }