Файловый менеджер - Редактировать - /var/www/vhosts/aviointeriors.dev1.mndrn.cloud/routes/update/hamcrest.tar
Назад
hamcrest-php/tests/bootstrap.php 0000644 00000000334 15233660706 0013037 0 ustar 00 <?php error_reporting(E_ALL | E_STRICT); require __DIR__ . '/../vendor/autoload.php'; if (defined('E_DEPRECATED')) { error_reporting(error_reporting() | E_DEPRECATED); } Hamcrest\Util::registerGlobalFunctions(); hamcrest-php/tests/phpunit.xml.dist 0000644 00000001153 15233660706 0013464 0 ustar 00 <phpunit backupGlobals="false" backupStaticAttributes="false" bootstrap="bootstrap.php" colors="false" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false"> <testsuites> <testsuite name="hamcrest-php"> <directory suffix="Test.php">.</directory> </testsuite> </testsuites> <filter> <whitelist addUncoveredFilesFromWhitelist="true"> <directory suffix=".php">../hamcrest</directory> </whitelist> </filter> </phpunit> hamcrest-php/tests/Hamcrest/Type/IsScalarTest.php 0000644 00000002162 15233660706 0016053 0 ustar 00 <?php namespace Hamcrest\Type; class IsScalarTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Type\IsScalar::scalarValue(); } public function testEvaluatesToTrueIfArgumentMatchesType() { assertThat(true, scalarValue()); assertThat(5, scalarValue()); assertThat(5.3, scalarValue()); assertThat('5', scalarValue()); } public function testEvaluatesToFalseIfArgumentDoesntMatchType() { assertThat(null, not(scalarValue())); assertThat(array(), not(scalarValue())); assertThat(array(5), not(scalarValue())); assertThat(tmpfile(), not(scalarValue())); assertThat(new \stdClass(), not(scalarValue())); } public function testHasAReadableDescription() { $this->assertDescription('a scalar', scalarValue()); } public function testDecribesActualTypeInMismatchMessage() { $this->assertMismatchDescription('was null', scalarValue(), null); $this->assertMismatchDescription('was an array ["foo"]', scalarValue(), array('foo')); } } hamcrest-php/tests/Hamcrest/Type/IsObjectTest.php 0000644 00000001611 15233660706 0016052 0 ustar 00 <?php namespace Hamcrest\Type; class IsObjectTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Type\IsObject::objectValue(); } public function testEvaluatesToTrueIfArgumentMatchesType() { assertThat(new \stdClass, objectValue()); } public function testEvaluatesToFalseIfArgumentDoesntMatchType() { assertThat(false, not(objectValue())); assertThat(5, not(objectValue())); assertThat('foo', not(objectValue())); } public function testHasAReadableDescription() { $this->assertDescription('an object', objectValue()); } public function testDecribesActualTypeInMismatchMessage() { $this->assertMismatchDescription('was null', objectValue(), null); $this->assertMismatchDescription('was a string "foo"', objectValue(), 'foo'); } } hamcrest-php/tests/Hamcrest/Type/IsStringTest.php 0000644 00000001657 15233660706 0016124 0 ustar 00 <?php namespace Hamcrest\Type; class IsStringTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Type\IsString::stringValue(); } public function testEvaluatesToTrueIfArgumentMatchesType() { assertThat('', stringValue()); assertThat("foo", stringValue()); } public function testEvaluatesToFalseIfArgumentDoesntMatchType() { assertThat(false, not(stringValue())); assertThat(5, not(stringValue())); assertThat(array(1, 2, 3), not(stringValue())); } public function testHasAReadableDescription() { $this->assertDescription('a string', stringValue()); } public function testDecribesActualTypeInMismatchMessage() { $this->assertMismatchDescription('was null', stringValue(), null); $this->assertMismatchDescription('was a double <5.2F>', stringValue(), 5.2); } } hamcrest-php/tests/Hamcrest/Type/IsResourceTest.php 0000644 00000001632 15233660706 0016436 0 ustar 00 <?php namespace Hamcrest\Type; class IsResourceTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Type\IsResource::resourceValue(); } public function testEvaluatesToTrueIfArgumentMatchesType() { assertThat(tmpfile(), resourceValue()); } public function testEvaluatesToFalseIfArgumentDoesntMatchType() { assertThat(false, not(resourceValue())); assertThat(5, not(resourceValue())); assertThat('foo', not(resourceValue())); } public function testHasAReadableDescription() { $this->assertDescription('a resource', resourceValue()); } public function testDecribesActualTypeInMismatchMessage() { $this->assertMismatchDescription('was null', resourceValue(), null); $this->assertMismatchDescription('was a string "foo"', resourceValue(), 'foo'); } } hamcrest-php/tests/Hamcrest/Type/IsBooleanTest.php 0000644 00000001667 15233660706 0016236 0 ustar 00 <?php namespace Hamcrest\Type; class IsBooleanTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Type\IsBoolean::booleanValue(); } public function testEvaluatesToTrueIfArgumentMatchesType() { assertThat(false, booleanValue()); assertThat(true, booleanValue()); } public function testEvaluatesToFalseIfArgumentDoesntMatchType() { assertThat(array(), not(booleanValue())); assertThat(5, not(booleanValue())); assertThat('foo', not(booleanValue())); } public function testHasAReadableDescription() { $this->assertDescription('a boolean', booleanValue()); } public function testDecribesActualTypeInMismatchMessage() { $this->assertMismatchDescription('was null', booleanValue(), null); $this->assertMismatchDescription('was a string "foo"', booleanValue(), 'foo'); } } hamcrest-php/tests/Hamcrest/Type/IsDoubleTest.php 0000644 00000001666 15233660706 0016070 0 ustar 00 <?php namespace Hamcrest\Type; class IsDoubleTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Type\IsDouble::doubleValue(); } public function testEvaluatesToTrueIfArgumentMatchesType() { assertThat((float) 5.2, floatValue()); assertThat((double) 5.3, doubleValue()); } public function testEvaluatesToFalseIfArgumentDoesntMatchType() { assertThat(false, not(doubleValue())); assertThat(5, not(doubleValue())); assertThat('foo', not(doubleValue())); } public function testHasAReadableDescription() { $this->assertDescription('a double', doubleValue()); } public function testDecribesActualTypeInMismatchMessage() { $this->assertMismatchDescription('was null', doubleValue(), null); $this->assertMismatchDescription('was a string "foo"', doubleValue(), 'foo'); } } hamcrest-php/tests/Hamcrest/Type/IsArrayTest.php 0000644 00000001651 15233660706 0015726 0 ustar 00 <?php namespace Hamcrest\Type; class IsArrayTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Type\IsArray::arrayValue(); } public function testEvaluatesToTrueIfArgumentMatchesType() { assertThat(array('5', 5), arrayValue()); assertThat(array(), arrayValue()); } public function testEvaluatesToFalseIfArgumentDoesntMatchType() { assertThat(false, not(arrayValue())); assertThat(5, not(arrayValue())); assertThat('foo', not(arrayValue())); } public function testHasAReadableDescription() { $this->assertDescription('an array', arrayValue()); } public function testDecribesActualTypeInMismatchMessage() { $this->assertMismatchDescription('was null', arrayValue(), null); $this->assertMismatchDescription('was a string "foo"', arrayValue(), 'foo'); } } hamcrest-php/tests/Hamcrest/Type/IsNumericTest.php 0000644 00000003470 15233660706 0016253 0 ustar 00 <?php namespace Hamcrest\Type; class IsNumericTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Type\IsNumeric::numericValue(); } public function testEvaluatesToTrueIfArgumentMatchesType() { assertThat(5, numericValue()); assertThat(0, numericValue()); assertThat(-5, numericValue()); assertThat(5.3, numericValue()); assertThat(0.53, numericValue()); assertThat(-5.3, numericValue()); assertThat('5', numericValue()); assertThat('0', numericValue()); assertThat('-5', numericValue()); assertThat('5.3', numericValue()); assertThat('5e+3', numericValue()); assertThat('0.053e-2', numericValue()); assertThat('-53.253e+25', numericValue()); assertThat('+53.253e+25', numericValue()); assertThat(0x4F2a04, numericValue()); assertThat('0x4F2a04', numericValue()); } public function testEvaluatesToFalseIfArgumentDoesntMatchType() { assertThat(false, not(numericValue())); assertThat('foo', not(numericValue())); assertThat('foo5', not(numericValue())); assertThat('5foo', not(numericValue())); assertThat('0x42A04G', not(numericValue())); // G is not in the hexadecimal range. assertThat('1x42A04', not(numericValue())); // 1x is not a valid hexadecimal sequence. assertThat('0x', not(numericValue())); } public function testHasAReadableDescription() { $this->assertDescription('a number', numericValue()); } public function testDecribesActualTypeInMismatchMessage() { $this->assertMismatchDescription('was null', numericValue(), null); $this->assertMismatchDescription('was a string "foo"', numericValue(), 'foo'); } } hamcrest-php/tests/Hamcrest/Type/IsIntegerTest.php 0000644 00000001731 15233660706 0016244 0 ustar 00 <?php namespace Hamcrest\Type; class IsIntegerTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Type\IsInteger::integerValue(); } public function testEvaluatesToTrueIfArgumentMatchesType() { assertThat(5, integerValue()); assertThat(0, integerValue()); assertThat(-5, integerValue()); } public function testEvaluatesToFalseIfArgumentDoesntMatchType() { assertThat(false, not(integerValue())); assertThat(5.2, not(integerValue())); assertThat('foo', not(integerValue())); } public function testHasAReadableDescription() { $this->assertDescription('an integer', integerValue()); } public function testDecribesActualTypeInMismatchMessage() { $this->assertMismatchDescription('was null', integerValue(), null); $this->assertMismatchDescription('was a string "foo"', integerValue(), 'foo'); } } hamcrest-php/tests/Hamcrest/Type/IsCallableTest.php 0000644 00000005377 15233660706 0016360 0 ustar 00 <?php namespace Hamcrest\Type; class IsCallableTest extends \Hamcrest\AbstractMatcherTest { public static function callableFunction() { } public function __invoke() { } protected function createMatcher() { return \Hamcrest\Type\IsCallable::callableValue(); } public function testEvaluatesToTrueIfArgumentIsFunctionName() { assertThat('preg_match', callableValue()); } public function testEvaluatesToTrueIfArgumentIsStaticMethodCallback() { assertThat( array('Hamcrest\Type\IsCallableTest', 'callableFunction'), callableValue() ); } public function testEvaluatesToTrueIfArgumentIsInstanceMethodCallback() { assertThat( array($this, 'testEvaluatesToTrueIfArgumentIsInstanceMethodCallback'), callableValue() ); } public function testEvaluatesToTrueIfArgumentIsClosure() { if (!version_compare(PHP_VERSION, '5.3', '>=')) { $this->markTestSkipped('Closures require php 5.3'); } eval('assertThat(function () {}, callableValue());'); } public function testEvaluatesToTrueIfArgumentImplementsInvoke() { if (!version_compare(PHP_VERSION, '5.3', '>=')) { $this->markTestSkipped('Magic method __invoke() requires php 5.3'); } assertThat($this, callableValue()); } public function testEvaluatesToFalseIfArgumentIsInvalidFunctionName() { if (function_exists('not_a_Hamcrest_function')) { $this->markTestSkipped('Function "not_a_Hamcrest_function" must not exist'); } assertThat('not_a_Hamcrest_function', not(callableValue())); } public function testEvaluatesToFalseIfArgumentIsInvalidStaticMethodCallback() { assertThat( array('Hamcrest\Type\IsCallableTest', 'noMethod'), not(callableValue()) ); } public function testEvaluatesToFalseIfArgumentIsInvalidInstanceMethodCallback() { assertThat(array($this, 'noMethod'), not(callableValue())); } public function testEvaluatesToFalseIfArgumentDoesntImplementInvoke() { assertThat(new \stdClass(), not(callableValue())); } public function testEvaluatesToFalseIfArgumentDoesntMatchType() { assertThat(false, not(callableValue())); assertThat(5.2, not(callableValue())); } public function testHasAReadableDescription() { $this->assertDescription('a callable', callableValue()); } public function testDecribesActualTypeInMismatchMessage() { $this->assertMismatchDescription( 'was a string "invalid-function"', callableValue(), 'invalid-function' ); } } hamcrest-php/tests/Hamcrest/Core/SampleSubClass.php 0000644 00000000140 15233660706 0016334 0 ustar 00 <?php namespace Hamcrest\Core; class SampleSubClass extends \Hamcrest\Core\SampleBaseClass { } hamcrest-php/tests/Hamcrest/Core/IsTest.php 0000644 00000002122 15233660706 0014670 0 ustar 00 <?php namespace Hamcrest\Core; class IsTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Core\Is::is('something'); } public function testJustMatchesTheSameWayTheUnderylingMatcherDoes() { $this->assertMatches(is(equalTo(true)), true, 'should match'); $this->assertMatches(is(equalTo(false)), false, 'should match'); $this->assertDoesNotMatch(is(equalTo(true)), false, 'should not match'); $this->assertDoesNotMatch(is(equalTo(false)), true, 'should not match'); } public function testGeneratesIsPrefixInDescription() { $this->assertDescription('is <true>', is(equalTo(true))); } public function testProvidesConvenientShortcutForIsEqualTo() { $this->assertMatches(is('A'), 'A', 'should match'); $this->assertMatches(is('B'), 'B', 'should match'); $this->assertDoesNotMatch(is('A'), 'B', 'should not match'); $this->assertDoesNotMatch(is('B'), 'A', 'should not match'); $this->assertDescription('is "A"', is('A')); } } hamcrest-php/tests/Hamcrest/Core/EveryTest.php 0000644 00000001502 15233660706 0015410 0 ustar 00 <?php namespace Hamcrest\Core; class EveryTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Core\Every::everyItem(anything()); } public function testIsTrueWhenEveryValueMatches() { assertThat(array('AaA', 'BaB', 'CaC'), everyItem(containsString('a'))); assertThat(array('AbA', 'BbB', 'CbC'), not(everyItem(containsString('a')))); } public function testIsAlwaysTrueForEmptyLists() { assertThat(array(), everyItem(containsString('a'))); } public function testDescribesItself() { $each = everyItem(containsString('a')); $this->assertEquals('every item is a string containing "a"', (string) $each); $this->assertMismatchDescription('an item was "BbB"', $each, array('BbB')); } } hamcrest-php/tests/Hamcrest/Core/IsCollectionContainingTest.php 0000644 00000005106 15233660706 0020723 0 ustar 00 <?php namespace Hamcrest\Core; class IsCollectionContainingTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Core\IsCollectionContaining::hasItem(equalTo('irrelevant')); } public function testMatchesACollectionThatContainsAnElementMatchingTheGivenMatcher() { $itemMatcher = hasItem(equalTo('a')); $this->assertMatches( $itemMatcher, array('a', 'b', 'c'), "should match list that contains 'a'" ); } public function testDoesNotMatchCollectionThatDoesntContainAnElementMatchingTheGivenMatcher() { $matcher1 = hasItem(equalTo('a')); $this->assertDoesNotMatch( $matcher1, array('b', 'c'), "should not match list that doesn't contain 'a'" ); $matcher2 = hasItem(equalTo('a')); $this->assertDoesNotMatch( $matcher2, array(), 'should not match the empty list' ); } public function testDoesNotMatchNull() { $this->assertDoesNotMatch( hasItem(equalTo('a')), null, 'should not match null' ); } public function testHasAReadableDescription() { $this->assertDescription('a collection containing "a"', hasItem(equalTo('a'))); } public function testMatchesAllItemsInCollection() { $matcher1 = hasItems(equalTo('a'), equalTo('b'), equalTo('c')); $this->assertMatches( $matcher1, array('a', 'b', 'c'), 'should match list containing all items' ); $matcher2 = hasItems('a', 'b', 'c'); $this->assertMatches( $matcher2, array('a', 'b', 'c'), 'should match list containing all items (without matchers)' ); $matcher3 = hasItems(equalTo('a'), equalTo('b'), equalTo('c')); $this->assertMatches( $matcher3, array('c', 'b', 'a'), 'should match list containing all items in any order' ); $matcher4 = hasItems(equalTo('a'), equalTo('b'), equalTo('c')); $this->assertMatches( $matcher4, array('e', 'c', 'b', 'a', 'd'), 'should match list containing all items plus others' ); $matcher5 = hasItems(equalTo('a'), equalTo('b'), equalTo('c')); $this->assertDoesNotMatch( $matcher5, array('e', 'c', 'b', 'd'), // 'a' missing 'should not match list unless it contains all items' ); } } hamcrest-php/tests/Hamcrest/Core/IsAnythingTest.php 0000644 00000001254 15233660706 0016377 0 ustar 00 <?php namespace Hamcrest\Core; class IsAnythingTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Core\IsAnything::anything(); } public function testAlwaysEvaluatesToTrue() { assertThat(null, anything()); assertThat(new \stdClass(), anything()); assertThat('hi', anything()); } public function testHasUsefulDefaultDescription() { $this->assertDescription('ANYTHING', anything()); } public function testCanOverrideDescription() { $description = 'description'; $this->assertDescription($description, anything($description)); } } hamcrest-php/tests/Hamcrest/Core/HasToStringTest.php 0000644 00000004476 15233660706 0016540 0 ustar 00 <?php namespace Hamcrest\Core; class PhpForm { public function __toString() { return 'php'; } } class JavaForm { public function toString() { return 'java'; } } class BothForms { public function __toString() { return 'php'; } public function toString() { return 'java'; } } class HasToStringTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Core\HasToString::hasToString('foo'); } public function testMatchesWhenToStringMatches() { $this->assertMatches( hasToString(equalTo('php')), new \Hamcrest\Core\PhpForm(), 'correct __toString' ); $this->assertMatches( hasToString(equalTo('java')), new \Hamcrest\Core\JavaForm(), 'correct toString' ); } public function testPicksJavaOverPhpToString() { $this->assertMatches( hasToString(equalTo('java')), new \Hamcrest\Core\BothForms(), 'correct toString' ); } public function testDoesNotMatchWhenToStringDoesNotMatch() { $this->assertDoesNotMatch( hasToString(equalTo('mismatch')), new \Hamcrest\Core\PhpForm(), 'incorrect __toString' ); $this->assertDoesNotMatch( hasToString(equalTo('mismatch')), new \Hamcrest\Core\JavaForm(), 'incorrect toString' ); $this->assertDoesNotMatch( hasToString(equalTo('mismatch')), new \Hamcrest\Core\BothForms(), 'incorrect __toString' ); } public function testDoesNotMatchNull() { $this->assertDoesNotMatch( hasToString(equalTo('a')), null, 'should not match null' ); } public function testProvidesConvenientShortcutForTraversableWithSizeEqualTo() { $this->assertMatches( hasToString(equalTo('php')), new \Hamcrest\Core\PhpForm(), 'correct __toString' ); } public function testHasAReadableDescription() { $this->assertDescription( 'an object with toString() "php"', hasToString(equalTo('php')) ); } } hamcrest-php/tests/Hamcrest/Core/IsIdenticalTest.php 0000644 00000001401 15233660706 0016504 0 ustar 00 <?php namespace Hamcrest\Core; class IsIdenticalTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Core\IsIdentical::identicalTo('irrelevant'); } public function testEvaluatesToTrueIfArgumentIsReferenceToASpecifiedObject() { $o1 = new \stdClass(); $o2 = new \stdClass(); assertThat($o1, identicalTo($o1)); assertThat($o2, not(identicalTo($o1))); } public function testReturnsReadableDescriptionFromToString() { $this->assertDescription('"ARG"', identicalTo('ARG')); } public function testReturnsReadableDescriptionFromToStringWhenInitialisedWithNull() { $this->assertDescription('null', identicalTo(null)); } } hamcrest-php/tests/Hamcrest/Core/IsInstanceOfTest.php 0000644 00000003456 15233660706 0016655 0 ustar 00 <?php namespace Hamcrest\Core; class IsInstanceOfTest extends \Hamcrest\AbstractMatcherTest { private $_baseClassInstance; private $_subClassInstance; protected function setUp() { $this->_baseClassInstance = new \Hamcrest\Core\SampleBaseClass('good'); $this->_subClassInstance = new \Hamcrest\Core\SampleSubClass('good'); } protected function createMatcher() { return \Hamcrest\Core\IsInstanceOf::anInstanceOf('stdClass'); } public function testEvaluatesToTrueIfArgumentIsInstanceOfASpecificClass() { assertThat($this->_baseClassInstance, anInstanceOf('Hamcrest\Core\SampleBaseClass')); assertThat($this->_subClassInstance, anInstanceOf('Hamcrest\Core\SampleSubClass')); assertThat(null, not(anInstanceOf('Hamcrest\Core\SampleBaseClass'))); assertThat(new \stdClass(), not(anInstanceOf('Hamcrest\Core\SampleBaseClass'))); } public function testEvaluatesToFalseIfArgumentIsNotAnObject() { assertThat(null, not(anInstanceOf('Hamcrest\Core\SampleBaseClass'))); assertThat(false, not(anInstanceOf('Hamcrest\Core\SampleBaseClass'))); assertThat(5, not(anInstanceOf('Hamcrest\Core\SampleBaseClass'))); assertThat('foo', not(anInstanceOf('Hamcrest\Core\SampleBaseClass'))); assertThat(array(1, 2, 3), not(anInstanceOf('Hamcrest\Core\SampleBaseClass'))); } public function testHasAReadableDescription() { $this->assertDescription('an instance of stdClass', anInstanceOf('stdClass')); } public function testDecribesActualClassInMismatchMessage() { $this->assertMismatchDescription( '[Hamcrest\Core\SampleBaseClass] <good>', anInstanceOf('Hamcrest\Core\SampleSubClass'), $this->_baseClassInstance ); } } hamcrest-php/tests/Hamcrest/Core/AllOfTest.php 0000644 00000003033 15233660706 0015314 0 ustar 00 <?php namespace Hamcrest\Core; class AllOfTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Core\AllOf::allOf('irrelevant'); } public function testEvaluatesToTheLogicalConjunctionOfTwoOtherMatchers() { assertThat('good', allOf('good', 'good')); assertThat('good', not(allOf('bad', 'good'))); assertThat('good', not(allOf('good', 'bad'))); assertThat('good', not(allOf('bad', 'bad'))); } public function testEvaluatesToTheLogicalConjunctionOfManyOtherMatchers() { assertThat('good', allOf('good', 'good', 'good', 'good', 'good')); assertThat('good', not(allOf('good', endsWith('d'), 'bad', 'good', 'good'))); } public function testSupportsMixedTypes() { $all = allOf( equalTo(new \Hamcrest\Core\SampleBaseClass('good')), equalTo(new \Hamcrest\Core\SampleBaseClass('good')), equalTo(new \Hamcrest\Core\SampleSubClass('ugly')) ); $negated = not($all); assertThat(new \Hamcrest\Core\SampleSubClass('good'), $negated); } public function testHasAReadableDescription() { $this->assertDescription( '("good" and "bad" and "ugly")', allOf('good', 'bad', 'ugly') ); } public function testMismatchDescriptionDescribesFirstFailingMatch() { $this->assertMismatchDescription( '"good" was "bad"', allOf('bad', 'good'), 'bad' ); } } hamcrest-php/tests/Hamcrest/Core/IsNullTest.php 0000644 00000000744 15233660706 0015533 0 ustar 00 <?php namespace Hamcrest\Core; class IsNullTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Core\IsNull::nullValue(); } public function testEvaluatesToTrueIfArgumentIsNull() { assertThat(null, nullValue()); assertThat(self::ANY_NON_NULL_ARGUMENT, not(nullValue())); assertThat(self::ANY_NON_NULL_ARGUMENT, notNullValue()); assertThat(null, not(notNullValue())); } } hamcrest-php/tests/Hamcrest/Core/IsSameTest.php 0000644 00000001433 15233660706 0015502 0 ustar 00 <?php namespace Hamcrest\Core; class IsSameTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Core\IsSame::sameInstance(new \stdClass()); } public function testEvaluatesToTrueIfArgumentIsReferenceToASpecifiedObject() { $o1 = new \stdClass(); $o2 = new \stdClass(); assertThat($o1, sameInstance($o1)); assertThat($o2, not(sameInstance($o1))); } public function testReturnsReadableDescriptionFromToString() { $this->assertDescription('sameInstance("ARG")', sameInstance('ARG')); } public function testReturnsReadableDescriptionFromToStringWhenInitialisedWithNull() { $this->assertDescription('sameInstance(null)', sameInstance(null)); } } hamcrest-php/tests/Hamcrest/Core/IsTypeOfTest.php 0000644 00000002711 15233660706 0016023 0 ustar 00 <?php namespace Hamcrest\Core; class IsTypeOfTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Core\IsTypeOf::typeOf('integer'); } public function testEvaluatesToTrueIfArgumentMatchesType() { assertThat(array('5', 5), typeOf('array')); assertThat(false, typeOf('boolean')); assertThat(5, typeOf('integer')); assertThat(5.2, typeOf('double')); assertThat(null, typeOf('null')); assertThat(tmpfile(), typeOf('resource')); assertThat('a string', typeOf('string')); } public function testEvaluatesToFalseIfArgumentDoesntMatchType() { assertThat(false, not(typeOf('array'))); assertThat(array('5', 5), not(typeOf('boolean'))); assertThat(5.2, not(typeOf('integer'))); assertThat(5, not(typeOf('double'))); assertThat(false, not(typeOf('null'))); assertThat('a string', not(typeOf('resource'))); assertThat(tmpfile(), not(typeOf('string'))); } public function testHasAReadableDescription() { $this->assertDescription('a double', typeOf('double')); $this->assertDescription('an integer', typeOf('integer')); } public function testDecribesActualTypeInMismatchMessage() { $this->assertMismatchDescription('was null', typeOf('boolean'), null); $this->assertMismatchDescription('was an integer <5>', typeOf('float'), 5); } } hamcrest-php/tests/Hamcrest/Core/IsEqualTest.php 0000644 00000005316 15233660706 0015670 0 ustar 00 <?php namespace Hamcrest\Core; class DummyToStringClass { private $_arg; public function __construct($arg) { $this->_arg = $arg; } public function __toString() { return $this->_arg; } } class IsEqualTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Core\IsEqual::equalTo('irrelevant'); } public function testComparesObjectsUsingEqualityOperator() { assertThat("hi", equalTo("hi")); assertThat("bye", not(equalTo("hi"))); assertThat(1, equalTo(1)); assertThat(1, not(equalTo(2))); assertThat("2", equalTo(2)); } public function testCanCompareNullValues() { assertThat(null, equalTo(null)); assertThat(null, not(equalTo('hi'))); assertThat('hi', not(equalTo(null))); } public function testComparesTheElementsOfAnArray() { $s1 = array('a', 'b'); $s2 = array('a', 'b'); $s3 = array('c', 'd'); $s4 = array('a', 'b', 'c', 'd'); assertThat($s1, equalTo($s1)); assertThat($s2, equalTo($s1)); assertThat($s3, not(equalTo($s1))); assertThat($s4, not(equalTo($s1))); } public function testComparesTheElementsOfAnArrayOfPrimitiveTypes() { $i1 = array(1, 2); $i2 = array(1, 2); $i3 = array(3, 4); $i4 = array(1, 2, 3, 4); assertThat($i1, equalTo($i1)); assertThat($i2, equalTo($i1)); assertThat($i3, not(equalTo($i1))); assertThat($i4, not(equalTo($i1))); } public function testRecursivelyTestsElementsOfArrays() { $i1 = array(array(1, 2), array(3, 4)); $i2 = array(array(1, 2), array(3, 4)); $i3 = array(array(5, 6), array(7, 8)); $i4 = array(array(1, 2, 3, 4), array(3, 4)); assertThat($i1, equalTo($i1)); assertThat($i2, equalTo($i1)); assertThat($i3, not(equalTo($i1))); assertThat($i4, not(equalTo($i1))); } public function testIncludesTheResultOfCallingToStringOnItsArgumentInTheDescription() { $argumentDescription = 'ARGUMENT DESCRIPTION'; $argument = new \Hamcrest\Core\DummyToStringClass($argumentDescription); $this->assertDescription('<' . $argumentDescription . '>', equalTo($argument)); } public function testReturnsAnObviousDescriptionIfCreatedWithANestedMatcherByMistake() { $innerMatcher = equalTo('NestedMatcher'); $this->assertDescription('<' . (string) $innerMatcher . '>', equalTo($innerMatcher)); } public function testReturnsGoodDescriptionIfCreatedWithNullReference() { $this->assertDescription('null', equalTo(null)); } } hamcrest-php/tests/Hamcrest/Core/CombinableMatcherTest.php 0000644 00000003355 15233660706 0017665 0 ustar 00 <?php namespace Hamcrest\Core; class CombinableMatcherTest extends \Hamcrest\AbstractMatcherTest { private $_either_3_or_4; private $_not_3_and_not_4; protected function setUp() { $this->_either_3_or_4 = \Hamcrest\Core\CombinableMatcher::either(equalTo(3))->orElse(equalTo(4)); $this->_not_3_and_not_4 = \Hamcrest\Core\CombinableMatcher::both(not(equalTo(3)))->andAlso(not(equalTo(4))); } protected function createMatcher() { return \Hamcrest\Core\CombinableMatcher::either(equalTo('irrelevant'))->orElse(equalTo('ignored')); } public function testBothAcceptsAndRejects() { assertThat(2, $this->_not_3_and_not_4); assertThat(3, not($this->_not_3_and_not_4)); } public function testAcceptsAndRejectsThreeAnds() { $tripleAnd = $this->_not_3_and_not_4->andAlso(equalTo(2)); assertThat(2, $tripleAnd); assertThat(3, not($tripleAnd)); } public function testBothDescribesItself() { $this->assertEquals('(not <3> and not <4>)', (string) $this->_not_3_and_not_4); $this->assertMismatchDescription('was <3>', $this->_not_3_and_not_4, 3); } public function testEitherAcceptsAndRejects() { assertThat(3, $this->_either_3_or_4); assertThat(6, not($this->_either_3_or_4)); } public function testAcceptsAndRejectsThreeOrs() { $orTriple = $this->_either_3_or_4->orElse(greaterThan(10)); assertThat(11, $orTriple); assertThat(9, not($orTriple)); } public function testEitherDescribesItself() { $this->assertEquals('(<3> or <4>)', (string) $this->_either_3_or_4); $this->assertMismatchDescription('was <6>', $this->_either_3_or_4, 6); } } hamcrest-php/tests/Hamcrest/Core/DescribedAsTest.php 0000644 00000002057 15233660706 0016474 0 ustar 00 <?php namespace Hamcrest\Core; class DescribedAsTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Core\DescribedAs::describedAs('irrelevant', anything()); } public function testOverridesDescriptionOfOtherMatcherWithThatPassedToConstructor() { $m1 = describedAs('m1 description', anything()); $m2 = describedAs('m2 description', not(anything())); $this->assertDescription('m1 description', $m1); $this->assertDescription('m2 description', $m2); } public function testAppendsValuesToDescription() { $m = describedAs('value 1 = %0, value 2 = %1', anything(), 33, 97); $this->assertDescription('value 1 = <33>, value 2 = <97>', $m); } public function testDelegatesMatchingToAnotherMatcher() { $m1 = describedAs('irrelevant', anything()); $m2 = describedAs('irrelevant', not(anything())); $this->assertTrue($m1->matches(new \stdClass())); $this->assertFalse($m2->matches('hi')); } } hamcrest-php/tests/Hamcrest/Core/AnyOfTest.php 0000644 00000004637 15233660706 0015346 0 ustar 00 <?php namespace Hamcrest\Core; class AnyOfTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Core\AnyOf::anyOf('irrelevant'); } public function testAnyOfEvaluatesToTheLogicalDisjunctionOfTwoOtherMatchers() { assertThat('good', anyOf('bad', 'good')); assertThat('good', anyOf('good', 'good')); assertThat('good', anyOf('good', 'bad')); assertThat('good', not(anyOf('bad', startsWith('b')))); } public function testAnyOfEvaluatesToTheLogicalDisjunctionOfManyOtherMatchers() { assertThat('good', anyOf('bad', 'good', 'bad', 'bad', 'bad')); assertThat('good', not(anyOf('bad', 'bad', 'bad', 'bad', 'bad'))); } public function testAnyOfSupportsMixedTypes() { $combined = anyOf( equalTo(new \Hamcrest\Core\SampleBaseClass('good')), equalTo(new \Hamcrest\Core\SampleBaseClass('ugly')), equalTo(new \Hamcrest\Core\SampleSubClass('good')) ); assertThat(new \Hamcrest\Core\SampleSubClass('good'), $combined); } public function testAnyOfHasAReadableDescription() { $this->assertDescription( '("good" or "bad" or "ugly")', anyOf('good', 'bad', 'ugly') ); } public function testNoneOfEvaluatesToTheLogicalDisjunctionOfTwoOtherMatchers() { assertThat('good', not(noneOf('bad', 'good'))); assertThat('good', not(noneOf('good', 'good'))); assertThat('good', not(noneOf('good', 'bad'))); assertThat('good', noneOf('bad', startsWith('b'))); } public function testNoneOfEvaluatesToTheLogicalDisjunctionOfManyOtherMatchers() { assertThat('good', not(noneOf('bad', 'good', 'bad', 'bad', 'bad'))); assertThat('good', noneOf('bad', 'bad', 'bad', 'bad', 'bad')); } public function testNoneOfSupportsMixedTypes() { $combined = noneOf( equalTo(new \Hamcrest\Core\SampleBaseClass('good')), equalTo(new \Hamcrest\Core\SampleBaseClass('ugly')), equalTo(new \Hamcrest\Core\SampleSubClass('good')) ); assertThat(new \Hamcrest\Core\SampleSubClass('bad'), $combined); } public function testNoneOfHasAReadableDescription() { $this->assertDescription( 'not ("good" or "bad" or "ugly")', noneOf('good', 'bad', 'ugly') ); } } hamcrest-php/tests/Hamcrest/Core/SetTest.php 0000644 00000006176 15233660706 0015065 0 ustar 00 <?php namespace Hamcrest\Core; class SetTest extends \Hamcrest\AbstractMatcherTest { public static $_classProperty; public $_instanceProperty; protected function setUp() { self::$_classProperty = null; unset($this->_instanceProperty); } protected function createMatcher() { return \Hamcrest\Core\Set::set('property_name'); } public function testEvaluatesToTrueIfArrayPropertyIsSet() { assertThat(array('foo' => 'bar'), set('foo')); } public function testNegatedEvaluatesToFalseIfArrayPropertyIsSet() { assertThat(array('foo' => 'bar'), not(notSet('foo'))); } public function testEvaluatesToTrueIfClassPropertyIsSet() { self::$_classProperty = 'bar'; assertThat('Hamcrest\Core\SetTest', set('_classProperty')); } public function testNegatedEvaluatesToFalseIfClassPropertyIsSet() { self::$_classProperty = 'bar'; assertThat('Hamcrest\Core\SetTest', not(notSet('_classProperty'))); } public function testEvaluatesToTrueIfObjectPropertyIsSet() { $this->_instanceProperty = 'bar'; assertThat($this, set('_instanceProperty')); } public function testNegatedEvaluatesToFalseIfObjectPropertyIsSet() { $this->_instanceProperty = 'bar'; assertThat($this, not(notSet('_instanceProperty'))); } public function testEvaluatesToFalseIfArrayPropertyIsNotSet() { assertThat(array('foo' => 'bar'), not(set('baz'))); } public function testNegatedEvaluatesToTrueIfArrayPropertyIsNotSet() { assertThat(array('foo' => 'bar'), notSet('baz')); } public function testEvaluatesToFalseIfClassPropertyIsNotSet() { assertThat('Hamcrest\Core\SetTest', not(set('_classProperty'))); } public function testNegatedEvaluatesToTrueIfClassPropertyIsNotSet() { assertThat('Hamcrest\Core\SetTest', notSet('_classProperty')); } public function testEvaluatesToFalseIfObjectPropertyIsNotSet() { assertThat($this, not(set('_instanceProperty'))); } public function testNegatedEvaluatesToTrueIfObjectPropertyIsNotSet() { assertThat($this, notSet('_instanceProperty')); } public function testHasAReadableDescription() { $this->assertDescription('set property foo', set('foo')); $this->assertDescription('unset property bar', notSet('bar')); } public function testDecribesPropertySettingInMismatchMessage() { $this->assertMismatchDescription( 'was not set', set('bar'), array('foo' => 'bar') ); $this->assertMismatchDescription( 'was "bar"', notSet('foo'), array('foo' => 'bar') ); self::$_classProperty = 'bar'; $this->assertMismatchDescription( 'was "bar"', notSet('_classProperty'), 'Hamcrest\Core\SetTest' ); $this->_instanceProperty = 'bar'; $this->assertMismatchDescription( 'was "bar"', notSet('_instanceProperty'), $this ); } } hamcrest-php/tests/Hamcrest/Core/IsNotTest.php 0000644 00000001746 15233660706 0015364 0 ustar 00 <?php namespace Hamcrest\Core; class IsNotTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Core\IsNot::not('something'); } public function testEvaluatesToTheTheLogicalNegationOfAnotherMatcher() { $this->assertMatches(not(equalTo('A')), 'B', 'should match'); $this->assertDoesNotMatch(not(equalTo('B')), 'B', 'should not match'); } public function testProvidesConvenientShortcutForNotEqualTo() { $this->assertMatches(not('A'), 'B', 'should match'); $this->assertMatches(not('B'), 'A', 'should match'); $this->assertDoesNotMatch(not('A'), 'A', 'should not match'); $this->assertDoesNotMatch(not('B'), 'B', 'should not match'); } public function testUsesDescriptionOfNegatedMatcherWithPrefix() { $this->assertDescription('not a value greater than <2>', not(greaterThan(2))); $this->assertDescription('not "A"', not('A')); } } hamcrest-php/tests/Hamcrest/Core/SampleBaseClass.php 0000644 00000000347 15233660706 0016466 0 ustar 00 <?php namespace Hamcrest\Core; class SampleBaseClass { private $_arg; public function __construct($arg) { $this->_arg = $arg; } public function __toString() { return $this->_arg; } } hamcrest-php/tests/Hamcrest/Array/IsArrayContainingInOrderTest.php 0000644 00000003031 15233660706 0021352 0 ustar 00 <?php namespace Hamcrest\Arrays; use Hamcrest\AbstractMatcherTest; class IsArrayContainingInOrderTest extends AbstractMatcherTest { protected function createMatcher() { return IsArrayContainingInOrder::arrayContaining(array(1, 2)); } public function testHasAReadableDescription() { $this->assertDescription('[<1>, <2>]', arrayContaining(array(1, 2))); } public function testMatchesItemsInOrder() { $this->assertMatches(arrayContaining(array(1, 2, 3)), array(1, 2, 3), 'in order'); $this->assertMatches(arrayContaining(array(1)), array(1), 'single'); } public function testAppliesMatchersInOrder() { $this->assertMatches( arrayContaining(array(1, 2, 3)), array(1, 2, 3), 'in order' ); $this->assertMatches(arrayContaining(array(1)), array(1), 'single'); } public function testMismatchesItemsInAnyOrder() { if (defined('HHVM_VERSION')) { $this->markTestSkipped('Broken on HHVM.'); } $matcher = arrayContaining(array(1, 2, 3)); $this->assertMismatchDescription('was null', $matcher, null); $this->assertMismatchDescription('No item matched: <1>', $matcher, array()); $this->assertMismatchDescription('No item matched: <2>', $matcher, array(1)); $this->assertMismatchDescription('item with key 0: was <4>', $matcher, array(4, 3, 2, 1)); $this->assertMismatchDescription('item with key 2: was <4>', $matcher, array(1, 2, 4)); } } hamcrest-php/tests/Hamcrest/Array/IsArrayContainingKeyValuePairTest.php 0000644 00000002112 15233660706 0022350 0 ustar 00 <?php namespace Hamcrest\Arrays; use Hamcrest\AbstractMatcherTest; class IsArrayContainingKeyValuePairTest extends AbstractMatcherTest { protected function createMatcher() { return IsArrayContainingKeyValuePair::hasKeyValuePair('irrelevant', 'irrelevant'); } public function testMatchesArrayContainingMatchingKeyAndValue() { $array = array('a'=>1, 'b'=>2); $this->assertMatches(hasKeyValuePair(equalTo('a'), equalTo(1)), $array, 'matcherA'); $this->assertMatches(hasKeyValuePair(equalTo('b'), equalTo(2)), $array, 'matcherB'); $this->assertMismatchDescription( 'array was ["a" => <1>, "b" => <2>]', hasKeyValuePair(equalTo('c'), equalTo(3)), $array ); } public function testDoesNotMatchNull() { $this->assertMismatchDescription('was null', hasKeyValuePair(anything(), anything()), null); } public function testHasReadableDescription() { $this->assertDescription('array containing ["a" => <2>]', hasKeyValuePair(equalTo('a'), equalTo(2))); } } hamcrest-php/tests/Hamcrest/Array/IsArrayContainingKeyTest.php 0000644 00000003076 15233660706 0020551 0 ustar 00 <?php namespace Hamcrest\Arrays; use Hamcrest\AbstractMatcherTest; class IsArrayContainingKeyTest extends AbstractMatcherTest { protected function createMatcher() { return IsArrayContainingKey::hasKeyInArray('irrelevant'); } public function testMatchesSingleElementArrayContainingKey() { $array = array('a'=>1); $this->assertMatches(hasKey('a'), $array, 'Matches single key'); } public function testMatchesArrayContainingKey() { $array = array('a'=>1, 'b'=>2, 'c'=>3); $this->assertMatches(hasKey('a'), $array, 'Matches a'); $this->assertMatches(hasKey('c'), $array, 'Matches c'); } public function testMatchesArrayContainingKeyWithIntegerKeys() { $array = array(1=>'A', 2=>'B'); assertThat($array, hasKey(1)); } public function testMatchesArrayContainingKeyWithNumberKeys() { $array = array(1=>'A', 2=>'B'); assertThat($array, hasKey(1)); // very ugly version! assertThat($array, IsArrayContainingKey::hasKeyInArray(2)); } public function testHasReadableDescription() { $this->assertDescription('array with key "a"', hasKey('a')); } public function testDoesNotMatchEmptyArray() { $this->assertMismatchDescription('array was []', hasKey('Foo'), array()); } public function testDoesNotMatchArrayMissingKey() { $array = array('a'=>1, 'b'=>2, 'c'=>3); $this->assertMismatchDescription('array was ["a" => <1>, "b" => <2>, "c" => <3>]', hasKey('d'), $array); } } hamcrest-php/tests/Hamcrest/Array/IsArrayContainingTest.php 0000644 00000002355 15233660706 0020077 0 ustar 00 <?php namespace Hamcrest\Arrays; use Hamcrest\AbstractMatcherTest; class IsArrayContainingTest extends AbstractMatcherTest { protected function createMatcher() { return IsArrayContaining::hasItemInArray('irrelevant'); } public function testMatchesAnArrayThatContainsAnElementMatchingTheGivenMatcher() { $this->assertMatches( hasItemInArray('a'), array('a', 'b', 'c'), "should matches array that contains 'a'" ); } public function testDoesNotMatchAnArrayThatDoesntContainAnElementMatchingTheGivenMatcher() { $this->assertDoesNotMatch( hasItemInArray('a'), array('b', 'c'), "should not matches array that doesn't contain 'a'" ); $this->assertDoesNotMatch( hasItemInArray('a'), array(), 'should not match empty array' ); } public function testDoesNotMatchNull() { $this->assertDoesNotMatch( hasItemInArray('a'), null, 'should not match null' ); } public function testHasAReadableDescription() { $this->assertDescription('an array containing "a"', hasItemInArray('a')); } } hamcrest-php/tests/Hamcrest/Array/IsArrayContainingInAnyOrderTest.php 0000644 00000003274 15233660706 0022033 0 ustar 00 <?php namespace Hamcrest\Arrays; use Hamcrest\AbstractMatcherTest; class IsArrayContainingInAnyOrderTest extends AbstractMatcherTest { protected function createMatcher() { return IsArrayContainingInAnyOrder::arrayContainingInAnyOrder(array(1, 2)); } public function testHasAReadableDescription() { $this->assertDescription('[<1>, <2>] in any order', containsInAnyOrder(array(1, 2))); } public function testMatchesItemsInAnyOrder() { $this->assertMatches(containsInAnyOrder(array(1, 2, 3)), array(1, 2, 3), 'in order'); $this->assertMatches(containsInAnyOrder(array(1, 2, 3)), array(3, 2, 1), 'out of order'); $this->assertMatches(containsInAnyOrder(array(1)), array(1), 'single'); } public function testAppliesMatchersInAnyOrder() { $this->assertMatches( containsInAnyOrder(array(1, 2, 3)), array(1, 2, 3), 'in order' ); $this->assertMatches( containsInAnyOrder(array(1, 2, 3)), array(3, 2, 1), 'out of order' ); $this->assertMatches( containsInAnyOrder(array(1)), array(1), 'single' ); } public function testMismatchesItemsInAnyOrder() { $matcher = containsInAnyOrder(array(1, 2, 3)); $this->assertMismatchDescription('was null', $matcher, null); $this->assertMismatchDescription('No item matches: <1>, <2>, <3> in []', $matcher, array()); $this->assertMismatchDescription('No item matches: <2>, <3> in [<1>]', $matcher, array(1)); $this->assertMismatchDescription('Not matched: <4>', $matcher, array(4, 3, 2, 1)); } } hamcrest-php/tests/Hamcrest/Array/IsArrayWithSizeTest.php 0000644 00000002203 15233660706 0017544 0 ustar 00 <?php namespace Hamcrest\Arrays; use Hamcrest\AbstractMatcherTest; class IsArrayWithSizeTest extends AbstractMatcherTest { protected function createMatcher() { return IsArrayWithSize::arrayWithSize(equalTo(2)); } public function testMatchesWhenSizeIsCorrect() { $this->assertMatches(arrayWithSize(equalTo(3)), array(1, 2, 3), 'correct size'); $this->assertDoesNotMatch(arrayWithSize(equalTo(2)), array(1, 2, 3), 'incorrect size'); } public function testProvidesConvenientShortcutForArrayWithSizeEqualTo() { $this->assertMatches(arrayWithSize(3), array(1, 2, 3), 'correct size'); $this->assertDoesNotMatch(arrayWithSize(2), array(1, 2, 3), 'incorrect size'); } public function testEmptyArray() { $this->assertMatches(emptyArray(), array(), 'correct size'); $this->assertDoesNotMatch(emptyArray(), array(1), 'incorrect size'); } public function testHasAReadableDescription() { $this->assertDescription('an array with size <3>', arrayWithSize(equalTo(3))); $this->assertDescription('an empty array', emptyArray()); } } hamcrest-php/tests/Hamcrest/Array/IsArrayTest.php 0000644 00000004676 15233660706 0016075 0 ustar 00 <?php namespace Hamcrest\Arrays; use Hamcrest\AbstractMatcherTest; class IsArrayTest extends AbstractMatcherTest { protected function createMatcher() { return IsArray::anArray(array(equalTo('irrelevant'))); } public function testMatchesAnArrayThatMatchesAllTheElementMatchers() { $this->assertMatches( anArray(array(equalTo('a'), equalTo('b'), equalTo('c'))), array('a', 'b', 'c'), 'should match array with matching elements' ); } public function testDoesNotMatchAnArrayWhenElementsDoNotMatch() { $this->assertDoesNotMatch( anArray(array(equalTo('a'), equalTo('b'))), array('b', 'c'), 'should not match array with different elements' ); } public function testDoesNotMatchAnArrayOfDifferentSize() { $this->assertDoesNotMatch( anArray(array(equalTo('a'), equalTo('b'))), array('a', 'b', 'c'), 'should not match larger array' ); $this->assertDoesNotMatch( anArray(array(equalTo('a'), equalTo('b'))), array('a'), 'should not match smaller array' ); } public function testDoesNotMatchNull() { $this->assertDoesNotMatch( anArray(array(equalTo('a'))), null, 'should not match null' ); } public function testHasAReadableDescription() { $this->assertDescription( '["a", "b"]', anArray(array(equalTo('a'), equalTo('b'))) ); } public function testHasAReadableMismatchDescriptionWhenKeysDontMatch() { $this->assertMismatchDescription( 'array keys were [<1>, <2>]', anArray(array(equalTo('a'), equalTo('b'))), array(1 => 'a', 2 => 'b') ); } public function testSupportsMatchesAssociativeArrays() { $this->assertMatches( anArray(array('x'=>equalTo('a'), 'y'=>equalTo('b'), 'z'=>equalTo('c'))), array('x'=>'a', 'y'=>'b', 'z'=>'c'), 'should match associative array with matching elements' ); } public function testDoesNotMatchAnAssociativeArrayWhenKeysDoNotMatch() { $this->assertDoesNotMatch( anArray(array('x'=>equalTo('a'), 'y'=>equalTo('b'))), array('x'=>'b', 'z'=>'c'), 'should not match array with different keys' ); } } hamcrest-php/tests/Hamcrest/BaseMatcherTest.php 0000644 00000001027 15233660706 0015606 0 ustar 00 <?php namespace Hamcrest; /* Test-specific subclass only */ class BaseMatcherTest extends \Hamcrest\BaseMatcher { public function matches($item) { throw new \RuntimeException(); } public function describeTo(\Hamcrest\Description $description) { $description->appendText('SOME DESCRIPTION'); } public function testDescribesItselfWithToStringMethod() { $someMatcher = new \Hamcrest\SomeMatcher(); $this->assertEquals('SOME DESCRIPTION', (string) $someMatcher); } } hamcrest-php/tests/Hamcrest/MatcherAssertTest.php 0000644 00000016275 15233660706 0016210 0 ustar 00 <?php namespace Hamcrest; use PHPUnit\Framework\TestCase; class MatcherAssertTest extends TestCase { protected function setUp() { \Hamcrest\MatcherAssert::resetCount(); } public function testResetCount() { \Hamcrest\MatcherAssert::assertThat(true); self::assertEquals(1, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); \Hamcrest\MatcherAssert::resetCount(); self::assertEquals(0, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } public function testAssertThatWithTrueArgPasses() { \Hamcrest\MatcherAssert::assertThat(true); \Hamcrest\MatcherAssert::assertThat('non-empty'); \Hamcrest\MatcherAssert::assertThat(1); \Hamcrest\MatcherAssert::assertThat(3.14159); \Hamcrest\MatcherAssert::assertThat(array(true)); self::assertEquals(5, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } public function testAssertThatWithFalseArgFails() { try { \Hamcrest\MatcherAssert::assertThat(false); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat(null); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat(''); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat(0); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat(0.0); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat(array()); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('', $ex->getMessage()); } self::assertEquals(6, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } public function testAssertThatWithIdentifierAndTrueArgPasses() { \Hamcrest\MatcherAssert::assertThat('identifier', true); \Hamcrest\MatcherAssert::assertThat('identifier', 'non-empty'); \Hamcrest\MatcherAssert::assertThat('identifier', 1); \Hamcrest\MatcherAssert::assertThat('identifier', 3.14159); \Hamcrest\MatcherAssert::assertThat('identifier', array(true)); self::assertEquals(5, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } public function testAssertThatWithIdentifierAndFalseArgFails() { try { \Hamcrest\MatcherAssert::assertThat('identifier', false); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('identifier', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat('identifier', null); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('identifier', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat('identifier', ''); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('identifier', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat('identifier', 0); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('identifier', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat('identifier', 0.0); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('identifier', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat('identifier', array()); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('identifier', $ex->getMessage()); } self::assertEquals(6, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } public function testAssertThatWithActualValueAndMatcherArgsThatMatchPasses() { \Hamcrest\MatcherAssert::assertThat(true, is(true)); self::assertEquals(1, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } public function testAssertThatWithActualValueAndMatcherArgsThatDontMatchFails() { $expected = 'expected'; $actual = 'actual'; $expectedMessage = 'Expected: "expected"' . PHP_EOL . ' but: was "actual"'; try { \Hamcrest\MatcherAssert::assertThat($actual, equalTo($expected)); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals($expectedMessage, $ex->getMessage()); self::assertEquals(1, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } } public function testAssertThatWithIdentifierAndActualValueAndMatcherArgsThatMatchPasses() { \Hamcrest\MatcherAssert::assertThat('identifier', true, is(true)); self::assertEquals(1, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } public function testAssertThatWithIdentifierAndActualValueAndMatcherArgsThatDontMatchFails() { $expected = 'expected'; $actual = 'actual'; $expectedMessage = 'identifier' . PHP_EOL . 'Expected: "expected"' . PHP_EOL . ' but: was "actual"'; try { \Hamcrest\MatcherAssert::assertThat('identifier', $actual, equalTo($expected)); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals($expectedMessage, $ex->getMessage()); self::assertEquals(1, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } } public function testAssertThatWithNoArgsThrowsErrorAndDoesntIncrementCount() { try { \Hamcrest\MatcherAssert::assertThat(); self::fail('expected invalid argument exception'); } catch (\InvalidArgumentException $ex) { self::assertEquals(0, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } } public function testAssertThatWithFourArgsThrowsErrorAndDoesntIncrementCount() { try { \Hamcrest\MatcherAssert::assertThat(1, 2, 3, 4); self::fail('expected invalid argument exception'); } catch (\InvalidArgumentException $ex) { self::assertEquals(0, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } } } hamcrest-php/tests/Hamcrest/StringDescriptionTest.php 0000644 00000012526 15233660706 0017110 0 ustar 00 <?php namespace Hamcrest; use PHPUnit\Framework\TestCase; class SampleSelfDescriber implements \Hamcrest\SelfDescribing { private $_text; public function __construct($text) { $this->_text = $text; } public function describeTo(\Hamcrest\Description $description) { $description->appendText($this->_text); } } class StringDescriptionTest extends TestCase { private $_description; protected function setUp() { $this->_description = new \Hamcrest\StringDescription(); } public function testAppendTextAppendsTextInformation() { $this->_description->appendText('foo')->appendText('bar'); $this->assertEquals('foobar', (string) $this->_description); } public function testAppendValueCanAppendTextTypes() { $this->_description->appendValue('foo'); $this->assertEquals('"foo"', (string) $this->_description); } public function testSpecialCharactersAreEscapedForStringTypes() { $this->_description->appendValue("foo\\bar\"zip\r\n"); $this->assertEquals('"foo\\bar\\"zip\r\n"', (string) $this->_description); } public function testIntegerValuesCanBeAppended() { $this->_description->appendValue(42); $this->assertEquals('<42>', (string) $this->_description); } public function testFloatValuesCanBeAppended() { $this->_description->appendValue(42.78); $this->assertEquals('<42.78F>', (string) $this->_description); } public function testNullValuesCanBeAppended() { $this->_description->appendValue(null); $this->assertEquals('null', (string) $this->_description); } public function testArraysCanBeAppended() { $this->_description->appendValue(array('foo', 42.78)); $this->assertEquals('["foo", <42.78F>]', (string) $this->_description); } public function testObjectsCanBeAppended() { $this->_description->appendValue(new \stdClass()); $this->assertEquals('<stdClass>', (string) $this->_description); } public function testBooleanValuesCanBeAppended() { $this->_description->appendValue(false); $this->assertEquals('<false>', (string) $this->_description); } public function testListsOfvaluesCanBeAppended() { $this->_description->appendValue(array('foo', 42.78)); $this->assertEquals('["foo", <42.78F>]', (string) $this->_description); } public function testIterableOfvaluesCanBeAppended() { $items = new \ArrayObject(array('foo', 42.78)); $this->_description->appendValue($items); $this->assertEquals('["foo", <42.78F>]', (string) $this->_description); } public function testIteratorOfvaluesCanBeAppended() { $items = new \ArrayObject(array('foo', 42.78)); $this->_description->appendValue($items->getIterator()); $this->assertEquals('["foo", <42.78F>]', (string) $this->_description); } public function testListsOfvaluesCanBeAppendedManually() { $this->_description->appendValueList('@start@', '@sep@ ', '@end@', array('foo', 42.78)); $this->assertEquals('@start@"foo"@sep@ <42.78F>@end@', (string) $this->_description); } public function testIterableOfvaluesCanBeAppendedManually() { $items = new \ArrayObject(array('foo', 42.78)); $this->_description->appendValueList('@start@', '@sep@ ', '@end@', $items); $this->assertEquals('@start@"foo"@sep@ <42.78F>@end@', (string) $this->_description); } public function testIteratorOfvaluesCanBeAppendedManually() { $items = new \ArrayObject(array('foo', 42.78)); $this->_description->appendValueList('@start@', '@sep@ ', '@end@', $items->getIterator()); $this->assertEquals('@start@"foo"@sep@ <42.78F>@end@', (string) $this->_description); } public function testSelfDescribingObjectsCanBeAppended() { $this->_description ->appendDescriptionOf(new \Hamcrest\SampleSelfDescriber('foo')) ->appendDescriptionOf(new \Hamcrest\SampleSelfDescriber('bar')) ; $this->assertEquals('foobar', (string) $this->_description); } public function testSelfDescribingObjectsCanBeAppendedAsLists() { $this->_description->appendList('@start@', '@sep@ ', '@end@', array( new \Hamcrest\SampleSelfDescriber('foo'), new \Hamcrest\SampleSelfDescriber('bar') )); $this->assertEquals('@start@foo@sep@ bar@end@', (string) $this->_description); } public function testSelfDescribingObjectsCanBeAppendedAsIteratedLists() { $items = new \ArrayObject(array( new \Hamcrest\SampleSelfDescriber('foo'), new \Hamcrest\SampleSelfDescriber('bar') )); $this->_description->appendList('@start@', '@sep@ ', '@end@', $items); $this->assertEquals('@start@foo@sep@ bar@end@', (string) $this->_description); } public function testSelfDescribingObjectsCanBeAppendedAsIterators() { $items = new \ArrayObject(array( new \Hamcrest\SampleSelfDescriber('foo'), new \Hamcrest\SampleSelfDescriber('bar') )); $this->_description->appendList('@start@', '@sep@ ', '@end@', $items->getIterator()); $this->assertEquals('@start@foo@sep@ bar@end@', (string) $this->_description); } } hamcrest-php/tests/Hamcrest/AbstractMatcherTest.php 0000644 00000003577 15233660706 0016513 0 ustar 00 <?php namespace Hamcrest; use PHPUnit\Framework\TestCase; class UnknownType { } abstract class AbstractMatcherTest extends TestCase { const ARGUMENT_IGNORED = "ignored"; const ANY_NON_NULL_ARGUMENT = "notnull"; abstract protected function createMatcher(); public function assertMatches(\Hamcrest\Matcher $matcher, $arg, $message) { $this->assertTrue($matcher->matches($arg), $message); } public function assertDoesNotMatch(\Hamcrest\Matcher $matcher, $arg, $message) { $this->assertFalse($matcher->matches($arg), $message); } public function assertDescription($expected, \Hamcrest\Matcher $matcher) { $description = new \Hamcrest\StringDescription(); $description->appendDescriptionOf($matcher); $this->assertEquals($expected, (string) $description, 'Expected description'); } 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' ); } public function testIsNullSafe() { //Should not generate any notices $this->createMatcher()->matches(null); $this->createMatcher()->describeMismatch( null, new \Hamcrest\NullDescription() ); } public function testCopesWithUnknownTypes() { //Should not generate any notices $this->createMatcher()->matches(new UnknownType()); $this->createMatcher()->describeMismatch( new UnknownType(), new NullDescription() ); } } hamcrest-php/tests/Hamcrest/Collection/IsEmptyTraversableTest.php 0000644 00000003513 15233660706 0021312 0 ustar 00 <?php namespace Hamcrest\Collection; use Hamcrest\AbstractMatcherTest; class IsEmptyTraversableTest extends AbstractMatcherTest { protected function createMatcher() { return IsEmptyTraversable::emptyTraversable(); } public function testEmptyMatcherMatchesWhenEmpty() { $this->assertMatches( emptyTraversable(), new \ArrayObject(array()), 'an empty traversable' ); } public function testEmptyMatcherDoesNotMatchWhenNotEmpty() { $this->assertDoesNotMatch( emptyTraversable(), new \ArrayObject(array(1, 2, 3)), 'a non-empty traversable' ); } public function testEmptyMatcherDoesNotMatchNull() { $this->assertDoesNotMatch( emptyTraversable(), null, 'should not match null' ); } public function testEmptyMatcherHasAReadableDescription() { $this->assertDescription('an empty traversable', emptyTraversable()); } public function testNonEmptyDoesNotMatchNull() { $this->assertDoesNotMatch( nonEmptyTraversable(), null, 'should not match null' ); } public function testNonEmptyDoesNotMatchWhenEmpty() { $this->assertDoesNotMatch( nonEmptyTraversable(), new \ArrayObject(array()), 'an empty traversable' ); } public function testNonEmptyMatchesWhenNotEmpty() { $this->assertMatches( nonEmptyTraversable(), new \ArrayObject(array(1, 2, 3)), 'a non-empty traversable' ); } public function testNonEmptyNonEmptyMatcherHasAReadableDescription() { $this->assertDescription('a non-empty traversable', nonEmptyTraversable()); } } hamcrest-php/tests/Hamcrest/Collection/IsTraversableWithSizeTest.php 0000644 00000002532 15233660706 0021762 0 ustar 00 <?php namespace Hamcrest\Collection; class IsTraversableWithSizeTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Collection\IsTraversableWithSize::traversableWithSize( equalTo(2) ); } public function testMatchesWhenSizeIsCorrect() { $this->assertMatches( traversableWithSize(equalTo(3)), new \ArrayObject(array(1, 2, 3)), 'correct size' ); } public function testDoesNotMatchWhenSizeIsIncorrect() { $this->assertDoesNotMatch( traversableWithSize(equalTo(2)), new \ArrayObject(array(1, 2, 3)), 'incorrect size' ); } public function testDoesNotMatchNull() { $this->assertDoesNotMatch( traversableWithSize(3), null, 'should not match null' ); } public function testProvidesConvenientShortcutForTraversableWithSizeEqualTo() { $this->assertMatches( traversableWithSize(3), new \ArrayObject(array(1, 2, 3)), 'correct size' ); } public function testHasAReadableDescription() { $this->assertDescription( 'a traversable with size <3>', traversableWithSize(equalTo(3)) ); } } hamcrest-php/tests/Hamcrest/UtilTest.php 0000644 00000005106 15233660706 0014347 0 ustar 00 <?php namespace Hamcrest; use PHPUnit\Framework\TestCase; class UtilTest extends TestCase { public function testWrapValueWithIsEqualLeavesMatchersUntouched() { $matcher = new \Hamcrest\Text\MatchesPattern('/fo+/'); $newMatcher = \Hamcrest\Util::wrapValueWithIsEqual($matcher); $this->assertSame($matcher, $newMatcher); } public function testWrapValueWithIsEqualWrapsPrimitive() { $matcher = \Hamcrest\Util::wrapValueWithIsEqual('foo'); $this->assertInstanceOf('Hamcrest\Core\IsEqual', $matcher); $this->assertTrue($matcher->matches('foo')); } public function testCheckAllAreMatchersAcceptsMatchers() { \Hamcrest\Util::checkAllAreMatchers(array( new \Hamcrest\Text\MatchesPattern('/fo+/'), new \Hamcrest\Core\IsEqual('foo'), )); } /** * @expectedException InvalidArgumentException */ public function testCheckAllAreMatchersFailsForPrimitive() { \Hamcrest\Util::checkAllAreMatchers(array( new \Hamcrest\Text\MatchesPattern('/fo+/'), 'foo', )); } 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 testCreateMatcherArrayLeavesMatchersUntouched() { $matcher = new \Hamcrest\Text\MatchesPattern('/fo+/'); $items = array($matcher); $matchers = $this->callAndAssertCreateMatcherArray($items); $this->assertSame($matcher, $matchers[0]); } public function testCreateMatcherArrayWrapsPrimitiveWithIsEqualMatcher() { $matchers = $this->callAndAssertCreateMatcherArray(array('foo')); $this->assertInstanceOf('Hamcrest\Core\IsEqual', $matchers[0]); $this->assertTrue($matchers[0]->matches('foo')); } public function testCreateMatcherArrayDoesntModifyOriginalArray() { $items = array('foo'); $this->callAndAssertCreateMatcherArray($items); $this->assertSame('foo', $items[0]); } public function testCreateMatcherArrayUnwrapsSingleArrayElement() { $matchers = $this->callAndAssertCreateMatcherArray(array(array('foo'))); $this->assertInstanceOf('Hamcrest\Core\IsEqual', $matchers[0]); $this->assertTrue($matchers[0]->matches('foo')); } } hamcrest-php/tests/Hamcrest/FeatureMatcherTest.php 0000644 00000003175 15233660706 0016335 0 ustar 00 <?php namespace Hamcrest; class Thingy { private $_result; public function __construct($result) { $this->_result = $result; } public function getResult() { return $this->_result; } } /* Test-specific subclass only */ class ResultMatcher extends \Hamcrest\FeatureMatcher { public function __construct() { parent::__construct(self::TYPE_ANY, null, equalTo('bar'), 'Thingy with result', 'result'); } public function featureValueOf($actual) { if ($actual instanceof \Hamcrest\Thingy) { return $actual->getResult(); } } } class FeatureMatcherTest extends \Hamcrest\AbstractMatcherTest { private $_resultMatcher; protected function setUp() { $this->_resultMatcher = $this->_resultMatcher(); } protected function createMatcher() { return $this->_resultMatcher(); } public function testMatchesPartOfAnObject() { $this->assertMatches($this->_resultMatcher, new \Hamcrest\Thingy('bar'), 'feature'); $this->assertDescription('Thingy with result "bar"', $this->_resultMatcher); } public function testMismatchesPartOfAnObject() { $this->assertMismatchDescription( 'result was "foo"', $this->_resultMatcher, new \Hamcrest\Thingy('foo') ); } public function testDoesNotGenerateNoticesForNull() { $this->assertMismatchDescription('result was null', $this->_resultMatcher, null); } // -- Creation Methods private function _resultMatcher() { return new \Hamcrest\ResultMatcher(); } } hamcrest-php/tests/Hamcrest/InvokedMatcherTest.php 0000644 00000001143 15233660706 0016332 0 ustar 00 <?php namespace Hamcrest; use PHPUnit\Framework\TestCase; class SampleInvokeMatcher extends BaseMatcherTest { private $matchAgainst; public function __construct($matchAgainst) { $this->matchAgainst = $matchAgainst; } public function matches($item) { return $item == $this->matchAgainst; } } class InvokedMatcherTest extends TestCase { public function testInvokedMatchersCallMatches() { $sampleMatcher = new SampleInvokeMatcher('foo'); $this->assertTrue($sampleMatcher('foo')); $this->assertFalse($sampleMatcher('bar')); } } hamcrest-php/tests/Hamcrest/Text/StringEndsWithTest.php 0000644 00000003552 15233660706 0017275 0 ustar 00 <?php namespace Hamcrest\Text; class StringEndsWithTest extends \Hamcrest\AbstractMatcherTest { const EXCERPT = 'EXCERPT'; private $_stringEndsWith; protected function setUp() { $this->_stringEndsWith = \Hamcrest\Text\StringEndsWith::endsWith(self::EXCERPT); } protected function createMatcher() { return $this->_stringEndsWith; } public function testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring() { $this->assertFalse( $this->_stringEndsWith->matches(self::EXCERPT . 'END'), 'should be false if excerpt at beginning' ); $this->assertTrue( $this->_stringEndsWith->matches('START' . self::EXCERPT), 'should be true if excerpt at end' ); $this->assertFalse( $this->_stringEndsWith->matches('START' . self::EXCERPT . 'END'), 'should be false if excerpt in middle' ); $this->assertTrue( $this->_stringEndsWith->matches(self::EXCERPT . self::EXCERPT), 'should be true if excerpt is at end and repeated' ); $this->assertFalse( $this->_stringEndsWith->matches('Something else'), 'should be false if excerpt is not in string' ); $this->assertFalse( $this->_stringEndsWith->matches(substr(self::EXCERPT, 0, strlen(self::EXCERPT) - 2)), 'should be false if part of excerpt is at end of string' ); } public function testEvaluatesToTrueIfArgumentIsEqualToSubstring() { $this->assertTrue( $this->_stringEndsWith->matches(self::EXCERPT), 'should be true if excerpt is entire string' ); } public function testHasAReadableDescription() { $this->assertDescription('a string ending with "EXCERPT"', $this->_stringEndsWith); } } hamcrest-php/tests/Hamcrest/Text/IsEqualIgnoringWhiteSpaceTest.php 0000644 00000002556 15233660706 0021401 0 ustar 00 <?php namespace Hamcrest\Text; class IsEqualIgnoringWhiteSpaceTest extends \Hamcrest\AbstractMatcherTest { private $_matcher; protected function setUp() { $this->_matcher = \Hamcrest\Text\IsEqualIgnoringWhiteSpace::equalToIgnoringWhiteSpace( "Hello World how\n are we? " ); } protected function createMatcher() { return $this->_matcher; } public function testPassesIfWordsAreSameButWhitespaceDiffers() { assertThat('Hello World how are we?', $this->_matcher); assertThat(" Hello \rWorld \t how are\nwe?", $this->_matcher); } public function testFailsIfTextOtherThanWhitespaceDiffers() { assertThat('Hello PLANET how are we?', not($this->_matcher)); assertThat('Hello World how are we', not($this->_matcher)); } public function testFailsIfWhitespaceIsAddedOrRemovedInMidWord() { assertThat('HelloWorld how are we?', not($this->_matcher)); assertThat('Hello Wo rld how are we?', not($this->_matcher)); } public function testFailsIfMatchingAgainstNull() { assertThat(null, not($this->_matcher)); } public function testHasAReadableDescription() { $this->assertDescription( "equalToIgnoringWhiteSpace(\"Hello World how\\n are we? \")", $this->_matcher ); } } hamcrest-php/tests/Hamcrest/Text/StringContainsTest.php 0000644 00000005132 15233660706 0017322 0 ustar 00 <?php namespace Hamcrest\Text; class StringContainsTest extends \Hamcrest\AbstractMatcherTest { const EXCERPT = 'EXCERPT'; private $_stringContains; protected function setUp() { $this->_stringContains = \Hamcrest\Text\StringContains::containsString(self::EXCERPT); } protected function createMatcher() { return $this->_stringContains; } public function testEvaluatesToTrueIfArgumentContainsSubstring() { $this->assertTrue( $this->_stringContains->matches(self::EXCERPT . 'END'), 'should be true if excerpt at beginning' ); $this->assertTrue( $this->_stringContains->matches('START' . self::EXCERPT), 'should be true if excerpt at end' ); $this->assertTrue( $this->_stringContains->matches('START' . self::EXCERPT . 'END'), 'should be true if excerpt in middle' ); $this->assertTrue( $this->_stringContains->matches(self::EXCERPT . self::EXCERPT), 'should be true if excerpt is repeated' ); $this->assertFalse( $this->_stringContains->matches('Something else'), 'should not be true if excerpt is not in string' ); $this->assertFalse( $this->_stringContains->matches(substr(self::EXCERPT, 1)), 'should not be true if part of excerpt is in string' ); } public function testEvaluatesToTrueIfArgumentIsEqualToSubstring() { $this->assertTrue( $this->_stringContains->matches(self::EXCERPT), 'should be true if excerpt is entire string' ); } public function testEvaluatesToFalseIfArgumentContainsSubstringIgnoringCase() { $this->assertFalse( $this->_stringContains->matches(strtolower(self::EXCERPT)), 'should be false if excerpt is entire string ignoring case' ); $this->assertFalse( $this->_stringContains->matches('START' . strtolower(self::EXCERPT) . 'END'), 'should be false if excerpt is contained in string ignoring case' ); } public function testIgnoringCaseReturnsCorrectMatcher() { $this->assertTrue( $this->_stringContains->ignoringCase()->matches('EXceRpT'), 'should be true if excerpt is entire string ignoring case' ); } public function testHasAReadableDescription() { $this->assertDescription( 'a string containing "' . self::EXCERPT . '"', $this->_stringContains ); } } hamcrest-php/tests/Hamcrest/Text/IsEmptyStringTest.php 0000644 00000004367 15233660706 0017147 0 ustar 00 <?php namespace Hamcrest\Text; class IsEmptyStringTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Text\IsEmptyString::isEmptyOrNullString(); } public function testEmptyDoesNotMatchNull() { $this->assertDoesNotMatch(emptyString(), null, 'null'); } public function testEmptyDoesNotMatchZero() { $this->assertDoesNotMatch(emptyString(), 0, 'zero'); } public function testEmptyDoesNotMatchFalse() { $this->assertDoesNotMatch(emptyString(), false, 'false'); } public function testEmptyDoesNotMatchEmptyArray() { $this->assertDoesNotMatch(emptyString(), array(), 'empty array'); } public function testEmptyMatchesEmptyString() { $this->assertMatches(emptyString(), '', 'empty string'); } public function testEmptyDoesNotMatchNonEmptyString() { $this->assertDoesNotMatch(emptyString(), 'foo', 'non-empty string'); } public function testEmptyHasAReadableDescription() { $this->assertDescription('an empty string', emptyString()); } public function testEmptyOrNullMatchesNull() { $this->assertMatches(nullOrEmptyString(), null, 'null'); } public function testEmptyOrNullMatchesEmptyString() { $this->assertMatches(nullOrEmptyString(), '', 'empty string'); } public function testEmptyOrNullDoesNotMatchNonEmptyString() { $this->assertDoesNotMatch(nullOrEmptyString(), 'foo', 'non-empty string'); } public function testEmptyOrNullHasAReadableDescription() { $this->assertDescription('(null or an empty string)', nullOrEmptyString()); } public function testNonEmptyDoesNotMatchNull() { $this->assertDoesNotMatch(nonEmptyString(), null, 'null'); } public function testNonEmptyDoesNotMatchEmptyString() { $this->assertDoesNotMatch(nonEmptyString(), '', 'empty string'); } public function testNonEmptyMatchesNonEmptyString() { $this->assertMatches(nonEmptyString(), 'foo', 'non-empty string'); } public function testNonEmptyHasAReadableDescription() { $this->assertDescription('a non-empty string', nonEmptyString()); } } hamcrest-php/tests/Hamcrest/Text/StringContainsIgnoringCaseTest.php 0000644 00000004671 15233660706 0021622 0 ustar 00 <?php namespace Hamcrest\Text; class StringContainsIgnoringCaseTest extends \Hamcrest\AbstractMatcherTest { const EXCERPT = 'ExcErPt'; private $_stringContains; protected function setUp() { $this->_stringContains = \Hamcrest\Text\StringContainsIgnoringCase::containsStringIgnoringCase( strtolower(self::EXCERPT) ); } protected function createMatcher() { return $this->_stringContains; } public function testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring() { $this->assertTrue( $this->_stringContains->matches(self::EXCERPT . 'END'), 'should be true if excerpt at beginning' ); $this->assertTrue( $this->_stringContains->matches('START' . self::EXCERPT), 'should be true if excerpt at end' ); $this->assertTrue( $this->_stringContains->matches('START' . self::EXCERPT . 'END'), 'should be true if excerpt in middle' ); $this->assertTrue( $this->_stringContains->matches(self::EXCERPT . self::EXCERPT), 'should be true if excerpt is repeated' ); $this->assertFalse( $this->_stringContains->matches('Something else'), 'should not be true if excerpt is not in string' ); $this->assertFalse( $this->_stringContains->matches(substr(self::EXCERPT, 1)), 'should not be true if part of excerpt is in string' ); } public function testEvaluatesToTrueIfArgumentIsEqualToSubstring() { $this->assertTrue( $this->_stringContains->matches(self::EXCERPT), 'should be true if excerpt is entire string' ); } public function testEvaluatesToTrueIfArgumentContainsExactSubstring() { $this->assertTrue( $this->_stringContains->matches(strtolower(self::EXCERPT)), 'should be false if excerpt is entire string ignoring case' ); $this->assertTrue( $this->_stringContains->matches('START' . strtolower(self::EXCERPT) . 'END'), 'should be false if excerpt is contained in string ignoring case' ); } public function testHasAReadableDescription() { $this->assertDescription( 'a string containing in any case "' . strtolower(self::EXCERPT) . '"', $this->_stringContains ); } } hamcrest-php/tests/Hamcrest/Text/MatchesPatternTest.php 0000644 00000001533 15233660706 0017300 0 ustar 00 <?php namespace Hamcrest\Text; class MatchesPatternTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return matchesPattern('/o+b/'); } public function testEvaluatesToTrueIfArgumentmatchesPattern() { assertThat('foobar', matchesPattern('/o+b/')); assertThat('foobar', matchesPattern('/^foo/')); assertThat('foobar', matchesPattern('/ba*r$/')); assertThat('foobar', matchesPattern('/^foobar$/')); } public function testEvaluatesToFalseIfArgumentDoesntMatchRegex() { assertThat('foobar', not(matchesPattern('/^foob$/'))); assertThat('foobar', not(matchesPattern('/oobe/'))); } public function testHasAReadableDescription() { $this->assertDescription('a string matching "pattern"', matchesPattern('pattern')); } } hamcrest-php/tests/Hamcrest/Text/StringStartsWithTest.php 0000644 00000003565 15233660706 0017670 0 ustar 00 <?php namespace Hamcrest\Text; class StringStartsWithTest extends \Hamcrest\AbstractMatcherTest { const EXCERPT = 'EXCERPT'; private $_stringStartsWith; protected function setUp() { $this->_stringStartsWith = \Hamcrest\Text\StringStartsWith::startsWith(self::EXCERPT); } protected function createMatcher() { return $this->_stringStartsWith; } public function testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring() { $this->assertTrue( $this->_stringStartsWith->matches(self::EXCERPT . 'END'), 'should be true if excerpt at beginning' ); $this->assertFalse( $this->_stringStartsWith->matches('START' . self::EXCERPT), 'should be false if excerpt at end' ); $this->assertFalse( $this->_stringStartsWith->matches('START' . self::EXCERPT . 'END'), 'should be false if excerpt in middle' ); $this->assertTrue( $this->_stringStartsWith->matches(self::EXCERPT . self::EXCERPT), 'should be true if excerpt is at beginning and repeated' ); $this->assertFalse( $this->_stringStartsWith->matches('Something else'), 'should be false if excerpt is not in string' ); $this->assertFalse( $this->_stringStartsWith->matches(substr(self::EXCERPT, 1)), 'should be false if part of excerpt is at start of string' ); } public function testEvaluatesToTrueIfArgumentIsEqualToSubstring() { $this->assertTrue( $this->_stringStartsWith->matches(self::EXCERPT), 'should be true if excerpt is entire string' ); } public function testHasAReadableDescription() { $this->assertDescription('a string starting with "EXCERPT"', $this->_stringStartsWith); } } hamcrest-php/tests/Hamcrest/Text/StringContainsInOrderTest.php 0000644 00000002347 15233660706 0020612 0 ustar 00 <?php namespace Hamcrest\Text; class StringContainsInOrderTest extends \Hamcrest\AbstractMatcherTest { private $_m; protected function setUp() { $this->_m = \Hamcrest\Text\StringContainsInOrder::stringContainsInOrder(array('a', 'b', 'c')); } protected function createMatcher() { return $this->_m; } public function testMatchesOnlyIfStringContainsGivenSubstringsInTheSameOrder() { $this->assertMatches($this->_m, 'abc', 'substrings in order'); $this->assertMatches($this->_m, '1a2b3c4', 'substrings separated'); $this->assertDoesNotMatch($this->_m, 'cab', 'substrings out of order'); $this->assertDoesNotMatch($this->_m, 'xyz', 'no substrings in string'); $this->assertDoesNotMatch($this->_m, 'ac', 'substring missing'); $this->assertDoesNotMatch($this->_m, '', 'empty string'); } public function testAcceptsVariableArguments() { $this->assertMatches(stringContainsInOrder('a', 'b', 'c'), 'abc', 'substrings as variable arguments'); } public function testHasAReadableDescription() { $this->assertDescription( 'a string containing "a", "b", "c" in order', $this->_m ); } } hamcrest-php/tests/Hamcrest/Text/IsEqualIgnoringCaseTest.php 0000644 00000002174 15233660706 0020214 0 ustar 00 <?php namespace Hamcrest\Text; class IsEqualIgnoringCaseTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Text\IsEqualIgnoringCase::equalToIgnoringCase('irrelevant'); } public function testIgnoresCaseOfCharsInString() { assertThat('HELLO', equalToIgnoringCase('heLLo')); assertThat('hello', equalToIgnoringCase('heLLo')); assertThat('HelLo', equalToIgnoringCase('heLLo')); assertThat('bye', not(equalToIgnoringCase('heLLo'))); } public function testFailsIfAdditionalWhitespaceIsPresent() { assertThat('heLLo ', not(equalToIgnoringCase('heLLo'))); assertThat(' heLLo', not(equalToIgnoringCase('heLLo'))); assertThat('hello', not(equalToIgnoringCase(' heLLo'))); } public function testFailsIfMatchingAgainstNull() { assertThat(null, not(equalToIgnoringCase('heLLo'))); } public function testDescribesItselfAsCaseInsensitive() { $this->assertDescription( 'equalToIgnoringCase("heLLo")', equalToIgnoringCase('heLLo') ); } } hamcrest-php/tests/Hamcrest/Number/IsCloseToTest.php 0000644 00000001441 15233660706 0016524 0 ustar 00 <?php namespace Hamcrest\Number; class IsCloseToTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { $irrelevant = 0.1; return \Hamcrest\Number\IsCloseTo::closeTo($irrelevant, $irrelevant); } public function testEvaluatesToTrueIfArgumentIsEqualToADoubleValueWithinSomeError() { $p = closeTo(1.0, 0.5); $this->assertTrue($p->matches(1.0)); $this->assertTrue($p->matches(0.5)); $this->assertTrue($p->matches(1.5)); $this->assertDoesNotMatch($p, 2.0, 'too large'); $this->assertMismatchDescription('<2F> differed by <0.5F>', $p, 2.0); $this->assertDoesNotMatch($p, 0.0, 'number too small'); $this->assertMismatchDescription('<0F> differed by <0.5F>', $p, 0.0); } } hamcrest-php/tests/Hamcrest/Number/OrderingComparisonTest.php 0000644 00000001750 15233660706 0020467 0 ustar 00 <?php namespace Hamcrest\Number; class OrderingComparisonTest extends \Hamcrest\AbstractMatcherTest { protected function createMatcher() { return \Hamcrest\Number\OrderingComparison::greaterThan(1); } public function testComparesValuesForGreaterThan() { assertThat(2, greaterThan(1)); assertThat(0, not(greaterThan(1))); } public function testComparesValuesForLessThan() { assertThat(2, lessThan(3)); assertThat(0, lessThan(1)); } public function testComparesValuesForEquality() { assertThat(3, comparesEqualTo(3)); assertThat('aa', comparesEqualTo('aa')); } public function testAllowsForInclusiveComparisons() { assertThat(1, lessThanOrEqualTo(1)); assertThat(1, greaterThanOrEqualTo(1)); } public function testSupportsDifferentTypesOfComparableValues() { assertThat(1.1, greaterThan(1.0)); assertThat("cc", greaterThan("bb")); } } hamcrest-php/tests/Hamcrest/Xml/HasXPathTest.php 0000644 00000011750 15233660706 0015654 0 ustar 00 <?php namespace Hamcrest\Xml; class HasXPathTest extends \Hamcrest\AbstractMatcherTest { protected static $xml; protected static $doc; protected static $html; public static function setUpBeforeClass() { self::$xml = <<<XML <?xml version="1.0"?> <users> <user> <id>alice</id> <name>Alice Frankel</name> <role>admin</role> </user> <user> <id>bob</id> <name>Bob Frankel</name> <role>user</role> </user> <user> <id>charlie</id> <name>Charlie Chan</name> <role>user</role> </user> </users> XML; self::$doc = new \DOMDocument(); self::$doc->loadXML(self::$xml); self::$html = <<<HTML <html> <head> <title>Home Page</title> </head> <body> <h1>Heading</h1> <p>Some text</p> </body> </html> HTML; } protected function createMatcher() { return \Hamcrest\Xml\HasXPath::hasXPath('/users/user'); } public function testMatchesWhenXPathIsFound() { assertThat('one match', self::$doc, hasXPath('user[id = "bob"]')); assertThat('two matches', self::$doc, hasXPath('user[role = "user"]')); } public function testDoesNotMatchWhenXPathIsNotFound() { assertThat( 'no match', self::$doc, not(hasXPath('user[contains(id, "frank")]')) ); } public function testMatchesWhenExpressionWithoutMatcherEvaluatesToTrue() { assertThat( 'one match', self::$doc, hasXPath('count(user[id = "bob"])') ); } public function testDoesNotMatchWhenExpressionWithoutMatcherEvaluatesToFalse() { assertThat( 'no matches', self::$doc, not(hasXPath('count(user[id = "frank"])')) ); } public function testMatchesWhenExpressionIsEqual() { assertThat( 'one match', self::$doc, hasXPath('count(user[id = "bob"])', 1) ); assertThat( 'two matches', self::$doc, hasXPath('count(user[role = "user"])', 2) ); } public function testDoesNotMatchWhenExpressionIsNotEqual() { assertThat( 'no match', self::$doc, not(hasXPath('count(user[id = "frank"])', 2)) ); assertThat( 'one match', self::$doc, not(hasXPath('count(user[role = "admin"])', 2)) ); } public function testMatchesWhenContentMatches() { assertThat( 'one match', self::$doc, hasXPath('user/name', containsString('ice')) ); assertThat( 'two matches', self::$doc, hasXPath('user/role', equalTo('user')) ); } public function testDoesNotMatchWhenContentDoesNotMatch() { assertThat( 'no match', self::$doc, not(hasXPath('user/name', containsString('Bobby'))) ); assertThat( 'no matches', self::$doc, not(hasXPath('user/role', equalTo('owner'))) ); } public function testProvidesConvenientShortcutForHasXPathEqualTo() { assertThat('matches', self::$doc, hasXPath('count(user)', 3)); assertThat('matches', self::$doc, hasXPath('user[2]/id', 'bob')); } public function testProvidesConvenientShortcutForHasXPathCountEqualTo() { assertThat('matches', self::$doc, hasXPath('user[id = "charlie"]', 1)); } public function testMatchesAcceptsXmlString() { assertThat('accepts XML string', self::$xml, hasXPath('user')); } public function testMatchesAcceptsHtmlString() { assertThat('accepts HTML string', self::$html, hasXPath('body/h1', 'Heading')); } public function testHasAReadableDescription() { $this->assertDescription( 'XML or HTML document with XPath "/users/user"', hasXPath('/users/user') ); $this->assertDescription( 'XML or HTML document with XPath "count(/users/user)" <2>', hasXPath('/users/user', 2) ); $this->assertDescription( 'XML or HTML document with XPath "/users/user/name"' . ' a string starting with "Alice"', hasXPath('/users/user/name', startsWith('Alice')) ); } public function testHasAReadableMismatchDescription() { $this->assertMismatchDescription( 'XPath returned no results', hasXPath('/users/name'), self::$doc ); $this->assertMismatchDescription( 'XPath expression result was <3F>', hasXPath('/users/user', 2), self::$doc ); $this->assertMismatchDescription( 'XPath returned ["alice", "bob", "charlie"]', hasXPath('/users/user/id', 'Frank'), self::$doc ); } } hamcrest-php/generator/FactoryMethod.php 0000644 00000013014 15233660706 0014415 0 ustar 00 <?php /* Copyright (c) 2009 hamcrest.org */ /** * Represents a single static factory method from a {@link Matcher} class. * * @todo Search method in file contents for func_get_args() to replace factoryVarArgs. */ class FactoryMethod { /** * @var FactoryClass */ private $class; /** * @var ReflectionMethod */ private $reflector; /** * @var array of string */ private $comment; /** * @var bool */ private $isVarArgs; /** * @var array of FactoryCall */ private $calls; /** * @var array FactoryParameter */ private $parameters; public function __construct(FactoryClass $class, ReflectionMethod $reflector) { $this->class = $class; $this->reflector = $reflector; $this->extractCommentWithoutLeadingShashesAndStars(); $this->extractFactoryNamesFromComment(); $this->extractParameters(); } public function extractCommentWithoutLeadingShashesAndStars() { $this->comment = explode("\n", $this->reflector->getDocComment()); foreach ($this->comment as &$line) { $line = preg_replace('#^\s*(/\\*+|\\*+/|\\*)\s?#', '', $line); } $this->trimLeadingBlankLinesFromComment(); $this->trimTrailingBlankLinesFromComment(); } public function trimLeadingBlankLinesFromComment() { while (count($this->comment) > 0) { $line = array_shift($this->comment); if (trim($line) != '') { array_unshift($this->comment, $line); break; } } } public function trimTrailingBlankLinesFromComment() { while (count($this->comment) > 0) { $line = array_pop($this->comment); if (trim($line) != '') { array_push($this->comment, $line); break; } } } public function extractFactoryNamesFromComment() { $this->calls = array(); for ($i = 0; $i < count($this->comment); $i++) { if ($this->extractFactoryNamesFromLine($this->comment[$i])) { unset($this->comment[$i]); } } $this->trimTrailingBlankLinesFromComment(); } public function extractFactoryNamesFromLine($line) { if (preg_match('/^\s*@factory(\s+(.+))?$/', $line, $match)) { $this->createCalls( $this->extractFactoryNamesFromAnnotation( isset($match[2]) ? trim($match[2]) : null ) ); return true; } return false; } public function extractFactoryNamesFromAnnotation($value) { $primaryName = $this->reflector->getName(); if (empty($value)) { return array($primaryName); } preg_match_all('/(\.{3}|-|[a-zA-Z_][a-zA-Z_0-9]*)/', $value, $match); $names = $match[0]; if (in_array('...', $names)) { $this->isVarArgs = true; } if (!in_array('-', $names) && !in_array($primaryName, $names)) { array_unshift($names, $primaryName); } return $names; } public function createCalls(array $names) { $names = array_unique($names); foreach ($names as $name) { if ($name != '-' && $name != '...') { $this->calls[] = new FactoryCall($this, $name); } } } public function extractParameters() { $this->parameters = array(); if (!$this->isVarArgs) { foreach ($this->reflector->getParameters() as $parameter) { $this->parameters[] = new FactoryParameter($this, $parameter); } } } public function getParameterDeclarations() { if ($this->isVarArgs || !$this->hasParameters()) { return ''; } $params = array(); foreach ($this->parameters as /** @var $parameter FactoryParameter */ $parameter) { $params[] = $parameter->getDeclaration(); } return implode(', ', $params); } public function getParameterInvocations() { if ($this->isVarArgs) { return ''; } $params = array(); foreach ($this->parameters as $parameter) { $params[] = $parameter->getInvocation(); } return implode(', ', $params); } public function getClass() { return $this->class; } public function getClassName() { return $this->class->getName(); } public function getName() { return $this->reflector->name; } public function isFactory() { return count($this->calls) > 0; } public function getCalls() { return $this->calls; } public function acceptsVariableArguments() { return $this->isVarArgs; } public function hasParameters() { return !empty($this->parameters); } public function getParameters() { return $this->parameters; } public function getFullName() { return $this->getClassName() . '::' . $this->getName(); } public function getCommentText() { return implode("\n", $this->comment); } public function getComment($indent = '') { $comment = $indent . '/**'; foreach ($this->comment as $line) { $comment .= "\n" . rtrim($indent . ' * ' . $line); } $comment .= "\n" . $indent . ' */'; return $comment; } } hamcrest-php/generator/StaticMethodFile.php 0000644 00000001405 15233660706 0015036 0 ustar 00 <?php /* Copyright (c) 2009 hamcrest.org */ class StaticMethodFile extends FactoryFile { /** * @var string containing method definitions */ private $methods; public function __construct($file) { parent::__construct($file, ' '); $this->methods = ''; } public function addCall(FactoryCall $call) { $this->methods .= PHP_EOL . $this->generateFactoryCall($call); } public function getDeclarationModifiers() { return 'public static '; } public function build() { $this->addFileHeader(); $this->addPart('matchers_imports'); $this->addPart('matchers_header'); $this->addCode($this->methods); $this->addPart('matchers_footer'); } } hamcrest-php/generator/run.php 0000644 00000002073 15233660706 0012454 0 ustar 00 <?php /* Copyright (c) 2009 hamcrest.org */ require __DIR__ . '/../vendor/autoload.php'; /* * Generates the Hamcrest\Matchers factory class and factory functions * from the @factory doctags in the various matchers. */ define('GENERATOR_BASE', __DIR__); define('HAMCREST_BASE', realpath(dirname(GENERATOR_BASE) . DIRECTORY_SEPARATOR . 'hamcrest')); define('GLOBAL_FUNCTIONS_FILE', HAMCREST_BASE . DIRECTORY_SEPARATOR . 'Hamcrest.php'); define('STATIC_MATCHERS_FILE', HAMCREST_BASE . DIRECTORY_SEPARATOR . 'Hamcrest' . DIRECTORY_SEPARATOR . 'Matchers.php'); set_include_path( implode( PATH_SEPARATOR, array( GENERATOR_BASE, HAMCREST_BASE, get_include_path() ) ) ); @unlink(GLOBAL_FUNCTIONS_FILE); @unlink(STATIC_MATCHERS_FILE); $generator = new FactoryGenerator(HAMCREST_BASE . DIRECTORY_SEPARATOR . 'Hamcrest'); $generator->addFactoryFile(new StaticMethodFile(STATIC_MATCHERS_FILE)); $generator->addFactoryFile(new GlobalFunctionFile(GLOBAL_FUNCTIONS_FILE)); $generator->generate(); $generator->write(); hamcrest-php/generator/FactoryParameter.php 0000644 00000006723 15233660706 0015126 0 ustar 00 <?php /* Copyright (c) 2009 hamcrest.org */ class FactoryParameter { /** * @var FactoryMethod */ private $method; /** * @var ReflectionParameter */ private $reflector; public function __construct(FactoryMethod $method, ReflectionParameter $reflector) { $this->method = $method; $this->reflector = $reflector; } /** * Compute the declaration code. * * @return string */ public function getDeclaration() { $code = $this->getTypeCode() . $this->getInvocation(); if ($this->reflector->isOptional()) { $default = $this->reflector->getDefaultValue(); if (is_null($default)) { $default = 'null'; } elseif (is_bool($default)) { $default = $default ? 'true' : 'false'; } elseif (is_string($default)) { $default = "'" . $default . "'"; } elseif (is_numeric($default)) { $default = strval($default); } elseif (is_array($default)) { $default = 'array()'; } else { echo 'Warning: unknown default type for ' . $this->getMethod()->getFullName() . "\n"; var_dump($default); $default = 'null'; } $code .= ' = ' . $default; } return $code; } /** * Compute the type code for the paramater. * * @return string */ private function getTypeCode() { // Handle PHP 5 separately if (PHP_VERSION_ID < 70000) { if ($this->reflector->isArray()) { return 'array'; } $class = $this->reflector->getClass(); return $class ? sprintf('\\%s ', $class->getName()) : ''; } if (!$this->reflector->hasType()) { return ''; } $type = $this->reflector->getType(); $name = self::getQualifiedName($type); // PHP 7.1+ supports nullable types via a leading question mark return (PHP_VERSION_ID >= 70100 && $type->allowsNull()) ? sprintf('?%s ', $name) : sprintf('%s ', $name); } /** * Compute qualified name for the given type. * * This function knows how to prefix class names with a leading slash and * also how to handle PHP 8's union types. * * @param ReflectionType $type * * @return string */ private static function getQualifiedName(ReflectionType $type) { // PHP 8 union types can be recursively processed if ($type instanceof ReflectionUnionType) { return implode('|', array_map(function (ReflectionType $type) { // The "self::" call within a Closure is fine here because this // code will only ever be executed on PHP 7.0+ return self::getQualifiedName($type); }, $type->getTypes())); } // PHP 7.0 doesn't have named types, but 7.1+ does $name = $type instanceof ReflectionNamedType ? $type->getName() : (string) $type; return $type->isBuiltin() ? $name : sprintf('\\%s', $name); } /** * Compute the invocation code. * * @return string */ public function getInvocation() { return sprintf('$%s', $this->reflector->getName()); } /** * Compute the method name. * * @return string */ public function getMethod() { return $this->method; } } hamcrest-php/generator/parts/functions_header.txt 0000644 00000001216 15233660706 0016347 0 ustar 00 if (!function_exists('assertThat')) { /** * Make an assertion and throw {@link Hamcrest_AssertionError} if it fails. * * Example: * <pre> * //With an identifier * assertThat("assertion identifier", $apple->flavour(), equalTo("tasty")); * //Without an identifier * assertThat($apple->flavour(), equalTo("tasty")); * //Evaluating a boolean expression * assertThat("some error", $a > $b); * </pre> */ function assertThat() { $args = func_get_args(); call_user_func_array( array('Hamcrest\MatcherAssert', 'assertThat'), $args ); } } hamcrest-php/generator/parts/file_header.txt 0000644 00000000170 15233660706 0015254 0 ustar 00 <?php /* Copyright (c) 2009-2010 hamcrest.org */ // This file is generated from the static method @factory doctags. hamcrest-php/generator/parts/functions_imports.txt 0000644 00000000000 15233660706 0016602 0 ustar 00 hamcrest-php/generator/parts/functions_footer.txt 0000644 00000000000 15233660706 0016403 0 ustar 00 hamcrest-php/generator/parts/matchers_header.txt 0000644 00000000126 15233660706 0016144 0 ustar 00 /** * A series of static factories for all hamcrest matchers. */ class Matchers { hamcrest-php/generator/parts/matchers_footer.txt 0000644 00000000002 15233660706 0016203 0 ustar 00 } hamcrest-php/generator/parts/matchers_imports.txt 0000644 00000000024 15233660706 0016406 0 ustar 00 namespace Hamcrest; hamcrest-php/generator/FactoryFile.php 0000644 00000005720 15233660706 0014061 0 ustar 00 <?php /* Copyright (c) 2009 hamcrest.org */ abstract class FactoryFile { /** * Hamcrest standard is two spaces for each level of indentation. * * @var string */ const INDENT = ' '; private $indent; private $file; private $code; public function __construct($file, $indent) { $this->file = $file; $this->indent = $indent; } abstract public function addCall(FactoryCall $call); abstract public function build(); public function addFileHeader() { $this->code = ''; $this->addPart('file_header'); } public function addPart($name) { $this->addCode($this->readPart($name)); } public function addCode($code) { $this->code .= $code; } public function readPart($name) { return file_get_contents(__DIR__ . "/parts/$name.txt"); } public function generateFactoryCall(FactoryCall $call) { $method = $call->getMethod(); $code = $method->getComment($this->indent) . "\n"; $code .= $this->generateDeclaration($call->getName(), $method); $code .= $this->generateCall($method); $code .= $this->generateClosing(); return $code; } public function generateDeclaration($name, FactoryMethod $method) { $code = $this->indent . $this->getDeclarationModifiers() . 'function ' . $name . '(' . $this->generateDeclarationArguments($method) . ')' . "\n" . $this->indent . '{' . "\n"; return $code; } public function getDeclarationModifiers() { return ''; } public function generateDeclarationArguments(FactoryMethod $method) { if ($method->acceptsVariableArguments()) { return '/* args... */'; } else { return $method->getParameterDeclarations(); } } public function generateImport(FactoryMethod $method) { return $this->indent . self::INDENT . "require_once '" . $method->getClass()->getFile() . "';" . "\n"; } public function generateCall(FactoryMethod $method) { $code = ''; if ($method->acceptsVariableArguments()) { $code .= $this->indent . self::INDENT . '$args = func_get_args();' . "\n"; } $code .= $this->indent . self::INDENT . 'return '; if ($method->acceptsVariableArguments()) { $code .= 'call_user_func_array(array(\'' . '\\' . $method->getClassName() . '\', \'' . $method->getName() . '\'), $args);' . "\n"; } else { $code .= '\\' . $method->getClassName() . '::' . $method->getName() . '(' . $method->getParameterInvocations() . ');' . "\n"; } return $code; } public function generateClosing() { return $this->indent . '}' . "\n"; } public function write() { file_put_contents($this->file, $this->code); } } hamcrest-php/generator/FactoryCall.php 0000644 00000001143 15233660706 0014050 0 ustar 00 <?php /* Copyright (c) 2009 hamcrest.org */ class FactoryCall { /** * Hamcrest standard is two spaces for each level of indentation. * * @var string */ const INDENT = ' '; /** * @var FactoryMethod */ private $method; /** * @var string */ private $name; public function __construct(FactoryMethod $method, $name) { $this->method = $method; $this->name = $name; } public function getMethod() { return $this->method; } public function getName() { return $this->name; } } hamcrest-php/generator/GlobalFunctionFile.php 0000644 00000001642 15233660706 0015357 0 ustar 00 <?php /* Copyright (c) 2009 hamcrest.org */ class GlobalFunctionFile extends FactoryFile { /** * @var string containing function definitions */ private $functions; public function __construct($file) { parent::__construct($file, ' '); $this->functions = ''; } public function addCall(FactoryCall $call) { $this->functions .= "\n" . $this->generateFactoryCall($call); } public function build() { $this->addFileHeader(); $this->addPart('functions_imports'); $this->addPart('functions_header'); $this->addCode($this->functions); $this->addPart('functions_footer'); } public function generateFactoryCall(FactoryCall $call) { $code = "if (!function_exists('{$call->getName()}')) {\n"; $code.= parent::generateFactoryCall($call); $code.= "}\n"; return $code; } } hamcrest-php/generator/FactoryClass.php 0000644 00000002552 15233660706 0014247 0 ustar 00 <?php /* Copyright (c) 2009 hamcrest.org */ class FactoryClass { /** * @var string */ private $file; /** * @var ReflectionClass */ private $reflector; /** * @var array */ private $methods; public function __construct($file, ReflectionClass $class) { $this->file = $file; $this->reflector = $class; $this->extractFactoryMethods(); } public function extractFactoryMethods() { $this->methods = array(); foreach ($this->getPublicStaticMethods() as $method) { if ($method->isFactory()) { $this->methods[] = $method; } } } public function getPublicStaticMethods() { $methods = array(); foreach ($this->reflector->getMethods(ReflectionMethod::IS_STATIC) as $method) { if ($method->isPublic() && $method->getDeclaringClass() == $this->reflector) { $methods[] = new FactoryMethod($this, $method); } } return $methods; } public function getFile() { return $this->file; } public function getName() { return $this->reflector->name; } public function isFactory() { return !empty($this->methods); } public function getMethods() { return $this->methods; } } hamcrest-php/generator/FactoryGenerator.php 0000644 00000005664 15233660706 0015137 0 ustar 00 <?php /* Copyright (c) 2009 hamcrest.org */ /** * Controls the process of extracting @factory doctags * and generating factory method files. * * Uses File_Iterator to scan for PHP files. */ class FactoryGenerator { /** * Path to the Hamcrest PHP files to process. * * @var string */ private $path; /** * @var array of FactoryFile */ private $factoryFiles; public function __construct($path) { $this->path = $path; $this->factoryFiles = array(); } public function addFactoryFile(FactoryFile $factoryFile) { $this->factoryFiles[] = $factoryFile; } public function generate() { $classes = $this->getClassesWithFactoryMethods(); foreach ($classes as $class) { foreach ($class->getMethods() as $method) { foreach ($method->getCalls() as $call) { foreach ($this->factoryFiles as $file) { $file->addCall($call); } } } } } public function write() { foreach ($this->factoryFiles as $file) { $file->build(); $file->write(); } } public function getClassesWithFactoryMethods() { $classes = array(); $files = $this->getSortedFiles(); foreach ($files as $file) { $class = $this->getFactoryClass($file); if ($class !== null) { $classes[] = $class; } } return $classes; } public function getSortedFiles() { $iter = $this->getFileIterator(); $files = array(); foreach ($iter as $file) { $files[] = $file; } sort($files, SORT_STRING); return $files; } private function getFileIterator() { $factoryClass = class_exists('File_Iterator_Factory') ? 'File_Iterator_Factory' : 'SebastianBergmann\FileIterator\Factory'; $factory = new $factoryClass(); return $factory->getFileIterator($this->path, '.php'); } public function getFactoryClass($file) { $name = $this->getFactoryClassName($file); if ($name !== null) { require_once $file; if (class_exists($name)) { $class = new FactoryClass(substr($file, strpos($file, 'Hamcrest/')), new ReflectionClass($name)); if ($class->isFactory()) { return $class; } } } return null; } public function getFactoryClassName($file) { $content = file_get_contents($file); if (preg_match('/namespace\s+(.+);/', $content, $namespace) && preg_match('/\n\s*class\s+(\w+)\s+extends\b/', $content, $className) && preg_match('/@factory\b/', $content) ) { return $namespace[1] . '\\' . $className[1]; } return null; } } hamcrest-php/.coveralls.yml 0000644 00000000022 15233660706 0011734 0 ustar 00 src_dir: hamcrest hamcrest-php/.travis.yml 0000644 00000000574 15233660706 0011266 0 ustar 00 language: php dist: trusty matrix: include: - name: PHP 5.3 php: 5.3 dist: precise - name: PHP 5.4 php: 5.4 - name: PHP 5.5 php: 5.5 - name: PHP 5.6 php: 5.6 - name: HHVM 3.18 php: hhvm-3.18 install: - travis_retry composer update --prefer-dist --no-progress script: - vendor/bin/phpunit -c tests/phpunit.xml.dist hamcrest-php/.gitignore 0000644 00000000025 15233660706 0011134 0 ustar 00 composer.lock vendor hamcrest-php/.gush.yml 0000644 00000000270 15233660706 0010715 0 ustar 00 adapter: github issue_tracker: github meta-header: "Copyright (c) 2009-2015 hamcrest.org" table-pr: fixed_tickets: ['Fixed Tickets', ''] license: ['License', MIT] base: master hamcrest-php/LICENSE.txt 0000644 00000002712 15233660706 0010774 0 ustar 00 BSD License Copyright (c) 2000-2014, www.hamcrest.org All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of Hamcrest nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. hamcrest-php/composer.json 0000644 00000001246 15233660706 0011674 0 ustar 00 { "name": "hamcrest/hamcrest-php", "type": "library", "description": "This is the PHP port of Hamcrest Matchers", "keywords": ["test"], "license": "BSD-3-Clause", "authors": [ ], "autoload": { "classmap": ["hamcrest"] }, "autoload-dev": { "classmap": ["tests", "generator"] }, "require": { "php": "^5.3|^7.0|^8.0" }, "require-dev": { "phpunit/php-file-iterator": "^1.4 || ^2.0", "phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0" }, "replace": { "kodova/hamcrest-php": "*", "davedevelopment/hamcrest-php": "*", "cordoval/hamcrest-php": "*" }, "extra": { "branch-alias": { "dev-master": "2.1-dev" } } } hamcrest-php/README.md 0000644 00000025255 15233660706 0010437 0 ustar 00 This is the PHP port of Hamcrest Matchers ========================================= [](https://travis-ci.org/hamcrest/hamcrest-php) 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 arary 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 emtpy ```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 givem 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 scaler 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)); ``` hamcrest-php/hamcrest/Hamcrest.php 0000644 00000052151 15233660706 0013240 0 ustar 00 <?php /* Copyright (c) 2009-2010 hamcrest.org */ // This file is generated from the static method @factory doctags. if (!function_exists('assertThat')) { /** * Make an assertion and throw {@link Hamcrest_AssertionError} if it fails. * * Example: * <pre> * //With an identifier * assertThat("assertion identifier", $apple->flavour(), equalTo("tasty")); * //Without an identifier * assertThat($apple->flavour(), equalTo("tasty")); * //Evaluating a boolean expression * assertThat("some error", $a > $b); * </pre> */ function assertThat() { $args = func_get_args(); call_user_func_array( array('Hamcrest\MatcherAssert', 'assertThat'), $args ); } } if (!function_exists('anArray')) { /** * Evaluates to true only if each $matcher[$i] is satisfied by $array[$i]. */ function anArray(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArray', 'anArray'), $args); } } if (!function_exists('hasItemInArray')) { /** * 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 */ function hasItemInArray($item) { return \Hamcrest\Arrays\IsArrayContaining::hasItemInArray($item); } } if (!function_exists('hasValue')) { /** * 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 */ function hasValue($item) { return \Hamcrest\Arrays\IsArrayContaining::hasItemInArray($item); } } if (!function_exists('arrayContainingInAnyOrder')) { /** * An array with elements that match the given matchers. */ function arrayContainingInAnyOrder(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInAnyOrder', 'arrayContainingInAnyOrder'), $args); } } if (!function_exists('containsInAnyOrder')) { /** * An array with elements that match the given matchers. */ function containsInAnyOrder(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInAnyOrder', 'arrayContainingInAnyOrder'), $args); } } if (!function_exists('arrayContaining')) { /** * An array with elements that match the given matchers in the same order. */ function arrayContaining(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInOrder', 'arrayContaining'), $args); } } if (!function_exists('contains')) { /** * An array with elements that match the given matchers in the same order. */ function contains(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInOrder', 'arrayContaining'), $args); } } if (!function_exists('hasKeyInArray')) { /** * 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 */ function hasKeyInArray($key) { return \Hamcrest\Arrays\IsArrayContainingKey::hasKeyInArray($key); } } if (!function_exists('hasKey')) { /** * 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 */ function hasKey($key) { return \Hamcrest\Arrays\IsArrayContainingKey::hasKeyInArray($key); } } if (!function_exists('hasKeyValuePair')) { /** * Test if an array has both an key and value in parity with each other. */ function hasKeyValuePair($key, $value) { return \Hamcrest\Arrays\IsArrayContainingKeyValuePair::hasKeyValuePair($key, $value); } } if (!function_exists('hasEntry')) { /** * Test if an array has both an key and value in parity with each other. */ function hasEntry($key, $value) { return \Hamcrest\Arrays\IsArrayContainingKeyValuePair::hasKeyValuePair($key, $value); } } if (!function_exists('arrayWithSize')) { /** * Does array size satisfy a given matcher? * * @param \Hamcrest\Matcher|int $size as a {@link Hamcrest\Matcher} or a value. * * @return \Hamcrest\Arrays\IsArrayWithSize */ function arrayWithSize($size) { return \Hamcrest\Arrays\IsArrayWithSize::arrayWithSize($size); } } if (!function_exists('emptyArray')) { /** * Matches an empty array. */ function emptyArray() { return \Hamcrest\Arrays\IsArrayWithSize::emptyArray(); } } if (!function_exists('nonEmptyArray')) { /** * Matches an empty array. */ function nonEmptyArray() { return \Hamcrest\Arrays\IsArrayWithSize::nonEmptyArray(); } } if (!function_exists('emptyTraversable')) { /** * Returns true if traversable is empty. */ function emptyTraversable() { return \Hamcrest\Collection\IsEmptyTraversable::emptyTraversable(); } } if (!function_exists('nonEmptyTraversable')) { /** * Returns true if traversable is not empty. */ function nonEmptyTraversable() { return \Hamcrest\Collection\IsEmptyTraversable::nonEmptyTraversable(); } } if (!function_exists('traversableWithSize')) { /** * Does traversable size satisfy a given matcher? */ function traversableWithSize($size) { return \Hamcrest\Collection\IsTraversableWithSize::traversableWithSize($size); } } if (!function_exists('allOf')) { /** * Evaluates to true only if ALL of the passed in matchers evaluate to true. */ function allOf(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\AllOf', 'allOf'), $args); } } if (!function_exists('anyOf')) { /** * Evaluates to true if ANY of the passed in matchers evaluate to true. */ function anyOf(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\AnyOf', 'anyOf'), $args); } } if (!function_exists('noneOf')) { /** * Evaluates to false if ANY of the passed in matchers evaluate to true. */ function noneOf(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\AnyOf', 'noneOf'), $args); } } if (!function_exists('both')) { /** * This is useful for fluently combining matchers that must both pass. * For example: * <pre> * assertThat($string, both(containsString("a"))->andAlso(containsString("b"))); * </pre> */ function both(\Hamcrest\Matcher $matcher) { return \Hamcrest\Core\CombinableMatcher::both($matcher); } } if (!function_exists('either')) { /** * This is useful for fluently combining matchers where either may pass, * for example: * <pre> * assertThat($string, either(containsString("a"))->orElse(containsString("b"))); * </pre> */ function either(\Hamcrest\Matcher $matcher) { return \Hamcrest\Core\CombinableMatcher::either($matcher); } } if (!function_exists('describedAs')) { /** * Wraps an existing matcher and overrides the description when it fails. */ function describedAs(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\DescribedAs', 'describedAs'), $args); } } if (!function_exists('everyItem')) { /** * @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 */ function everyItem(\Hamcrest\Matcher $itemMatcher) { return \Hamcrest\Core\Every::everyItem($itemMatcher); } } if (!function_exists('hasToString')) { /** * Does array size satisfy a given matcher? */ function hasToString($matcher) { return \Hamcrest\Core\HasToString::hasToString($matcher); } } if (!function_exists('is')) { /** * 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))) */ function is($value) { return \Hamcrest\Core\Is::is($value); } } if (!function_exists('anything')) { /** * This matcher always evaluates to true. * * @param string $description A meaningful string used when describing itself. * * @return \Hamcrest\Core\IsAnything */ function anything($description = 'ANYTHING') { return \Hamcrest\Core\IsAnything::anything($description); } } if (!function_exists('hasItem')) { /** * 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> */ function hasItem(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\IsCollectionContaining', 'hasItem'), $args); } } if (!function_exists('hasItems')) { /** * Test if the value is an array containing elements that match all of these * matchers. * * Example: * <pre> * assertThat(array('a', 'b', 'c'), hasItems(equalTo('a'), equalTo('b'))); * </pre> */ function hasItems(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\IsCollectionContaining', 'hasItems'), $args); } } if (!function_exists('equalTo')) { /** * Is the value equal to another value, as tested by the use of the "==" * comparison operator? */ function equalTo($item) { return \Hamcrest\Core\IsEqual::equalTo($item); } } if (!function_exists('identicalTo')) { /** * Tests of the value is identical to $value as tested by the "===" operator. */ function identicalTo($value) { return \Hamcrest\Core\IsIdentical::identicalTo($value); } } if (!function_exists('anInstanceOf')) { /** * Is the value an instance of a particular type? * This version assumes no relationship between the required type and * the signature of the method that sets it up, for example in * <code>assertThat($anObject, anInstanceOf('Thing'));</code> */ function anInstanceOf($theClass) { return \Hamcrest\Core\IsInstanceOf::anInstanceOf($theClass); } } if (!function_exists('any')) { /** * Is the value an instance of a particular type? * This version assumes no relationship between the required type and * the signature of the method that sets it up, for example in * <code>assertThat($anObject, anInstanceOf('Thing'));</code> */ function any($theClass) { return \Hamcrest\Core\IsInstanceOf::anInstanceOf($theClass); } } if (!function_exists('not')) { /** * Matches if value does not match $value. */ function not($value) { return \Hamcrest\Core\IsNot::not($value); } } if (!function_exists('nullValue')) { /** * Matches if value is null. */ function nullValue() { return \Hamcrest\Core\IsNull::nullValue(); } } if (!function_exists('notNullValue')) { /** * Matches if value is not null. */ function notNullValue() { return \Hamcrest\Core\IsNull::notNullValue(); } } if (!function_exists('sameInstance')) { /** * 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 */ function sameInstance($object) { return \Hamcrest\Core\IsSame::sameInstance($object); } } if (!function_exists('typeOf')) { /** * Is the value a particular built-in type? */ function typeOf($theType) { return \Hamcrest\Core\IsTypeOf::typeOf($theType); } } if (!function_exists('set')) { /** * Matches if value (class, object, or array) has named $property. */ function set($property) { return \Hamcrest\Core\Set::set($property); } } if (!function_exists('notSet')) { /** * Matches if value (class, object, or array) does not have named $property. */ function notSet($property) { return \Hamcrest\Core\Set::notSet($property); } } if (!function_exists('closeTo')) { /** * Matches if value is a number equal to $value within some range of * acceptable error $delta. */ function closeTo($value, $delta) { return \Hamcrest\Number\IsCloseTo::closeTo($value, $delta); } } if (!function_exists('comparesEqualTo')) { /** * The value is not > $value, nor < $value. */ function comparesEqualTo($value) { return \Hamcrest\Number\OrderingComparison::comparesEqualTo($value); } } if (!function_exists('greaterThan')) { /** * The value is > $value. */ function greaterThan($value) { return \Hamcrest\Number\OrderingComparison::greaterThan($value); } } if (!function_exists('greaterThanOrEqualTo')) { /** * The value is >= $value. */ function greaterThanOrEqualTo($value) { return \Hamcrest\Number\OrderingComparison::greaterThanOrEqualTo($value); } } if (!function_exists('atLeast')) { /** * The value is >= $value. */ function atLeast($value) { return \Hamcrest\Number\OrderingComparison::greaterThanOrEqualTo($value); } } if (!function_exists('lessThan')) { /** * The value is < $value. */ function lessThan($value) { return \Hamcrest\Number\OrderingComparison::lessThan($value); } } if (!function_exists('lessThanOrEqualTo')) { /** * The value is <= $value. */ function lessThanOrEqualTo($value) { return \Hamcrest\Number\OrderingComparison::lessThanOrEqualTo($value); } } if (!function_exists('atMost')) { /** * The value is <= $value. */ function atMost($value) { return \Hamcrest\Number\OrderingComparison::lessThanOrEqualTo($value); } } if (!function_exists('isEmptyString')) { /** * Matches if value is a zero-length string. */ function isEmptyString() { return \Hamcrest\Text\IsEmptyString::isEmptyString(); } } if (!function_exists('emptyString')) { /** * Matches if value is a zero-length string. */ function emptyString() { return \Hamcrest\Text\IsEmptyString::isEmptyString(); } } if (!function_exists('isEmptyOrNullString')) { /** * Matches if value is null or a zero-length string. */ function isEmptyOrNullString() { return \Hamcrest\Text\IsEmptyString::isEmptyOrNullString(); } } if (!function_exists('nullOrEmptyString')) { /** * Matches if value is null or a zero-length string. */ function nullOrEmptyString() { return \Hamcrest\Text\IsEmptyString::isEmptyOrNullString(); } } if (!function_exists('isNonEmptyString')) { /** * Matches if value is a non-zero-length string. */ function isNonEmptyString() { return \Hamcrest\Text\IsEmptyString::isNonEmptyString(); } } if (!function_exists('nonEmptyString')) { /** * Matches if value is a non-zero-length string. */ function nonEmptyString() { return \Hamcrest\Text\IsEmptyString::isNonEmptyString(); } } if (!function_exists('equalToIgnoringCase')) { /** * Matches if value is a string equal to $string, regardless of the case. */ function equalToIgnoringCase($string) { return \Hamcrest\Text\IsEqualIgnoringCase::equalToIgnoringCase($string); } } if (!function_exists('equalToIgnoringWhiteSpace')) { /** * Matches if value is a string equal to $string, regardless of whitespace. */ function equalToIgnoringWhiteSpace($string) { return \Hamcrest\Text\IsEqualIgnoringWhiteSpace::equalToIgnoringWhiteSpace($string); } } if (!function_exists('matchesPattern')) { /** * Matches if value is a string that matches regular expression $pattern. */ function matchesPattern($pattern) { return \Hamcrest\Text\MatchesPattern::matchesPattern($pattern); } } if (!function_exists('containsString')) { /** * Matches if value is a string that contains $substring. */ function containsString($substring) { return \Hamcrest\Text\StringContains::containsString($substring); } } if (!function_exists('containsStringIgnoringCase')) { /** * Matches if value is a string that contains $substring regardless of the case. */ function containsStringIgnoringCase($substring) { return \Hamcrest\Text\StringContainsIgnoringCase::containsStringIgnoringCase($substring); } } if (!function_exists('stringContainsInOrder')) { /** * Matches if value contains $substrings in a constrained order. */ function stringContainsInOrder(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Text\StringContainsInOrder', 'stringContainsInOrder'), $args); } } if (!function_exists('endsWith')) { /** * Matches if value is a string that ends with $substring. */ function endsWith($substring) { return \Hamcrest\Text\StringEndsWith::endsWith($substring); } } if (!function_exists('startsWith')) { /** * Matches if value is a string that starts with $substring. */ function startsWith($substring) { return \Hamcrest\Text\StringStartsWith::startsWith($substring); } } if (!function_exists('arrayValue')) { /** * Is the value an array? */ function arrayValue() { return \Hamcrest\Type\IsArray::arrayValue(); } } if (!function_exists('booleanValue')) { /** * Is the value a boolean? */ function booleanValue() { return \Hamcrest\Type\IsBoolean::booleanValue(); } } if (!function_exists('boolValue')) { /** * Is the value a boolean? */ function boolValue() { return \Hamcrest\Type\IsBoolean::booleanValue(); } } if (!function_exists('callableValue')) { /** * Is the value callable? */ function callableValue() { return \Hamcrest\Type\IsCallable::callableValue(); } } if (!function_exists('doubleValue')) { /** * Is the value a float/double? */ function doubleValue() { return \Hamcrest\Type\IsDouble::doubleValue(); } } if (!function_exists('floatValue')) { /** * Is the value a float/double? */ function floatValue() { return \Hamcrest\Type\IsDouble::doubleValue(); } } if (!function_exists('integerValue')) { /** * Is the value an integer? */ function integerValue() { return \Hamcrest\Type\IsInteger::integerValue(); } } if (!function_exists('intValue')) { /** * Is the value an integer? */ function intValue() { return \Hamcrest\Type\IsInteger::integerValue(); } } if (!function_exists('numericValue')) { /** * Is the value a numeric? */ function numericValue() { return \Hamcrest\Type\IsNumeric::numericValue(); } } if (!function_exists('objectValue')) { /** * Is the value an object? */ function objectValue() { return \Hamcrest\Type\IsObject::objectValue(); } } if (!function_exists('anObject')) { /** * Is the value an object? */ function anObject() { return \Hamcrest\Type\IsObject::objectValue(); } } if (!function_exists('resourceValue')) { /** * Is the value a resource? */ function resourceValue() { return \Hamcrest\Type\IsResource::resourceValue(); } } if (!function_exists('scalarValue')) { /** * Is the value a scalar (boolean, integer, double, or string)? */ function scalarValue() { return \Hamcrest\Type\IsScalar::scalarValue(); } } if (!function_exists('stringValue')) { /** * Is the value a string? */ function stringValue() { return \Hamcrest\Type\IsString::stringValue(); } } if (!function_exists('hasXPath')) { /** * Wraps <code>$matcher</code> with {@link Hamcrest\Core\IsEqual) * if it's not a matcher and the XPath in <code>count()</code> * if it's an integer. */ function hasXPath($xpath, $matcher = null) { return \Hamcrest\Xml\HasXPath::hasXPath($xpath, $matcher); } } hamcrest-php/hamcrest/Hamcrest/NullDescription.php 0000644 00000001273 15233660706 0016355 0 ustar 00 <?php namespace Hamcrest; /* Copyright (c) 2009 hamcrest.org */ /** * Null implementation of {@link Hamcrest\Description}. */ class NullDescription implements Description { public function appendText($text) { return $this; } public function appendDescriptionOf(SelfDescribing $value) { return $this; } public function appendValue($value) { return $this; } public function appendValueList($start, $separator, $end, $values) { return $this; } public function appendList($start, $separator, $end, $values) { return $this; } public function __toString() { return ''; } } hamcrest-php/hamcrest/Hamcrest/Type/IsDouble.php 0000644 00000001053 15233660706 0015662 0 ustar 00 <?php namespace Hamcrest\Type; /* Copyright (c) 2010 hamcrest.org */ use Hamcrest\Core\IsTypeOf; /** * Tests whether the value is a float/double. * * PHP returns "double" for values of type "float". */ class IsDouble extends IsTypeOf { /** * Creates a new instance of IsDouble */ public function __construct() { parent::__construct('double'); } /** * Is the value a float/double? * * @factory floatValue */ public static function doubleValue() { return new self; } } hamcrest-php/hamcrest/Hamcrest/Type/IsCallable.php 0000644 00000001070 15233660706 0016146 0 ustar 00 <?php namespace Hamcrest\Type; /* Copyright (c) 2010 hamcrest.org */ use Hamcrest\Core\IsTypeOf; /** * Tests whether the value is callable. */ class IsCallable extends IsTypeOf { /** * Creates a new instance of IsCallable */ public function __construct() { parent::__construct('callable'); } public function matches($item) { return is_callable($item); } /** * Is the value callable? * * @factory */ public static function callableValue() { return new self; } } hamcrest-php/hamcrest/Hamcrest/Type/IsInteger.php 0000644 00000000756 15233660706 0016056 0 ustar 00 <?php namespace Hamcrest\Type; /* Copyright (c) 2010 hamcrest.org */ use Hamcrest\Core\IsTypeOf; /** * Tests whether the value is an integer. */ class IsInteger extends IsTypeOf { /** * Creates a new instance of IsInteger */ public function __construct() { parent::__construct('integer'); } /** * Is the value an integer? * * @factory intValue */ public static function integerValue() { return new self; } } hamcrest-php/hamcrest/Hamcrest/Type/IsObject.php 0000644 00000000750 15233660706 0015661 0 ustar 00 <?php namespace Hamcrest\Type; /* Copyright (c) 2010 hamcrest.org */ use Hamcrest\Core\IsTypeOf; /** * Tests whether the value is an object. */ class IsObject extends IsTypeOf { /** * Creates a new instance of IsObject */ public function __construct() { parent::__construct('object'); } /** * Is the value an object? * * @factory anObject */ public static function objectValue() { return new self; } } hamcrest-php/hamcrest/Hamcrest/Type/IsNumeric.php 0000644 00000002011 15233660706 0016045 0 ustar 00 <?php namespace Hamcrest\Type; /* Copyright (c) 2010 hamcrest.org */ use Hamcrest\Core\IsTypeOf; /** * Tests whether the value is numeric. */ class IsNumeric extends IsTypeOf { public function __construct() { parent::__construct('number'); } public function matches($item) { if ($this->isHexadecimal($item)) { return true; } return is_numeric($item); } /** * Return if the string passed is a valid hexadecimal number. * This check is necessary because PHP 7 doesn't recognize hexadecimal string as numeric anymore. * * @param mixed $item * @return boolean */ private function isHexadecimal($item) { if (is_string($item) && preg_match('/^0x(.*)$/', $item, $matches)) { return ctype_xdigit($matches[1]); } return false; } /** * Is the value a numeric? * * @factory */ public static function numericValue() { return new self; } } hamcrest-php/hamcrest/Hamcrest/Type/IsResource.php 0000644 00000000751 15233660706 0016243 0 ustar 00 <?php namespace Hamcrest\Type; /* Copyright (c) 2010 hamcrest.org */ use Hamcrest\Core\IsTypeOf; /** * Tests whether the value is a resource. */ class IsResource extends IsTypeOf { /** * Creates a new instance of IsResource */ public function __construct() { parent::__construct('resource'); } /** * Is the value a resource? * * @factory */ public static function resourceValue() { return new self; } } hamcrest-php/hamcrest/Hamcrest/Type/IsArray.php 0000644 00000000731 15233660706 0015530 0 ustar 00 <?php namespace Hamcrest\Type; /* Copyright (c) 2010 hamcrest.org */ use Hamcrest\Core\IsTypeOf; /** * Tests whether the value is an array. */ class IsArray extends IsTypeOf { /** * Creates a new instance of IsArray */ public function __construct() { parent::__construct('array'); } /** * Is the value an array? * * @factory */ public static function arrayValue() { return new self; } } hamcrest-php/hamcrest/Hamcrest/Type/IsScalar.php 0000644 00000001100 15233660706 0015646 0 ustar 00 <?php namespace Hamcrest\Type; /* Copyright (c) 2010 hamcrest.org */ use Hamcrest\Core\IsTypeOf; /** * Tests whether the value is a scalar (boolean, integer, double, or string). */ class IsScalar extends IsTypeOf { public function __construct() { parent::__construct('scalar'); } public function matches($item) { return is_scalar($item); } /** * Is the value a scalar (boolean, integer, double, or string)? * * @factory */ public static function scalarValue() { return new self; } } hamcrest-php/hamcrest/Hamcrest/Type/IsString.php 0000644 00000000735 15233660706 0015724 0 ustar 00 <?php namespace Hamcrest\Type; /* Copyright (c) 2010 hamcrest.org */ use Hamcrest\Core\IsTypeOf; /** * Tests whether the value is a string. */ class IsString extends IsTypeOf { /** * Creates a new instance of IsString */ public function __construct() { parent::__construct('string'); } /** * Is the value a string? * * @factory */ public static function stringValue() { return new self; } } hamcrest-php/hamcrest/Hamcrest/Type/IsBoolean.php 0000644 00000000755 15233660706 0016037 0 ustar 00 <?php namespace Hamcrest\Type; /* Copyright (c) 2010 hamcrest.org */ use Hamcrest\Core\IsTypeOf; /** * Tests whether the value is a boolean. */ class IsBoolean extends IsTypeOf { /** * Creates a new instance of IsBoolean */ public function __construct() { parent::__construct('boolean'); } /** * Is the value a boolean? * * @factory boolValue */ public static function booleanValue() { return new self; } } hamcrest-php/hamcrest/Hamcrest/SelfDescribing.php 0000644 00000001027 15233660706 0016117 0 ustar 00 <?php namespace Hamcrest; /* Copyright (c) 2009 hamcrest.org */ /** * The ability of an object to describe itself. */ interface SelfDescribing { /** * Generates a description of the object. The description may be part * of a description of a larger object of which this is just a component, * so it should be worded appropriately. * * @param \Hamcrest\Description $description * The description to be built or appended to. */ public function describeTo(Description $description); } hamcrest-php/hamcrest/Hamcrest/Arrays/IsArrayWithSize.php 0000644 00000002715 15233660706 0017543 0 ustar 00 <?php namespace Hamcrest\Arrays; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\Core\DescribedAs; use Hamcrest\Core\IsNot; use Hamcrest\FeatureMatcher; use Hamcrest\Matcher; use Hamcrest\Util; /** * Matches if array size satisfies a nested matcher. */ class IsArrayWithSize extends FeatureMatcher { public function __construct(Matcher $sizeMatcher) { parent::__construct( self::TYPE_ARRAY, null, $sizeMatcher, 'an array with size', 'array size' ); } protected function featureValueOf($array) { return count($array); } /** * 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)); } /** * Matches an empty array. * * @factory */ public static function emptyArray() { return DescribedAs::describedAs( 'an empty array', self::arrayWithSize(0) ); } /** * Matches an empty array. * * @factory */ public static function nonEmptyArray() { return DescribedAs::describedAs( 'a non-empty array', self::arrayWithSize(IsNot::not(0)) ); } } hamcrest-php/hamcrest/Hamcrest/Arrays/SeriesMatchingOnce.php 0000644 00000003454 15233660706 0020215 0 ustar 00 <?php namespace Hamcrest\Arrays; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\Description; use Hamcrest\Matcher; class SeriesMatchingOnce { private $_elementMatchers; private $_keys; private $_mismatchDescription; private $_nextMatchKey; public function __construct(array $elementMatchers, Description $mismatchDescription) { $this->_elementMatchers = $elementMatchers; $this->_keys = array_keys($elementMatchers); $this->_mismatchDescription = $mismatchDescription; } public function matches($item) { return $this->_isNotSurplus($item) && $this->_isMatched($item); } public function isFinished() { if (!empty($this->_elementMatchers)) { $nextMatcher = current($this->_elementMatchers); $this->_mismatchDescription->appendText('No item matched: ')->appendDescriptionOf($nextMatcher); return false; } return true; } // -- Private Methods private function _isNotSurplus($item) { if (empty($this->_elementMatchers)) { $this->_mismatchDescription->appendText('Not matched: ')->appendValue($item); return false; } return true; } private function _isMatched($item) { $this->_nextMatchKey = array_shift($this->_keys); $nextMatcher = array_shift($this->_elementMatchers); if (!$nextMatcher->matches($item)) { $this->_describeMismatch($nextMatcher, $item); return false; } return true; } private function _describeMismatch(Matcher $matcher, $item) { $this->_mismatchDescription->appendText('item with key ' . $this->_nextMatchKey . ': '); $matcher->describeMismatch($item, $this->_mismatchDescription); } } hamcrest-php/hamcrest/Hamcrest/Arrays/IsArrayContainingKeyValuePair.php 0000644 00000004323 15233660706 0022345 0 ustar 00 <?php namespace Hamcrest\Arrays; /** * Tests for the presence of both a key and value inside an array. */ use Hamcrest\Description; use Hamcrest\Matcher; use Hamcrest\TypeSafeMatcher; use Hamcrest\Util; /** * @namespace */ class IsArrayContainingKeyValuePair extends TypeSafeMatcher { private $_keyMatcher; private $_valueMatcher; public function __construct(Matcher $keyMatcher, Matcher $valueMatcher) { parent::__construct(self::TYPE_ARRAY); $this->_keyMatcher = $keyMatcher; $this->_valueMatcher = $valueMatcher; } protected function matchesSafely($array) { foreach ($array as $key => $value) { if ($this->_keyMatcher->matches($key) && $this->_valueMatcher->matches($value)) { return true; } } return false; } protected function describeMismatchSafely($array, Description $mismatchDescription) { //Not using appendValueList() so that keys can be shown $mismatchDescription->appendText('array was ') ->appendText('[') ; $loop = false; foreach ($array as $key => $value) { if ($loop) { $mismatchDescription->appendText(', '); } $mismatchDescription->appendValue($key)->appendText(' => ')->appendValue($value); $loop = true; } $mismatchDescription->appendText(']'); } public function describeTo(Description $description) { $description->appendText('array containing [') ->appendDescriptionOf($this->_keyMatcher) ->appendText(' => ') ->appendDescriptionOf($this->_valueMatcher) ->appendText(']') ; } /** * 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) ); } } hamcrest-php/hamcrest/Hamcrest/Arrays/IsArrayContainingInAnyOrder.php 0000644 00000002732 15233660706 0022020 0 ustar 00 <?php namespace Hamcrest\Arrays; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\Description; use Hamcrest\TypeSafeDiagnosingMatcher; use Hamcrest\Util; /** * Matches if an array contains a set of items satisfying nested matchers. */ class IsArrayContainingInAnyOrder extends TypeSafeDiagnosingMatcher { private $_elementMatchers; public function __construct(array $elementMatchers) { parent::__construct(self::TYPE_ARRAY); Util::checkAllAreMatchers($elementMatchers); $this->_elementMatchers = $elementMatchers; } protected function matchesSafelyWithDiagnosticDescription($array, Description $mismatchDescription) { $matching = new MatchingOnce($this->_elementMatchers, $mismatchDescription); foreach ($array as $element) { if (!$matching->matches($element)) { return false; } } return $matching->isFinished($array); } public function describeTo(Description $description) { $description->appendList('[', ', ', ']', $this->_elementMatchers) ->appendText(' in any order') ; } /** * An array with elements that match the given matchers. * * @factory containsInAnyOrder ... */ public static function arrayContainingInAnyOrder(/* args... */) { $args = func_get_args(); return new self(Util::createMatcherArray($args)); } } hamcrest-php/hamcrest/Hamcrest/Arrays/MatchingOnce.php 0000644 00000003126 15233660706 0017036 0 ustar 00 <?php namespace Hamcrest\Arrays; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\Description; class MatchingOnce { private $_elementMatchers; private $_mismatchDescription; public function __construct(array $elementMatchers, Description $mismatchDescription) { $this->_elementMatchers = $elementMatchers; $this->_mismatchDescription = $mismatchDescription; } public function matches($item) { return $this->_isNotSurplus($item) && $this->_isMatched($item); } public function isFinished($items) { if (empty($this->_elementMatchers)) { return true; } $this->_mismatchDescription ->appendText('No item matches: ')->appendList('', ', ', '', $this->_elementMatchers) ->appendText(' in ')->appendValueList('[', ', ', ']', $items) ; return false; } // -- Private Methods private function _isNotSurplus($item) { if (empty($this->_elementMatchers)) { $this->_mismatchDescription->appendText('Not matched: ')->appendValue($item); return false; } return true; } private function _isMatched($item) { /** @var $matcher \Hamcrest\Matcher */ foreach ($this->_elementMatchers as $i => $matcher) { if ($matcher->matches($item)) { unset($this->_elementMatchers[$i]); return true; } } $this->_mismatchDescription->appendText('Not matched: ')->appendValue($item); return false; } } hamcrest-php/hamcrest/Hamcrest/Arrays/IsArrayContaining.php 0000644 00000002731 15233660706 0020064 0 ustar 00 <?php namespace Hamcrest\Arrays; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\Description; use Hamcrest\Matcher; use Hamcrest\TypeSafeMatcher; use Hamcrest\Util; /** * Matches if an array contains an item satisfying a nested matcher. */ class IsArrayContaining extends TypeSafeMatcher { private $_elementMatcher; public function __construct(Matcher $elementMatcher) { parent::__construct(self::TYPE_ARRAY); $this->_elementMatcher = $elementMatcher; } protected function matchesSafely($array) { foreach ($array as $element) { if ($this->_elementMatcher->matches($element)) { return true; } } return false; } protected function describeMismatchSafely($array, Description $mismatchDescription) { $mismatchDescription->appendText('was ')->appendValue($array); } public function describeTo(Description $description) { $description ->appendText('an array containing ') ->appendDescriptionOf($this->_elementMatcher) ; } /** * 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)); } } hamcrest-php/hamcrest/Hamcrest/Arrays/IsArrayContainingInOrder.php 0000644 00000002560 15233660706 0021347 0 ustar 00 <?php namespace Hamcrest\Arrays; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\Description; use Hamcrest\TypeSafeDiagnosingMatcher; use Hamcrest\Util; /** * Matches if an array contains a set of items satisfying nested matchers. */ class IsArrayContainingInOrder extends TypeSafeDiagnosingMatcher { private $_elementMatchers; public function __construct(array $elementMatchers) { parent::__construct(self::TYPE_ARRAY); Util::checkAllAreMatchers($elementMatchers); $this->_elementMatchers = $elementMatchers; } protected function matchesSafelyWithDiagnosticDescription($array, Description $mismatchDescription) { $series = new SeriesMatchingOnce($this->_elementMatchers, $mismatchDescription); foreach ($array as $element) { if (!$series->matches($element)) { return false; } } return $series->isFinished(); } public function describeTo(Description $description) { $description->appendList('[', ', ', ']', $this->_elementMatchers); } /** * An array with elements that match the given matchers in the same order. * * @factory contains ... */ public static function arrayContaining(/* args... */) { $args = func_get_args(); return new self(Util::createMatcherArray($args)); } } hamcrest-php/hamcrest/Hamcrest/Arrays/IsArray.php 0000644 00000006330 15233660706 0016051 0 ustar 00 <?php namespace Hamcrest\Arrays; /* Copyright (c) 2009 hamcrest.org */ // NOTE: This class is not exactly a direct port of Java's since Java handles // arrays quite differently than PHP // TODO: Allow this to take matchers or values within the array use Hamcrest\Description; use Hamcrest\TypeSafeMatcher; use Hamcrest\Util; /** * Matcher for array whose elements satisfy a sequence of matchers. * The array size must equal the number of element matchers. */ class IsArray extends TypeSafeMatcher { private $_elementMatchers; public function __construct(array $elementMatchers) { parent::__construct(self::TYPE_ARRAY); Util::checkAllAreMatchers($elementMatchers); $this->_elementMatchers = $elementMatchers; } protected function matchesSafely($array) { if (array_keys($array) != array_keys($this->_elementMatchers)) { return false; } /** @var $matcher \Hamcrest\Matcher */ foreach ($this->_elementMatchers as $k => $matcher) { if (!$matcher->matches($array[$k])) { return false; } } return true; } protected function describeMismatchSafely($actual, Description $mismatchDescription) { if (count($actual) != count($this->_elementMatchers)) { $mismatchDescription->appendText('array length was ' . count($actual)); return; } elseif (array_keys($actual) != array_keys($this->_elementMatchers)) { $mismatchDescription->appendText('array keys were ') ->appendValueList( $this->descriptionStart(), $this->descriptionSeparator(), $this->descriptionEnd(), array_keys($actual) ) ; return; } /** @var $matcher \Hamcrest\Matcher */ foreach ($this->_elementMatchers as $k => $matcher) { if (!$matcher->matches($actual[$k])) { $mismatchDescription->appendText('element ')->appendValue($k) ->appendText(' was ')->appendValue($actual[$k]); return; } } } public function describeTo(Description $description) { $description->appendList( $this->descriptionStart(), $this->descriptionSeparator(), $this->descriptionEnd(), $this->_elementMatchers ); } /** * Evaluates to true only if each $matcher[$i] is satisfied by $array[$i]. * * @factory ... */ public static function anArray(/* args... */) { $args = func_get_args(); return new self(Util::createMatcherArray($args)); } // -- Protected Methods protected function descriptionStart() { return '['; } protected function descriptionSeparator() { return ', '; } protected function descriptionEnd() { return ']'; } } hamcrest-php/hamcrest/Hamcrest/Arrays/IsArrayContainingKey.php 0000644 00000003654 15233660706 0020542 0 ustar 00 <?php namespace Hamcrest\Arrays; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\Description; use Hamcrest\Matcher; use Hamcrest\TypeSafeMatcher; use Hamcrest\Util; /** * Matches if an array contains the specified key. */ class IsArrayContainingKey extends TypeSafeMatcher { private $_keyMatcher; public function __construct(Matcher $keyMatcher) { parent::__construct(self::TYPE_ARRAY); $this->_keyMatcher = $keyMatcher; } protected function matchesSafely($array) { foreach ($array as $key => $element) { if ($this->_keyMatcher->matches($key)) { return true; } } return false; } protected function describeMismatchSafely($array, Description $mismatchDescription) { //Not using appendValueList() so that keys can be shown $mismatchDescription->appendText('array was ') ->appendText('[') ; $loop = false; foreach ($array as $key => $value) { if ($loop) { $mismatchDescription->appendText(', '); } $mismatchDescription->appendValue($key)->appendText(' => ')->appendValue($value); $loop = true; } $mismatchDescription->appendText(']'); } public function describeTo(Description $description) { $description ->appendText('array with key ') ->appendDescriptionOf($this->_keyMatcher) ; } /** * 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)); } } hamcrest-php/hamcrest/Hamcrest/Matchers.php 0000644 00000045021 15233660706 0015004 0 ustar 00 <?php /* Copyright (c) 2009-2010 hamcrest.org */ // This file is generated from the static method @factory doctags. namespace Hamcrest; /** * A series of static factories for all hamcrest matchers. */ class Matchers { /** * Evaluates to true only if each $matcher[$i] is satisfied by $array[$i]. */ public static function anArray(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArray', 'anArray'), $args); } /** * 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 */ public static function hasItemInArray($item) { return \Hamcrest\Arrays\IsArrayContaining::hasItemInArray($item); } /** * 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 */ public static function hasValue($item) { return \Hamcrest\Arrays\IsArrayContaining::hasItemInArray($item); } /** * An array with elements that match the given matchers. */ public static function arrayContainingInAnyOrder(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInAnyOrder', 'arrayContainingInAnyOrder'), $args); } /** * An array with elements that match the given matchers. */ public static function containsInAnyOrder(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInAnyOrder', 'arrayContainingInAnyOrder'), $args); } /** * An array with elements that match the given matchers in the same order. */ public static function arrayContaining(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInOrder', 'arrayContaining'), $args); } /** * An array with elements that match the given matchers in the same order. */ public static function contains(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInOrder', 'arrayContaining'), $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 */ public static function hasKeyInArray($key) { return \Hamcrest\Arrays\IsArrayContainingKey::hasKeyInArray($key); } /** * 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 */ public static function hasKey($key) { return \Hamcrest\Arrays\IsArrayContainingKey::hasKeyInArray($key); } /** * Test if an array has both an key and value in parity with each other. */ public static function hasKeyValuePair($key, $value) { return \Hamcrest\Arrays\IsArrayContainingKeyValuePair::hasKeyValuePair($key, $value); } /** * Test if an array has both an key and value in parity with each other. */ public static function hasEntry($key, $value) { return \Hamcrest\Arrays\IsArrayContainingKeyValuePair::hasKeyValuePair($key, $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 */ public static function arrayWithSize($size) { return \Hamcrest\Arrays\IsArrayWithSize::arrayWithSize($size); } /** * Matches an empty array. */ public static function emptyArray() { return \Hamcrest\Arrays\IsArrayWithSize::emptyArray(); } /** * Matches an empty array. */ public static function nonEmptyArray() { return \Hamcrest\Arrays\IsArrayWithSize::nonEmptyArray(); } /** * Returns true if traversable is empty. */ public static function emptyTraversable() { return \Hamcrest\Collection\IsEmptyTraversable::emptyTraversable(); } /** * Returns true if traversable is not empty. */ public static function nonEmptyTraversable() { return \Hamcrest\Collection\IsEmptyTraversable::nonEmptyTraversable(); } /** * Does traversable size satisfy a given matcher? */ public static function traversableWithSize($size) { return \Hamcrest\Collection\IsTraversableWithSize::traversableWithSize($size); } /** * Evaluates to true only if ALL of the passed in matchers evaluate to true. */ public static function allOf(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\AllOf', 'allOf'), $args); } /** * Evaluates to true if ANY of the passed in matchers evaluate to true. */ public static function anyOf(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\AnyOf', 'anyOf'), $args); } /** * Evaluates to false if ANY of the passed in matchers evaluate to true. */ public static function noneOf(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\AnyOf', 'noneOf'), $args); } /** * This is useful for fluently combining matchers that must both pass. * For example: * <pre> * assertThat($string, both(containsString("a"))->andAlso(containsString("b"))); * </pre> */ public static function both(\Hamcrest\Matcher $matcher) { return \Hamcrest\Core\CombinableMatcher::both($matcher); } /** * This is useful for fluently combining matchers where either may pass, * for example: * <pre> * assertThat($string, either(containsString("a"))->orElse(containsString("b"))); * </pre> */ public static function either(\Hamcrest\Matcher $matcher) { return \Hamcrest\Core\CombinableMatcher::either($matcher); } /** * Wraps an existing matcher and overrides the description when it fails. */ public static function describedAs(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\DescribedAs', 'describedAs'), $args); } /** * @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 */ public static function everyItem(\Hamcrest\Matcher $itemMatcher) { return \Hamcrest\Core\Every::everyItem($itemMatcher); } /** * Does array size satisfy a given matcher? */ public static function hasToString($matcher) { return \Hamcrest\Core\HasToString::hasToString($matcher); } /** * 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))) */ public static function is($value) { return \Hamcrest\Core\Is::is($value); } /** * This matcher always evaluates to true. * * @param string $description A meaningful string used when describing itself. * * @return \Hamcrest\Core\IsAnything */ public static function anything($description = 'ANYTHING') { return \Hamcrest\Core\IsAnything::anything($description); } /** * 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> */ public static function hasItem(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\IsCollectionContaining', 'hasItem'), $args); } /** * Test if the value is an array containing elements that match all of these * matchers. * * Example: * <pre> * assertThat(array('a', 'b', 'c'), hasItems(equalTo('a'), equalTo('b'))); * </pre> */ public static function hasItems(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\IsCollectionContaining', 'hasItems'), $args); } /** * Is the value equal to another value, as tested by the use of the "==" * comparison operator? */ public static function equalTo($item) { return \Hamcrest\Core\IsEqual::equalTo($item); } /** * Tests of the value is identical to $value as tested by the "===" operator. */ public static function identicalTo($value) { return \Hamcrest\Core\IsIdentical::identicalTo($value); } /** * Is the value an instance of a particular type? * This version assumes no relationship between the required type and * the signature of the method that sets it up, for example in * <code>assertThat($anObject, anInstanceOf('Thing'));</code> */ public static function anInstanceOf($theClass) { return \Hamcrest\Core\IsInstanceOf::anInstanceOf($theClass); } /** * Is the value an instance of a particular type? * This version assumes no relationship between the required type and * the signature of the method that sets it up, for example in * <code>assertThat($anObject, anInstanceOf('Thing'));</code> */ public static function any($theClass) { return \Hamcrest\Core\IsInstanceOf::anInstanceOf($theClass); } /** * Matches if value does not match $value. */ public static function not($value) { return \Hamcrest\Core\IsNot::not($value); } /** * Matches if value is null. */ public static function nullValue() { return \Hamcrest\Core\IsNull::nullValue(); } /** * Matches if value is not null. */ public static function notNullValue() { return \Hamcrest\Core\IsNull::notNullValue(); } /** * 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 */ public static function sameInstance($object) { return \Hamcrest\Core\IsSame::sameInstance($object); } /** * Is the value a particular built-in type? */ public static function typeOf($theType) { return \Hamcrest\Core\IsTypeOf::typeOf($theType); } /** * Matches if value (class, object, or array) has named $property. */ public static function set($property) { return \Hamcrest\Core\Set::set($property); } /** * Matches if value (class, object, or array) does not have named $property. */ public static function notSet($property) { return \Hamcrest\Core\Set::notSet($property); } /** * Matches if value is a number equal to $value within some range of * acceptable error $delta. */ public static function closeTo($value, $delta) { return \Hamcrest\Number\IsCloseTo::closeTo($value, $delta); } /** * The value is not > $value, nor < $value. */ public static function comparesEqualTo($value) { return \Hamcrest\Number\OrderingComparison::comparesEqualTo($value); } /** * The value is > $value. */ public static function greaterThan($value) { return \Hamcrest\Number\OrderingComparison::greaterThan($value); } /** * The value is >= $value. */ public static function greaterThanOrEqualTo($value) { return \Hamcrest\Number\OrderingComparison::greaterThanOrEqualTo($value); } /** * The value is >= $value. */ public static function atLeast($value) { return \Hamcrest\Number\OrderingComparison::greaterThanOrEqualTo($value); } /** * The value is < $value. */ public static function lessThan($value) { return \Hamcrest\Number\OrderingComparison::lessThan($value); } /** * The value is <= $value. */ public static function lessThanOrEqualTo($value) { return \Hamcrest\Number\OrderingComparison::lessThanOrEqualTo($value); } /** * The value is <= $value. */ public static function atMost($value) { return \Hamcrest\Number\OrderingComparison::lessThanOrEqualTo($value); } /** * Matches if value is a zero-length string. */ public static function isEmptyString() { return \Hamcrest\Text\IsEmptyString::isEmptyString(); } /** * Matches if value is a zero-length string. */ public static function emptyString() { return \Hamcrest\Text\IsEmptyString::isEmptyString(); } /** * Matches if value is null or a zero-length string. */ public static function isEmptyOrNullString() { return \Hamcrest\Text\IsEmptyString::isEmptyOrNullString(); } /** * Matches if value is null or a zero-length string. */ public static function nullOrEmptyString() { return \Hamcrest\Text\IsEmptyString::isEmptyOrNullString(); } /** * Matches if value is a non-zero-length string. */ public static function isNonEmptyString() { return \Hamcrest\Text\IsEmptyString::isNonEmptyString(); } /** * Matches if value is a non-zero-length string. */ public static function nonEmptyString() { return \Hamcrest\Text\IsEmptyString::isNonEmptyString(); } /** * Matches if value is a string equal to $string, regardless of the case. */ public static function equalToIgnoringCase($string) { return \Hamcrest\Text\IsEqualIgnoringCase::equalToIgnoringCase($string); } /** * Matches if value is a string equal to $string, regardless of whitespace. */ public static function equalToIgnoringWhiteSpace($string) { return \Hamcrest\Text\IsEqualIgnoringWhiteSpace::equalToIgnoringWhiteSpace($string); } /** * Matches if value is a string that matches regular expression $pattern. */ public static function matchesPattern($pattern) { return \Hamcrest\Text\MatchesPattern::matchesPattern($pattern); } /** * Matches if value is a string that contains $substring. */ public static function containsString($substring) { return \Hamcrest\Text\StringContains::containsString($substring); } /** * Matches if value is a string that contains $substring regardless of the case. */ public static function containsStringIgnoringCase($substring) { return \Hamcrest\Text\StringContainsIgnoringCase::containsStringIgnoringCase($substring); } /** * Matches if value contains $substrings in a constrained order. */ public static function stringContainsInOrder(/* args... */) { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Text\StringContainsInOrder', 'stringContainsInOrder'), $args); } /** * Matches if value is a string that ends with $substring. */ public static function endsWith($substring) { return \Hamcrest\Text\StringEndsWith::endsWith($substring); } /** * Matches if value is a string that starts with $substring. */ public static function startsWith($substring) { return \Hamcrest\Text\StringStartsWith::startsWith($substring); } /** * Is the value an array? */ public static function arrayValue() { return \Hamcrest\Type\IsArray::arrayValue(); } /** * Is the value a boolean? */ public static function booleanValue() { return \Hamcrest\Type\IsBoolean::booleanValue(); } /** * Is the value a boolean? */ public static function boolValue() { return \Hamcrest\Type\IsBoolean::booleanValue(); } /** * Is the value callable? */ public static function callableValue() { return \Hamcrest\Type\IsCallable::callableValue(); } /** * Is the value a float/double? */ public static function doubleValue() { return \Hamcrest\Type\IsDouble::doubleValue(); } /** * Is the value a float/double? */ public static function floatValue() { return \Hamcrest\Type\IsDouble::doubleValue(); } /** * Is the value an integer? */ public static function integerValue() { return \Hamcrest\Type\IsInteger::integerValue(); } /** * Is the value an integer? */ public static function intValue() { return \Hamcrest\Type\IsInteger::integerValue(); } /** * Is the value a numeric? */ public static function numericValue() { return \Hamcrest\Type\IsNumeric::numericValue(); } /** * Is the value an object? */ public static function objectValue() { return \Hamcrest\Type\IsObject::objectValue(); } /** * Is the value an object? */ public static function anObject() { return \Hamcrest\Type\IsObject::objectValue(); } /** * Is the value a resource? */ public static function resourceValue() { return \Hamcrest\Type\IsResource::resourceValue(); } /** * Is the value a scalar (boolean, integer, double, or string)? */ public static function scalarValue() { return \Hamcrest\Type\IsScalar::scalarValue(); } /** * Is the value a string? */ public static function stringValue() { return \Hamcrest\Type\IsString::stringValue(); } /** * Wraps <code>$matcher</code> with {@link Hamcrest\Core\IsEqual) * if it's not a matcher and the XPath in <code>count()</code> * if it's an integer. */ public static function hasXPath($xpath, $matcher = null) { return \Hamcrest\Xml\HasXPath::hasXPath($xpath, $matcher); } } hamcrest-php/hamcrest/Hamcrest/BaseMatcher.php 0000644 00000001065 15233660706 0015414 0 ustar 00 <?php namespace Hamcrest; /* Copyright (c) 2009 hamcrest.org */ /** * BaseClass for all Matcher implementations. * * @see Hamcrest\Matcher */ abstract class BaseMatcher implements Matcher { public function describeMismatch($item, Description $description) { $description->appendText('was ')->appendValue($item); } public function __toString() { return StringDescription::toString($this); } public function __invoke() { return call_user_func_array(array($this, 'matches'), func_get_args()); } } hamcrest-php/hamcrest/Hamcrest/Core/IsAnything.php 0000644 00000001553 15233660706 0016205 0 ustar 00 <?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); } } hamcrest-php/hamcrest/Hamcrest/Core/IsNull.php 0000644 00000001720 15233660706 0015332 0 ustar 00 <?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; } } hamcrest-php/hamcrest/Hamcrest/Core/IsNot.php 0000644 00000001472 15233660706 0015164 0 ustar 00 <?php namespace Hamcrest\Core; /* Copyright (c) 2009 hamcrest.org */ use Hamcrest\BaseMatcher; use Hamcrest\Description; use Hamcrest\Matcher; use Hamcrest\Util; /** * Calculates the logical negation of a matcher. */ class IsNot 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('not ')->appendDescriptionOf($this->_matcher); } /** * Matches if value does not match $value. * * @factory */ public static function not($value) { return new self(Util::wrapValueWithIsEqual($value)); } } hamcrest-php/hamcrest/Hamcrest/Core/IsTypeOf.php 0000644 00000003221 15233660706 0015624 0 ustar 00 <?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); } } hamcrest-php/hamcrest/Hamcrest/Core/Every.php 0000644 00000002472 15233660706 0015223 0 ustar 00 <?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); } } hamcrest-php/hamcrest/Hamcrest/Core/ShortcutCombination.php 0000644 00000001630 15233660706 0020122 0 ustar 00 <?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); } } hamcrest-php/hamcrest/Hamcrest/Core/DescribedAs.php 0000644 00000003471 15233660706 0016301 0 ustar 00 <?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); } } hamcrest-php/hamcrest/Hamcrest/Core/Set.php 0000644 00000004550 15233660706 0014663 0 ustar 00 <?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); } } hamcrest-php/hamcrest/Hamcrest/Core/Is.php 0000644 00000002513 15233660706 0014500 0 ustar 00 <?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)); } } hamcrest-php/hamcrest/Hamcrest/Core/AnyOf.php 0000644 00000002356 15233660706 0015146 0 ustar 00 <?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)) ); } } hamcrest-php/hamcrest/Hamcrest/Core/IsSame.php 0000644 00000002106 15233660706 0015304 0 ustar 00 <?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); } } hamcrest-php/hamcrest/Hamcrest/Core/AllOf.php 0000644 00000002654 15233660706 0015130 0 ustar 00 <?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)); } } hamcrest-php/hamcrest/Hamcrest/Core/CombinableMatcher.php 0000644 00000003365 15233660706 0017472 0 ustar 00
| ver. 1.4 |
Github
|
.
| PHP 8.2.5 | Генерация страницы: 0.03 |
proxy
|
phpinfo
|
Настройка