/** * 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(Util::wrapValueWithIsEqual($firstArg)); }
/** * Evaluates to true if any key in an array matches the given matcher. * * @param mixed $key as a {@link Hamcrest\Matcher} or a value. * * @return \Hamcrest\Arrays\IsArrayContainingKey * @factory hasKey */ public static function hasKeyInArray($key) { return new self(Util::wrapValueWithIsEqual($key)); }
/** * 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(Util::wrapValueWithIsEqual($key), Util::wrapValueWithIsEqual($value)); }
/** * Does array size satisfy a given matcher? * * @param \Hamcrest\Matcher|int $size as a {@link Hamcrest\Matcher} or a value. * * @return \Hamcrest\Arrays\IsArrayWithSize * @factory */ public static function arrayWithSize($size) { return new self(Util::wrapValueWithIsEqual($size)); }
/** * 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(Util::wrapValueWithIsEqual($value)); }
/** * Does traversable size satisfy a given matcher? * * @factory */ public static function traversableWithSize($size) { return new self(Util::wrapValueWithIsEqual($size)); }
/** * Does array size satisfy a given matcher? * * @factory */ public static function hasToString($matcher) { return new self(Util::wrapValueWithIsEqual($matcher)); }
/** * Evaluates to true if any item in an array satisfies the given matcher. * * @param mixed $item as a {@link Hamcrest\Matcher} or a value. * * @return \Hamcrest\Arrays\IsArrayContaining * @factory hasValue */ public static function hasItemInArray($item) { return new self(Util::wrapValueWithIsEqual($item)); }
public function testWrapValueWithIsEqualWrapsPrimitive() { $matcher = \Hamcrest\Util::wrapValueWithIsEqual('foo'); $this->assertInstanceOf('Hamcrest\\Core\\IsEqual', $matcher); $this->assertTrue($matcher->matches('foo')); }