File manager - Edit - /home/linknsbh/sabel-eltaqwa.com/assets/lfm/files/shares/events/thumbs/hamcrest.zip
Back
PK j��\��.8�* �* hamcrest-php/README.mdnu �[��� This is the PHP port of Hamcrest Matchers ========================================= [](https://github.com/hamcrest/hamcrest-php/actions/workflows/tests.yml) Hamcrest is a matching library originally written for Java, but subsequently ported to many other languages. hamcrest-php is the official PHP port of Hamcrest and essentially follows a literal translation of the original Java API for Hamcrest, with a few Exceptions, mostly down to PHP language barriers: 1. `instanceOf($theClass)` is actually `anInstanceOf($theClass)` 2. `both(containsString('a'))->and(containsString('b'))` is actually `both(containsString('a'))->andAlso(containsString('b'))` 3. `either(containsString('a'))->or(containsString('b'))` is actually `either(containsString('a'))->orElse(containsString('b'))` 4. Unless it would be non-semantic for a matcher to do so, hamcrest-php allows dynamic typing for it's input, in "the PHP way". Exception are where semantics surrounding the type itself would suggest otherwise, such as stringContains() and greaterThan(). 5. Several official matchers have not been ported because they don't make sense or don't apply in PHP: - `typeCompatibleWith($theClass)` - `eventFrom($source)` - `hasProperty($name)` ** - `samePropertyValuesAs($obj)` ** 6. When most of the collections matchers are finally ported, PHP-specific aliases will probably be created due to a difference in naming conventions between Java's Arrays, Collections, Sets and Maps compared with PHP's Arrays. --- ** [Unless we consider POPO's (Plain Old PHP Objects) akin to JavaBeans] - The POPO thing is a joke. Java devs coin the term POJO's (Plain Old Java Objects). Usage ----- Hamcrest matchers are easy to use as: ```php Hamcrest_MatcherAssert::assertThat('a', Hamcrest_Matchers::equalToIgnoringCase('A')); ``` Alternatively, you can use the global proxy-functions: ```php $result = true; // with an identifier assertThat("result should be true", $result, equalTo(true)); // without an identifier assertThat($result, equalTo(true)); // evaluate a boolean expression assertThat($result === true); // with syntactic sugar is() assertThat(true, is(true)); ``` :warning: **NOTE:** the global proxy-functions aren't autoloaded by default, so you will need to load them first: ```php \Hamcrest\Util::registerGlobalFunctions(); ``` For brevity, all of the examples below use the proxy-functions. Documentation ------------- A tutorial can be found on the [Hamcrest site](https://code.google.com/archive/p/hamcrest/wikis/TutorialPHP.wiki). Available Matchers ------------------ * [Array](../master/README.md#array) * [Collection](../master/README.md#collection) * [Object](../master/README.md#object) * [Numbers](../master/README.md#numbers) * [Type checking](../master/README.md#type-checking) * [XML](../master/README.md#xml) ### Array * `anArray` - evaluates an array ```php assertThat([], anArray()); ``` * `hasItemInArray` - check if item exists in array ```php $list = range(2, 7, 2); $item = 4; assertThat($list, hasItemInArray($item)); ``` * `hasValue` - alias of hasItemInArray * `arrayContainingInAnyOrder` - check if array contains elements in any order ```php assertThat([2, 4, 6], arrayContainingInAnyOrder([6, 4, 2])); assertThat([2, 4, 6], arrayContainingInAnyOrder([4, 2, 6])); ``` * `containsInAnyOrder` - alias of arrayContainingInAnyOrder * `arrayContaining` - An array with elements that match the given matchers in the same order. ```php assertThat([2, 4, 6], arrayContaining([2, 4, 6])); assertthat([2, 4, 6], not(arrayContaining([6, 4, 2]))); ``` * `contains` - check array in same order ```php assertThat([2, 4, 6], contains([2, 4, 6])); ``` * `hasKeyInArray` - check if array has given key ```php assertThat(['name'=> 'foobar'], hasKeyInArray('name')); ``` * `hasKey` - alias of hasKeyInArray * `hasKeyValuePair` - check if array has given key, value pair ```php assertThat(['name'=> 'foobar'], hasKeyValuePair('name', 'foobar')); ``` * `hasEntry` - same as hasKeyValuePair * `arrayWithSize` - check array has given size ```php assertthat([2, 4, 6], arrayWithSize(3)); ``` * `emptyArray` - check if array is empty ```php assertThat([], emptyArray()); ``` * `nonEmptyArray` ```php assertThat([1], nonEmptyArray()); ``` ### Collection * `emptyTraversable` - check if traversable is empty ```php $empty_it = new EmptyIterator; assertThat($empty_it, emptyTraversable()); ``` * `nonEmptyTraversable` - check if traversable isn't empty ```php $non_empty_it = new ArrayIterator(range(1, 10)); assertThat($non_empty_it, nonEmptyTraversable()); a ``` * `traversableWithSize` ```php $non_empty_it = new ArrayIterator(range(1, 10)); assertThat($non_empty_it, traversableWithSize(count(range(1, 10)))); ` ``` ### Core * `allOf` - Evaluates to true only if ALL of the passed in matchers evaluate to true. ```php assertThat([2,4,6], allOf(hasValue(2), arrayWithSize(3))); ``` * `anyOf` - Evaluates to true if ANY of the passed in matchers evaluate to true. ```php assertThat([2, 4, 6], anyOf(hasValue(8), hasValue(2))); ``` * `noneOf` - Evaluates to false if ANY of the passed in matchers evaluate to true. ```php assertThat([2, 4, 6], noneOf(hasValue(1), hasValue(3))); ``` * `both` + `andAlso` - This is useful for fluently combining matchers that must both pass. ```php assertThat([2, 4, 6], both(hasValue(2))->andAlso(hasValue(4))); ``` * `either` + `orElse` - This is useful for fluently combining matchers where either may pass, ```php assertThat([2, 4, 6], either(hasValue(2))->orElse(hasValue(4))); ``` * `describedAs` - Wraps an existing matcher and overrides the description when it fails. ```php $expected = "Dog"; $found = null; // this assertion would result error message as Expected: is not null but: was null //assertThat("Expected {$expected}, got {$found}", $found, is(notNullValue())); // and this assertion would result error message as Expected: Dog but: was null //assertThat($found, describedAs($expected, notNullValue())); ``` * `everyItem` - A matcher to apply to every element in an array. ```php assertThat([2, 4, 6], everyItem(notNullValue())); ``` * `hasItem` - check array has given item, it can take a matcher argument ```php assertThat([2, 4, 6], hasItem(equalTo(2))); ``` * `hasItems` - check array has given items, it can take multiple matcher as arguments ```php assertThat([1, 3, 5], hasItems(equalTo(1), equalTo(3))); ``` ### Object * `hasToString` - check `__toString` or `toString` method ```php class Foo { public $name = null; public function __toString() { return "[Foo]Instance"; } } $foo = new Foo; assertThat($foo, hasToString(equalTo("[Foo]Instance"))); ``` * `equalTo` - compares two instances using comparison operator '==' ```php $foo = new Foo; $foo2 = new Foo; assertThat($foo, equalTo($foo2)); ``` * `identicalTo` - compares two instances using identity operator '===' ```php assertThat($foo, is(not(identicalTo($foo2)))); ``` * `anInstanceOf` - check instance is an instance|sub-class of given class ```php assertThat($foo, anInstanceOf(Foo::class)); ``` * `any` - alias of `anInstanceOf` * `nullValue` check null ```php assertThat(null, is(nullValue())); ``` * `notNullValue` check not null ```php assertThat("", notNullValue()); ``` * `sameInstance` - check for same instance ```php assertThat($foo, is(not(sameInstance($foo2)))); assertThat($foo, is(sameInstance($foo))); ``` * `typeOf`- check type ```php assertThat(1, typeOf("integer")); ``` * `notSet` - check if instance property is not set ```php assertThat($foo, notSet("name")); ``` * `set` - check if instance property is set ```php $foo->name = "bar"; assertThat($foo, set("name")); ``` ### Numbers * `closeTo` - check value close to a range ```php assertThat(3, closeTo(3, 0.5)); ``` * `comparesEqualTo` - check with '==' ```php assertThat(2, comparesEqualTo(2)); ``` * `greaterThan` - check '>' ``` assertThat(2, greaterThan(1)); ``` * `greaterThanOrEqualTo` ```php assertThat(2, greaterThanOrEqualTo(2)); ``` * `atLeast` - The value is >= given value ```php assertThat(3, atLeast(2)); ``` * `lessThan` ```php assertThat(2, lessThan(3)); ``` * `lessThanOrEqualTo` ```php assertThat(2, lessThanOrEqualTo(3)); ``` * `atMost` - The value is <= given value ```php assertThat(2, atMost(3)); ``` ### String * `emptyString` - check for empty string ```php assertThat("", emptyString()); ``` * `isEmptyOrNullString` ```php assertThat(null, isEmptyOrNullString()); ``` * `nullOrEmptyString` ```php assertThat("", nullOrEmptyString()); ``` * `isNonEmptyString` ```php assertThat("foo", isNonEmptyString()); ``` * `nonEmptyString` ```php assertThat("foo", nonEmptyString()); ``` * `equalToIgnoringCase` ```php assertThat("Foo", equalToIgnoringCase("foo")); ``` * `equalToIgnoringWhiteSpace` ```php assertThat(" Foo ", equalToIgnoringWhiteSpace("Foo")); ``` * `matchesPattern` - matches with regex pattern ```php assertThat("foobarbaz", matchesPattern('/(foo)(bar)(baz)/')); ``` * `containsString` - check for substring ```php assertThat("foobar", containsString("foo")); ``` * `containsStringIgnoringCase` ```php assertThat("fooBar", containsStringIgnoringCase("bar")); ``` * `stringContainsInOrder` ```php assertThat("foo", stringContainsInOrder("foo")); ``` * `endsWith` - check string that ends with given value ```php assertThat("foo", endsWith("oo")); ``` * `startsWith` - check string that starts with given value ```php assertThat("bar", startsWith("ba")); ``` ### Type-checking * `arrayValue` - check array type ```php assertThat([], arrayValue()); ``` * `booleanValue` ```php assertThat(true, booleanValue()); ``` * `boolValue` - alias of booleanValue * `callableValue` - check if value is callable ```php $func = function () {}; assertThat($func, callableValue()); ``` * `doubleValue` ```php assertThat(3.14, doubleValue()); ``` * `floatValue` ```php assertThat(3.14, floatValue()); ``` * `integerValue` ```php assertThat(1, integerValue()); ``` * `intValue` - alias of `integerValue` * `numericValue` - check if value is numeric ```php assertThat("123", numericValue()); ``` * `objectValue` - check for object ```php $obj = new stdClass; assertThat($obj, objectValue()); ``` * `anObject` ```php assertThat($obj, anObject()); ``` * `resourceValue` - check resource type ```php $fp = fopen("/tmp/foo", "w+"); assertThat($fp, resourceValue()); ``` * `scalarValue` - check for scalar value ```php assertThat(1, scalarValue()); ``` * `stringValue` ```php assertThat("", stringValue()); ``` ### XML * `hasXPath` - check xml with a xpath ```php $xml = <<<XML <books> <book> <isbn>1</isbn> </book> <book> <isbn>2</isbn> </book> </books> XML; $doc = new DOMDocument; $doc->loadXML($xml); assertThat($doc, hasXPath("book", 2)); ``` PK j��\����c c 4 hamcrest-php/hamcrest/Hamcrest/StringDescription.phpnu �[��� <?php namespace Hamcrest; /* Copyright (c) 2009 hamcrest.org */ /** * A {@link Hamcrest\Description} that is stored as a string. */ class StringDescription extends BaseDescription { private $_out; public function __construct($out = '') { $this->_out = (string) $out; } public function __toString() { return $this->_out; } /** * Return the description of a {@link Hamcrest\SelfDescribing} object as a * String. * * @param \Hamcrest\SelfDescribing $selfDescribing * The object to be described. * * @return string * The description of the object. */ public static function toString(SelfDescribing $selfDescribing) { $self = new self(); return (string) $self->appendDescriptionOf($selfDescribing); } /** * Alias for {@link toString()}. */ public static function asString(SelfDescribing $selfDescribing) { return self::toString($selfDescribing); } // -- Protected Methods protected function append($str) { $this->_out .= $str; } } PK j��\GY��k k 2 hamcrest-php/hamcrest/Hamcrest/Core/IsAnything.phpnu �[��� <?php namespace Hamcrest\Core; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\BaseMatcher; use Hamcrest\Description; /** * A matcher that always returns <code>true</code>. */ class IsAnything extends BaseMatcher { private $_message; public function __construct($message = 'ANYTHING') { $this->_message = $message; } public function matches($item) { return true; } public function describeTo(Description $description) { $description->appendText($this->_message); } /** * This matcher always evaluates to true. * * @param string $description A meaningful string used when describing itself. * * @return \Hamcrest\Core\IsAnything * @factory */ public static function anything($description = 'ANYTHING') { return new self($description); } } PK j��\�ٞ� � 0 hamcrest-php/hamcrest/Hamcrest/Core/IsTypeOf.phpnu �[��� <?php namespace Hamcrest\Core; /* Copyright (c) 2010 hamcrest.org */ use Hamcrest\BaseMatcher; use Hamcrest\Description; /** * Tests whether the value has a built-in type. */ class IsTypeOf extends BaseMatcher { private $_theType; /** * Creates a new instance of IsTypeOf * * @param string $theType * The predicate evaluates to true for values with this built-in type. */ public function __construct($theType) { $this->_theType = strtolower($theType); } public function matches($item) { return strtolower(gettype($item)) == $this->_theType; } public function describeTo(Description $description) { $description->appendText(self::getTypeDescription($this->_theType)); } public function describeMismatch($item, Description $description) { if ($item === null) { $description->appendText('was null'); } else { $description->appendText('was ') ->appendText(self::getTypeDescription(strtolower(gettype($item)))) ->appendText(' ') ->appendValue($item) ; } } public static function getTypeDescription($type) { if ($type == 'null') { return 'null'; } return (strpos('aeiou', substr($type, 0, 1)) === false ? 'a ' : 'an ') . $type; } /** * Is the value a particular built-in type? * * @factory */ public static function typeOf($theType) { return new self($theType); } } PK j��\7���F F . hamcrest-php/hamcrest/Hamcrest/Core/IsSame.phpnu �[��� <?php namespace Hamcrest\Core; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\BaseMatcher; use Hamcrest\Description; /** * Is the value the same object as another value? * In PHP terms, does $a === $b? */ class IsSame extends BaseMatcher { private $_object; public function __construct($object) { $this->_object = $object; } public function matches($object) { return ($object === $this->_object) && ($this->_object === $object); } public function describeTo(Description $description) { $description->appendText('sameInstance(') ->appendValue($this->_object) ->appendText(')') ; } /** * Creates a new instance of IsSame. * * @param mixed $object * The predicate evaluates to true only when the argument is * this object. * * @return \Hamcrest\Core\IsSame * @factory */ public static function sameInstance($object) { return new self($object); } } PK j��\�� � 3 hamcrest-php/hamcrest/Hamcrest/Core/HasToString.phpnu �[��� <?php namespace Hamcrest\Core; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\Description; use Hamcrest\FeatureMatcher; use Hamcrest\Matcher; use Hamcrest\Util; /** * Matches if array size satisfies a nested matcher. */ class HasToString extends FeatureMatcher { public function __construct(Matcher $toStringMatcher) { parent::__construct( self::TYPE_OBJECT, null, $toStringMatcher, 'an object with toString()', 'toString()' ); } public function matchesSafelyWithDiagnosticDescription($actual, Description $mismatchDescription) { if (method_exists($actual, 'toString') || method_exists($actual, '__toString')) { return parent::matchesSafelyWithDiagnosticDescription($actual, $mismatchDescription); } return false; } protected function featureValueOf($actual) { if (method_exists($actual, 'toString')) { return $actual->toString(); } return (string) $actual; } /** * Does array size satisfy a given matcher? * * @factory */ public static function hasToString($matcher) { return new self(Util::wrapValueWithIsEqual($matcher)); } } PK j��\"'Q� � ; hamcrest-php/hamcrest/Hamcrest/Core/ShortcutCombination.phpnu �[��� <?php namespace Hamcrest\Core; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\BaseMatcher; use Hamcrest\Description; use Hamcrest\Util; abstract class ShortcutCombination extends BaseMatcher { /** * @var array<\Hamcrest\Matcher> */ private $_matchers; public function __construct(array $matchers) { Util::checkAllAreMatchers($matchers); $this->_matchers = $matchers; } protected function matchesWithShortcut($item, $shortcut) { /** @var $matcher \Hamcrest\Matcher */ foreach ($this->_matchers as $matcher) { if ($matcher->matches($item) == $shortcut) { return $shortcut; } } return !$shortcut; } public function describeToWithOperator(Description $description, $operator) { $description->appendList('(', ' ' . $operator . ' ', ')', $this->_matchers); } } PK j��\'� : : - hamcrest-php/hamcrest/Hamcrest/Core/Every.phpnu �[��� <?php namespace Hamcrest\Core; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\Description; use Hamcrest\Matcher; use Hamcrest\TypeSafeDiagnosingMatcher; class Every extends TypeSafeDiagnosingMatcher { private $_matcher; public function __construct(Matcher $matcher) { parent::__construct(self::TYPE_ARRAY); $this->_matcher = $matcher; } protected function matchesSafelyWithDiagnosticDescription($items, Description $mismatchDescription) { foreach ($items as $item) { if (!$this->_matcher->matches($item)) { $mismatchDescription->appendText('an item '); $this->_matcher->describeMismatch($item, $mismatchDescription); return false; } } return true; } public function describeTo(Description $description) { $description->appendText('every item is ')->appendDescriptionOf($this->_matcher); } /** * @param Matcher $itemMatcher * A matcher to apply to every element in an array. * * @return \Hamcrest\Core\Every * Evaluates to TRUE for a collection in which every item matches $itemMatcher * * @factory */ public static function everyItem(Matcher $itemMatcher) { return new self($itemMatcher); } } PK j��\��B{h h + hamcrest-php/hamcrest/Hamcrest/Core/Set.phpnu �[��� <?php namespace Hamcrest\Core; /* Copyright (c) 2010 hamcrest.org */ use Hamcrest\BaseMatcher; use Hamcrest\Description; /** * Tests if a value (class, object, or array) has a named property. * * For example: * <pre> * assertThat(array('a', 'b'), set('b')); * assertThat($foo, set('bar')); * assertThat('Server', notSet('defaultPort')); * </pre> * * @todo Replace $property with a matcher and iterate all property names. */ class Set extends BaseMatcher { private $_property; private $_not; public function __construct($property, $not = false) { $this->_property = $property; $this->_not = $not; } public function matches($item) { if ($item === null) { return false; } $property = $this->_property; if (is_array($item)) { $result = isset($item[$property]); } elseif (is_object($item)) { $result = isset($item->$property); } elseif (is_string($item)) { $result = isset($item::$$property); } else { throw new \InvalidArgumentException('Must pass an object, array, or class name'); } return $this->_not ? !$result : $result; } public function describeTo(Description $description) { $description->appendText($this->_not ? 'unset property ' : 'set property ')->appendText($this->_property); } public function describeMismatch($item, Description $description) { $value = ''; if (!$this->_not) { $description->appendText('was not set'); } else { $property = $this->_property; if (is_array($item)) { $value = $item[$property]; } elseif (is_object($item)) { $value = $item->$property; } elseif (is_string($item)) { $value = $item::$$property; } parent::describeMismatch($value, $description); } } /** * Matches if value (class, object, or array) has named $property. * * @factory */ public static function set($property) { return new self($property); } /** * Matches if value (class, object, or array) does not have named $property. * * @factory */ public static function notSet($property) { return new self($property, true); } } PK j��\�n�1� � 3 hamcrest-php/hamcrest/Hamcrest/Core/IsIdentical.phpnu �[��� <?php namespace Hamcrest\Core; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\Description; /** * The same as {@link Hamcrest\Core\IsSame} but with slightly different * semantics. */ class IsIdentical extends IsSame { private $_value; public function __construct($value) { parent::__construct($value); $this->_value = $value; } public function describeTo(Description $description) { $description->appendValue($this->_value); } /** * Tests of the value is identical to $value as tested by the "===" operator. * * @factory */ public static function identicalTo($value) { return new self($value); } } PK j��\+M{K K * hamcrest-php/hamcrest/Hamcrest/Core/Is.phpnu �[��� <?php namespace Hamcrest\Core; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\BaseMatcher; use Hamcrest\Description; use Hamcrest\Matcher; use Hamcrest\Util; /** * 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))) */ class Is extends BaseMatcher { private $_matcher; public function __construct(Matcher $matcher) { $this->_matcher = $matcher; } public function matches($arg) { return $this->_matcher->matches($arg); } public function describeTo(Description $description) { $description->appendText('is ')->appendDescriptionOf($this->_matcher); } public function describeMismatch($item, Description $mismatchDescription) { $this->_matcher->describeMismatch($item, $mismatchDescription); } /** * 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)); } } PK j��\F���� � 9 hamcrest-php/hamcrest/Hamcrest/Core/CombinableMatcher.phpnu �[��� <?php namespace Hamcrest\Core; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\BaseMatcher; use Hamcrest\Description; use Hamcrest\Matcher; class CombinableMatcher extends BaseMatcher { private $_matcher; public function __construct(Matcher $matcher) { $this->_matcher = $matcher; } public function matches($item) { return $this->_matcher->matches($item); } public function describeTo(Description $description) { $description->appendDescriptionOf($this->_matcher); } /** Diversion from Hamcrest-Java... Logical "and" not permitted */ public function andAlso(Matcher $other) { return new self(new AllOf($this->_templatedListWith($other))); } /** Diversion from Hamcrest-Java... Logical "or" not permitted */ public function orElse(Matcher $other) { return new self(new AnyOf($this->_templatedListWith($other))); } /** * This is useful for fluently combining matchers that must both pass. * For example: * <pre> * assertThat($string, both(containsString("a"))->andAlso(containsString("b"))); * </pre> * * @factory */ public static function both(Matcher $matcher) { return new self($matcher); } /** * This is useful for fluently combining matchers where either may pass, * for example: * <pre> * assertThat($string, either(containsString("a"))->orElse(containsString("b"))); * </pre> * * @factory */ public static function either(Matcher $matcher) { return new self($matcher); } // -- Private Methods private function _templatedListWith(Matcher $other) { return array($this->_matcher, $other); } } PK j��\3j<� � - hamcrest-php/hamcrest/Hamcrest/Core/AllOf.phpnu �[��� <?php namespace Hamcrest\Core; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\Description; use Hamcrest\DiagnosingMatcher; use Hamcrest\Util; /** * Calculates the logical conjunction of multiple matchers. Evaluation is * shortcut, so subsequent matchers are not called if an earlier matcher * returns <code>false</code>. */ class AllOf extends DiagnosingMatcher { private $_matchers; public function __construct(array $matchers) { Util::checkAllAreMatchers($matchers); $this->_matchers = $matchers; } public function matchesWithDiagnosticDescription($item, Description $mismatchDescription) { /** @var $matcher \Hamcrest\Matcher */ foreach ($this->_matchers as $matcher) { if (!$matcher->matches($item)) { $mismatchDescription->appendDescriptionOf($matcher)->appendText(' '); $matcher->describeMismatch($item, $mismatchDescription); return false; } } return true; } public function describeTo(Description $description) { $description->appendList('(', ' and ', ')', $this->_matchers); } /** * Evaluates to true only if ALL of the passed in matchers evaluate to true. * * @factory ... */ public static function allOf(/* args... */) { $args = func_get_args(); return new self(Util::createMatcherArray($args)); } } PK j��\�._�� � . hamcrest-php/hamcrest/Hamcrest/Core/IsNull.phpnu �[��� <?php namespace Hamcrest\Core; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\BaseMatcher; use Hamcrest\Description; /** * Is the value null? */ class IsNull extends BaseMatcher { private static $_INSTANCE; private static $_NOT_INSTANCE; public function matches($item) { return is_null($item); } public function describeTo(Description $description) { $description->appendText('null'); } /** * Matches if value is null. * * @factory */ public static function nullValue() { if (!self::$_INSTANCE) { self::$_INSTANCE = new self(); } return self::$_INSTANCE; } /** * Matches if value is not null. * * @factory */ public static function notNullValue() { if (!self::$_NOT_INSTANCE) { self::$_NOT_INSTANCE = IsNot::not(self::nullValue()); } return self::$_NOT_INSTANCE; } } PK j��\Zb.� � - hamcrest-php/hamcrest/Hamcrest/Core/AnyOf.phpnu �[��� <?php namespace Hamcrest\Core; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\Description; use Hamcrest\Util; /** * Calculates the logical disjunction of multiple matchers. Evaluation is * shortcut, so subsequent matchers are not called if an earlier matcher * returns <code>true</code>. */ class AnyOf extends ShortcutCombination { public function __construct(array $matchers) { parent::__construct($matchers); } public function matches($item) { return $this->matchesWithShortcut($item, true); } public function describeTo(Description $description) { $this->describeToWithOperator($description, 'or'); } /** * Evaluates to true if ANY of the passed in matchers evaluate to true. * * @factory ... */ public static function anyOf(/* args... */) { $args = func_get_args(); return new self(Util::createMatcherArray($args)); } /** * Evaluates to false if ANY of the passed in matchers evaluate to true. * * @factory ... */ public static function noneOf(/* args... */) { $args = func_get_args(); return IsNot::not( new self(Util::createMatcherArray($args)) ); } } PK j��\T��@9 9 3 hamcrest-php/hamcrest/Hamcrest/Core/DescribedAs.phpnu �[��� <?php namespace Hamcrest\Core; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\BaseMatcher; use Hamcrest\Description; use Hamcrest\Matcher; /** * Provides a custom description to another matcher. */ class DescribedAs extends BaseMatcher { private $_descriptionTemplate; private $_matcher; private $_values; const ARG_PATTERN = '/%([0-9]+)/'; public function __construct($descriptionTemplate, Matcher $matcher, array $values) { $this->_descriptionTemplate = $descriptionTemplate; $this->_matcher = $matcher; $this->_values = $values; } public function matches($item) { return $this->_matcher->matches($item); } public function describeTo(Description $description) { $textStart = 0; while (preg_match(self::ARG_PATTERN, $this->_descriptionTemplate, $matches, PREG_OFFSET_CAPTURE, $textStart)) { $text = $matches[0][0]; $index = $matches[1][0]; $offset = $matches[0][1]; $description->appendText(substr($this->_descriptionTemplate, $textStart, $offset - $textStart)); $description->appendValue($this->_values[$index]); $textStart = $offset + strlen($text); } if ($textStart < strlen($this->_descriptionTemplate)) { $description->appendText(substr($this->_descriptionTemplate, $textStart)); } } /** * Wraps an existing matcher and overrides the description when it fails. * * @factory ... */ public static function describedAs(/* $description, Hamcrest\Matcher $matcher, $values... */) { $args = func_get_args(); $description = array_shift($args); $matcher = array_shift($args); $values = $args; return new self($description, $matcher, $values); } } PK j��\�b �C C / hamcrest-php/hamcrest/Hamcrest/Core/IsEqual.phpnu �[��� <?php namespace Hamcrest\Core; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\BaseMatcher; use Hamcrest\Description; /** * Is the value equal to another value, as tested by the use of the "==" * comparison operator? */ class IsEqual extends BaseMatcher { private $_item; public function __construct($item) { $this->_item = $item; } public function matches($arg) { return (($arg == $this->_item) && ($this->_item == $arg)); } public function describeTo(Description $description) { $description->appendValue($this->_item); } /** * Is the value equal to another value, as tested by the use of the "==" * comparison operator? * * @factory */ public static function equalTo($item) { return new self($item); } } PK j��\&�w�l l >