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; }
public function __construct(array $matchers) { Util::checkAllAreMatchers($matchers); $this->_matchers = $matchers; }
/** * An array with elements that match the given matchers in the same order. * * @factory contains ... */ public static function arrayContaining() { $args = func_get_args(); return new self(Util::createMatcherArray($args)); }
/** * 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 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)); }
/** * 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)); }
/** * Evaluates to false if ANY of the passed in matchers evaluate to true. * * @factory ... */ public static function noneOf() { $args = func_get_args(); return IsNot::not(new self(Util::createMatcherArray($args))); }
/** * 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)); }
/** * 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)); }
public static function setUpBeforeClass() { // Require the Hamcrest global functions. Util::registerGlobalFunctions(); }
/** * 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)); }
<?php /** * Test bootstrap */ use Hamcrest\Util; require_once __DIR__ . "/../vendor/autoload.php"; Util::registerGlobalFunctions();