Example #1
0
 /**
  * Make an assertion and throw {@link Hamcrest_AssertionError} if it fails.
  *
  * The first parameter may optionally be a string identifying the assertion
  * to be included in the failure message.
  *
  * If the third parameter is not a matcher it is passed to
  * {@link Hamcrest_Core_IsEqual#equalTo} to create one.
  *
  * Example:
  * <pre>
  * // With an identifier
  * assertThat("apple flavour", $apple->flavour(), equalTo("tasty"));
  * // Without an identifier
  * assertThat($apple->flavour(), equalTo("tasty"));
  * // Evaluating a boolean expression
  * assertThat("some error", $a > $b);
  * assertThat($a > $b);
  * </pre>
  */
 public static function assertThat()
 {
     $args = func_get_args();
     switch (count($args)) {
         case 1:
             self::$_count++;
             if (!$args[0]) {
                 throw new Hamcrest_AssertionError();
             }
             break;
         case 2:
             self::$_count++;
             if ($args[1] instanceof Hamcrest_Matcher) {
                 self::doAssert('', $args[0], $args[1]);
             } elseif (!$args[1]) {
                 throw new Hamcrest_AssertionError($args[0]);
             }
             break;
         case 3:
             self::$_count++;
             self::doAssert($args[0], $args[1], Hamcrest_Util::wrapValueWithIsEqual($args[2]));
             break;
         default:
             throw new InvalidArgumentException('assertThat() requires one to three arguments');
     }
 }
Example #2
0
 private function callAndAssertCreateMatcherArray($items)
 {
     $matchers = Hamcrest_Util::createMatcherArray($items);
     $this->assertInternalType('array', $matchers);
     $this->assertSameSize($items, $matchers);
     foreach ($matchers as $matcher) {
         $this->assertInstanceOf('Hamcrest_Matcher', $matcher);
     }
     return $matchers;
 }
Example #3
0
 /**
  * Evaluates to false if ANY of the passed in matchers evaluate to true.
  *
  * @factory ...
  */
 public static function noneOf()
 {
     $args = func_get_args();
     return Hamcrest_Core_IsNot::not(new self(Hamcrest_Util::createMatcherArray($args)));
 }
Example #4
0
 /**
  * Evaluates to true only if each $matcher[$i] is satisfied by $array[$i].
  *
  * @factory ...
  */
 public static function anArray()
 {
     $args = func_get_args();
     return new self(Hamcrest_Util::createMatcherArray($args));
 }
 /**
  * Does traversable size satisfy a given matcher?
  *
  * @factory
  */
 public static function traversableWithSize($size)
 {
     return new self(Hamcrest_Util::wrapValueWithIsEqual($size));
 }
 /**
  * Test if the value is an array containing this matcher.
  *
  * Example:
  * <pre>
  * assertThat(array('a', 'b'), hasItem(equalTo('b')));
  * //Convenience defaults to equalTo()
  * assertThat(array('a', 'b'), hasItem('b'));
  * </pre>
  *
  * @factory ...
  */
 public static function hasItem()
 {
     $args = func_get_args();
     $firstArg = array_shift($args);
     return new self(Hamcrest_Util::wrapValueWithIsEqual($firstArg));
 }
Example #7
0
 /**
  * Decorates another Matcher, retaining the behavior but allowing tests
  * to be slightly more expressive.
  *
  * For example:  assertThat($cheese, equalTo($smelly))
  *          vs.  assertThat($cheese, is(equalTo($smelly)))
  *
  * @factory
  */
 public static function is($value)
 {
     return new self(Hamcrest_Util::wrapValueWithIsEqual($value));
 }
 /**
  * Evaluates to true if any item in an array satisfies the given matcher.
  *
  * @param mixed $item as a {@link Hamcrest_Matcher} or a value.
  *
  * @factory hasValue
  */
 public static function hasItemInArray($item)
 {
     return new self(Hamcrest_Util::wrapValueWithIsEqual($item));
 }
 /**
  * Evaluates to true if any key in an array matches the given matcher.
  *
  * @param mixed $key as a {@link Hamcrest_Matcher} or a value.
  *
  * @factory hasKey
  */
 public static function hasKeyInArray($key)
 {
     return new self(Hamcrest_Util::wrapValueWithIsEqual($key));
 }
Example #10
0
 /**
  * Does array size satisfy a given matcher?
  *
  * @factory
  */
 public static function hasToString($matcher)
 {
     return new self(Hamcrest_Util::wrapValueWithIsEqual($matcher));
 }
 /**
  * An array with elements that match the given matchers.
  *
  * @factory containsInAnyOrder ...
  */
 public static function arrayContainingInAnyOrder()
 {
     $args = func_get_args();
     return new self(Hamcrest_Util::createMatcherArray($args));
 }
 public function __construct(array $matchers)
 {
     Hamcrest_Util::checkAllAreMatchers($matchers);
     $this->_matchers = $matchers;
 }
 /**
  * Test if an array has both an key and value in parity with each other.
  *
  * @factory hasEntry
  */
 public static function hasKeyValuePair($key, $value)
 {
     return new self(Hamcrest_Util::wrapValueWithIsEqual($key), Hamcrest_Util::wrapValueWithIsEqual($value));
 }