PK t?VEX{_ phpunit.xml.distnu W+A
./test/unit
./test/integration
src/
PK t?VSI I LICENSEnu W+A Copyright 2014 Christopher Davis
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
PK t?VoD .travis.ymlnu W+A language: php
php:
- 5.4
- 5.5
- 5.6
install:
- composer install --prefer-source --dev
script: ./vendor/bin/phpunit
PK t?V*^
composer.jsonnu W+A {
"name": "counterpart/counterpart"
, "description": "A set of generic matchers -- for see if one value matches another"
, "tags": ["testing", "assert", "matcher"]
, "authors": [
{
"name": "Christopher Davis"
, "homepage": "http://christopherdavis.me"
, "role": "Developer"
}
]
, "require": {
"php": ">=5.4"
, "sebastian/exporter": "~1.0"
}
, "require-dev": {
"phpunit/phpunit": "~4.0"
}
, "autoload": {
"psr-4": {
"Counterpart\\": "src/"
}
, "files": [
"src/utilities.php"
]
}
, "minimum-stability": "dev"
}
PK t?VwTG ( test/integration/IntegrationTestCase.phpnu W+A
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Counterpart
* @copyright 2014 Christopher Davis
* @license http://opensource.org/licenses/apache-2.0 Apache-2.0
*/
namespace Counterpart;
class IntegrationTestCase extends \PHPUnit_Framework_TestCase
{
protected function matcherReturning($bool)
{
$matcher = $this->createMatcher();
$matcher->expects($this->any())
->method('matches')
->willReturn($bool);
return $matcher;
}
protected function createMatcher()
{
return $this->getMock('Counterpart\\Matcher');
}
}
PK t?V}0s s " test/integration/UtilitiesTest.phpnu W+A
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Counterpart\Test
* @copyright 2014 Christopher Davis
* @license http://opensource.org/licenses/apache-2.0 Apache-2.0
*/
namespace Counterpart;
class UtilitiesTest extends IntegrationTestCase
{
public function testPrettifyReturnsAStringWithVariousVariableTypes()
{
// we know that certain types will return certain values...
$this->assertEquals('null', prettify(null));
$this->assertEquals('true', prettify(true));
$this->assertEquals('false', prettify(false));
$this->assertEquals("'yep'", prettify('yep'));
// others, we only care they they return a string
$this->assertInternalType('string', prettify(['one' => 'two']));
$this->assertInternalType('string', prettify(['one', 'two']));
$obj = new \stdClass;
$obj->prop = new \stdClass;
$obj->prop2 = "two";
$obj->prop->three = "three";
$this->assertInternalType('string', prettify($obj));
}
}
PK t?V
.' ' ! test/integration/MatchersTest.phpnu W+A
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Counterpart
* @copyright 2014 Christopher Davis
* @license http://opensource.org/licenses/apache-2.0 Apache-2.0
*/
namespace Counterpart;
/**
* There are super high-level, happy-path-only integration tests to make sure
* all the static factory methods in Matchers work.
*
* @since 1.0
*/
class MatchersTest extends IntegrationTestCase
{
public function testAnythingMatchesAnything()
{
$anything = Matchers::anything();
$this->assertMatcher($anything);
$this->assertTrue($anything->matches(true));
}
public function testCallbackMatchesWhenCallbackReturnsTrue()
{
$cb = Matchers::callback(function () { return true; });
$this->assertMatcher($cb);
$this->assertTrue($cb->matches(1));
}
public function testContainsMatchesWhenGivenAnArrayContainingValue()
{
$ct = Matchers::contains(1);
$this->assertMatcher($ct);
$this->assertTrue($ct->matches([1, 2]));
}
public function testDoesNotContainMatchesWhenGivenAnArrayNotContaingValue()
{
$dct = Matchers::doesNotContain(1);
$this->assertMatcher($dct);
$this->assertTrue($dct->matches([2, 3]));
}
public function testCountMatchesWhenArrayContainsExpectedCount()
{
$count = Matchers::count(0);
$this->assertMatcher($count);
$this->assertTrue($count->matches([]));
}
public function testFileExistsMatchesWhenGivenAnExistingFile()
{
$fe = Matchers::fileExists();
$this->assertMatcher($fe);
$this->assertTrue($fe->matches(__FILE__));
}
public function testFileDoesNotExistMatchesWhenGivenANonExistentFile()
{
$fde = Matchers::fileDoesNotExist();
$this->assertMatcher($fde);
$this->assertTrue($fde->matches(__DIR__ . '/does/not/exists/at/all.txt'));
}
public function testGreaterThanMatchesWhenGivenANumberGreaterThanExpected()
{
$ge = Matchers::greaterThan(10);
$this->assertMatcher($ge);
$this->assertTrue($ge->matches(100));
$this->assertFalse($ge->matches(0));
}
public function testGreaterThanOrEqualMatchesWhenGivenANumberGreaterThanExpected()
{
$gte = Matchers::greaterThanOrEqual(10);
$this->assertMatcher($gte);
$this->assertTrue($gte->matches(100));
$this->assertTrue($gte->matches(10));
$this->assertFalse($gte->matches(0));
}
public function testHasKeyMatchesWhenGivenAnArrayWithTheExpectedKey()
{
$hk = Matchers::hasKey('k');
$this->assertMatcher($hk);
$this->assertTrue($hk->matches(['k' => true]));
$this->assertFalse($hk->matches([]));
}
public function testDoesNotHaveKeyMatchesWhenGivenAnArrayWithoutExpectedKey()
{
$dhk = Matchers::doesNotHaveKey('k');
$this->assertMatcher($dhk);
$this->assertTrue($dhk->matches([]));
$this->assertFalse($dhk->matches(['k' => true]));
}
public function testHasPropertyMatchesWhenObjectHasExpectedProperty()
{
$cls = new \stdClass;
$cls->prop = true;
$hp = Matchers::hasProperty('prop');
$this->assertMatcher($hp);
$this->assertTrue($hp->matches($cls));
$this->assertFalse($hp->matches(new \stdClass));
}
public function testDoesNotHavePropertyMatchesWhenObjectDoesNotHaveProperty()
{
$cls = new \stdClass;
$cls->prop = true;
$dhp = Matchers::doesNotHaveProperty('prop');
$this->assertMatcher($dhp);
$this->assertTrue($dhp->matches(new \stdClass));
$this->assertFalse($dhp->matches($cls));
}
public function testIsEmptyMatchesWhenGivenEmptyValues()
{
$ie = Matchers::isEmpty();
$this->assertMatcher($ie);
$this->assertTrue($ie->matches(null));
$this->assertTrue($ie->matches(''));
$this->assertTrue($ie->matches(false));
$this->assertTrue($ie->matches([]));
$this->assertTrue($ie->matches(0));
}
public function testIsNotEmptyMatchesWhenGivenANonEmptyValue()
{
$ine = Matchers::isNotEmpty();
$this->assertMatcher($ine);
$this->assertTrue($ine->matches('one'));
$this->assertTrue($ine->matches(true));
$this->assertTrue($ine->matches(1));
$this->assertTrue($ine->matches([1]));
}
public function testIsEqualMatchesWhenTwoValuesAreEqual()
{
$eq = Matchers::isEqual('1');
$this->assertMatcher($eq);
$this->assertTrue($eq->matches(1));
}
public function testIsNotEqualsMatchesWhenTwoValuesAreNotEqual()
{
$neq = Matchers::isNotEqual(1);
$this->assertMatcher($neq);
$this->assertTrue($neq->matches(2));
}
public function testIsIdenticalMatchesWhenTwoValuesAreExactlyEqual()
{
$iden = Matchers::isIdentical(1);
$this->assertMatcher($iden);
$this->assertTrue($iden->matches(1));
$this->assertFalse($iden->matches('1'));
}
public function testIsFalseMatchesWithValuesThatAreExactlyFalse()
{
$false = Matchers::isFalse();
$this->assertMatcher($false);
$this->assertTrue($false->matches(false));
$this->assertFalse($false->matches(null));
}
public function testIsFlasyMatchesWhenFalsyValuesArePassed()
{
$falsy = Matchers::isFalsy();
$this->assertMatcher($falsy);
$this->assertTrue($falsy->matches('no'));
$this->assertTrue($falsy->matches(0));
}
public function testIsInstanceOfMatchesWhenGivenAnAppropriateClass()
{
$io = Matchers::isInstanceOf(__CLASS__);
$this->assertMatcher($io);
$this->assertTrue($io->matches($this));
}
public function testIsJsonMatchesWhenGivenValidJson()
{
$ij = Matchers::isJson();
$this->assertMatcher($ij);
$this->assertTrue($ij->matches('{}'));
}
public function testIsNullMatchesWhenNullValuesAreGiven()
{
$in = Matchers::isNull();
$this->assertMatcher($in);
$this->assertTrue($in->matches(null));
}
public function testIsNotNullMatchesWhenGivenNonNullValues()
{
$inn = Matchers::isNotNull();
$this->assertMatcher($inn);
$this->assertTrue($inn->matches(''));
}
public function testIsTrueMatchesWhenGivenTrueBoolean()
{
$true = Matchers::isTrue();
$this->assertMatcher($true);
$this->assertTrue($true->matches(true));
}
public function testIsTruthyMatchesWhenGivenTruthyValues()
{
$truthy = Matchers::isTruthy();
$this->assertMatcher($truthy);
$this->assertTrue($truthy->matches('yes'));
$this->assertTrue($truthy->matches('on'));
$this->assertTrue($truthy->matches(1));
}
public function testIsTypeMatchesWhenGivenTheExpectedType()
{
$it = Matchers::isType('array');
$this->assertMatcher($it);
$this->assertTrue($it->matches([]));
$this->assertFalse($it->matches('a string'));
}
public function testLessThanMatchesWhenGivenAValueLessThanExpected()
{
$lt = Matchers::lessThan(10);
$this->assertMatcher($lt);
$this->assertTrue($lt->matches(1));
$this->assertFalse($lt->matches(10));
$this->assertFalse($lt->matches(100));
}
public function testLessThanOrEqualMatchesWhenGivenAvalueEqualToOrLessThanExpected()
{
$lte = Matchers::lessThanOrEqual(10);
$this->assertMatcher($lte);
$this->assertTrue($lte->matches(1));
$this->assertTrue($lte->matches(10));
$this->assertFalse($lte->matches(100));
}
public function testMatchesRegexMatchesWhenGivenStringContainsPattern()
{
$re = Matchers::matchesRegex('/here/');
$this->assertMatcher($re);
$this->assertTrue($re->matches('here we are'));
}
public function testDoesNotMatchRegexMatchesWhenGivenStringDoesNotContainPattern()
{
$dre = Matchers::doesNotMatchRegex('/here/');
$this->assertMatcher($dre);
$this->assertTrue($dre->matches('nope nope nope'));
}
public function testStringContainsMatchesWhenStringHasNeedle()
{
$sc = Matchers::stringContains('here');
$this->assertMatcher($sc);
$this->assertTrue($sc->matches('here we are'));
}
public function testStringDoesNotContainMatchesWhenStringDoesNotHaveNeedle()
{
$sdc = Matchers::stringDoesNotContain('here');
$this->assertMatcher($sdc);
$this->assertTrue($sdc->matches('nope nope nope'));
}
public function testLogicalNotReturnsValidMatcher()
{
$this->assertMatcher(Matchers::logicalNot($this->createMatcher()));
}
public function testLogicalAndReturnsValidMatcher()
{
$this->assertMatcher(Matchers::logicalAnd(
$this->createMatcher(),
$this->createMatcher()
));
}
public function testLogicalOrReturnsValidMatcher()
{
$this->assertMatcher(Matchers::logicalOr(
$this->createMatcher(),
$this->createMatcher()
));
}
public function testLogicalXorReturnsValidMatcher()
{
$this->assertMatcher(Matchers::logicalXor(
$this->createMatcher(),
$this->createMatcher()
));
}
private function assertMatcher($object)
{
$this->assertInstanceOf('Counterpart\\Matcher', $object);
}
}
PK t?VE % test/integration/AssertThrowsTest.phpnu W+A
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Counterpart
* @copyright 2014 Christopher Davis
* @license http://opensource.org/licenses/apache-2.0 Apache-2.0
*/
namespace Counterpart;
/**
* Tests all the paths where Assert::assert* will throw exceptions
*/
class AssertThrowsTest extends IntegrationTestCase
{
public function testAssertThanThrowsAssertionFailedWhenMatcherDoesNotMatch()
{
$matcher = $this->matcherReturning(false);
Assert::assertThat($matcher, true, 'this should throw');
}
public function testAssertContainsThrowsWhenArrayDoesNotContainExpected()
{
Assert::assertContains(123, [234, 455], 'this should throw');
}
public function testAssertDoesNotContainsThrowsWhenArrayDoesContainExpected()
{
Assert::assertDoesNotContain(123, [123, 234], 'this should throw');
}
public function testAssertCountThrowsWhenCountsDoesNotMatchExpected()
{
Assert::assertCount(100, [], 'should throw');
}
public function testAssertFileExistsThrowsWithNonExistentFile()
{
Assert::assertFileExists(__DIR__ . '/does/not/exist/at/all.txt');
}
public function testAssertGreaterThanThrowsWithNumberSmallerThanExpected()
{
Assert::assertGreaterThan(10, 10);
}
public function testAssertGreaterThanOrEqualThrowsWhenGivenASmallerValue()
{
Assert::assertGreaterThanOrEqual(10, 9);
}
public function testAssertLessThanThrowsWhenGivenANumberBiggerThanExpected()
{
Assert::assertLessThan(10, 10);
}
public function testAssertLessThanOrEqualsThrowsWhenGivenANumberBiggerThanExpected()
{
Assert::assertLessThanOrEqual(10, 100);
}
public function testAssertArrayHasKeyThrowsWhenGivenArrayWithoutExpectedKey()
{
Assert::assertArrayHasKey('one', []);
}
public function testAssertObjectHasPropertyThrowsWhenGivenObjectWithoutExpectedProperty()
{
Assert::assertObjectHasProperty('one', new \stdClass);
}
public function testAssertEmptyThrowsWhenGivenANonEmptyValue()
{
Assert::assertEmpty(['not', 'empty']);
}
public function testAssertNotEmptyThrowsWhenGivenAnemptyValue()
{
Assert::assertNotEmpty([]);
}
public function testAssertEqualsThrowsWhenValuesAreNotEqual()
{
Assert::assertEquals(1, 2);
}
public function testAssertNotEqualsThrowsWhenValuesAreEqual()
{
Assert::assertNotEquals(1, 1);
}
public function testAssertIdenticalThrowsWhenValuesAreNotIdentical()
{
Assert::assertIdentical(new \stdClass, new \stdClass);
}
public static function testAssertFalseThrowsWhenValueIsNotFalse()
{
Assert::assertFalse(true);
}
public static function testAssertTrueThrowsWhenValueIsNotTrue()
{
Assert::assertTrue(false);
}
public function testAssertInstanceOfThrowsWhenGivenAnInvalidInstance()
{
Assert::assertInstanceOf(__CLASS__, new \stdClass);
}
public function testAssertNullThrowsWhenGivenANonNullValue()
{
Assert::assertNull('not null');
}
public function testAssertNotNullThrowsWhenGivenANullValue()
{
Assert::assertNotNull(null);
}
public function testAssertTypeThrowsWhenGivenAMismatchedType()
{
Assert::assertType('array', 'not an array');
}
public function testAssertMatchesRegexThrowsWhenAPatternDoesntMatch()
{
Assert::assertMatchesRegex('/here/', 'nope nope nope');
}
public function testAssertStringContainsWhenValueDoesNotContainNeedle()
{
Assert::assertStringContains('here', 'nope nope nope');
}
public function testAssertStringDoesNotContainThrowsWhenValueContainsNeedle()
{
Assert::assertStringDoesNotContain('here', 'here we are');
}
protected function setUp()
{
$this->setExpectedException('Counterpart\\Exception\\AssertionFailed');
}
}
PK t?V[H3 test/bootstrap.phpnu W+A
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Counterpart\Test
* @copyright 2014 Christopher Davis
* @license http://opensource.org/licenses/apache-2.0 Apache-2.0
*/
$loader = require __DIR__ . '/../vendor/autoload.php';
$loader->addPsr4("Counterpart\\", __DIR__ . '/unit');
$loader->addPsr4("Counterpart\\", __DIR__ . '/integration');
PK t?V±V " test/unit/Fixtures/file_exists.txtnu W+A Just checkin'
PK t?VCq " test/unit/Matcher/IsTruthyTest.phpnu W+A
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Counterpart\Test
* @copyright 2014 Christopher Davis
* @license http://opensource.org/licenses/apache-2.0 Apache-2.0
*/
namespace Counterpart\Matcher;
use Counterpart\TestCase;
class IsTruthyTest extends TestCase
{
private $matcher;
public function testMatchesReturnsTrueForTruthyValues()
{
$this->assertTrue($this->matcher->matches(true));
$this->assertTrue($this->matcher->matches(1));
$this->assertTrue($this->matcher->matches("1"));
$this->assertTrue($this->matcher->matches("yes"));
$this->assertTrue($this->matcher->matches("on"));
$this->assertTrue($this->matcher->matches("true"));
}
public function testMatchesReturnsFalseForNonTruthyValues()
{
$this->assertFalse($this->matcher->matches("false"));
$this->assertFalse($this->matcher->matches("this should return false as well"));
$this->assertFalse($this->matcher->matches(null));
}
protected function setUp()
{
$this->matcher = new IsTruthy();
}
}
PK t?VƖ 9 9 $ test/unit/Matcher/FileExistsTest.phpnu W+A
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Counterpart\Test
* @copyright 2014 Christopher Davis
* @license http://opensource.org/licenses/apache-2.0 Apache-2.0
*/
namespace Counterpart\Matcher;
use Counterpart\TestCase;
class FileExistsTest extends TestCase
{
private $matcher;
public function nonScalarProvider()
{
return [
[null],
[['one']],
[new \stdClass],
];
}
/**
* @dataProvider nonScalarProvider
*/
public function testMatchesReturnsFalseForNonScalarValues($notAPath)
{
$this->assertFalse($this->matcher->matches($notAPath));
}
public function filePathProvider()
{
return [
[__DIR__, true],
[".", true],
[__DIR__ . '/../Fixtures/file_exists.txt', true],
['path/does/not/at/all/exist.txt', false],
];
}
/**
* @dataProvider filePathProvider
*/
public function testMatchesReturnsTrueForOnlyValidFilePaths($path, $expected)
{
$this->assertEquals($expected, $this->matcher->matches($path));
}
protected function setUp()
{
$this->matcher = new FileExists();
}
}
PK t?V1@4C C % test/unit/Matcher/HasPropertyTest.phpnu W+A
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Counterpart\Test
* @copyright 2014 Christopher Davis
* @license http://opensource.org/licenses/apache-2.0 Apache-2.0
*/
namespace Counterpart\Matcher;
use Counterpart\TestCase;
class HasPropertyTest extends TestCase
{
public $publicProp = true;
protected $protectedProp = true;
private $privateProp = true;
public function testMatchesReturnsFalseWithNonObjects()
{
$matcher = new HasProperty('aProp');
$this->assertFalse($matcher->matches(null));
$this->assertFalse($matcher->matches('a string'));
$this->assertFalse($matcher->matches(true));
$this->assertFalse($matcher->matches(['aProp' => true]));
}
public function testMatchesReturnsTrueWithPropertiesOfVariousAccessScopes()
{
$this->assertTrue((new HasProperty('publicProp'))->matches($this));
$this->assertTrue((new HasProperty('protectedProp'))->matches($this));
$this->assertTrue((new HasProperty('privateProp'))->matches($this));
}
public function testMatchesReturnsTrueWithNullPropertyValues()
{
$o = new \stdClass;
$o->prop = null;
$this->assertTrue((new HasProperty('prop'))->matches($o));
}
/**
* @expectedException Counterpart\Exception\CounterpartException
*/
public function testNonStringPropertyNameCausesConstructorToComplain()
{
new HasProperty(['this', "doesn't", 'work']);
}
}
PK t?V%X| | # test/unit/Matcher/LogicalOrTest.phpnu W+A
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Counterpart
* @copyright 2014 Christopher Davis
* @license http://opensource.org/licenses/apache-2.0 Apache-2.0
*/
namespace Counterpart\Matcher;
class LogicalOrTest extends LogicalCombinationTestCase
{
/**
* @expectedException Counterpart\Exception\CounterpartException
*/
public function testCreateWithInvalidMatcherThrowsException()
{
new LogicalOr([null]);
}
public function testMatchesReturnsTrueWhenOneMatcherReturnsTrue()
{
$matcherOne = $this->matcherReturning(false);
$matcherTwo = $this->matcherReturning(true);
$this->assertTrue((new LogicalOr([$matcherOne, $matcherTwo]))->matches('ignored'));
}
public function testMatchesReturnsFalseWhenAllMatchersReturnFalse()
{
$matcherOne = $this->matcherReturning(false);
$matcherTwo = $this->matcherReturning(false);
$this->assertFalse((new LogicalAnd([$matcherOne, $matcherTwo]))->matches('ignored'));
}
}
PK t?VR " test/unit/Matcher/LessThanTest.phpnu W+A
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Counterpart\Test
* @copyright 2014 Christopher Davis
* @license http://opensource.org/licenses/apache-2.0 Apache-2.0
*/
namespace Counterpart\Matcher;
use Counterpart\TestCase;
class LessThanTest extends TestCase
{
public function lessThanProvider()
{
return [
[0xFF, 0x00],
[10, 1],
[100, -4]
];
}
/**
* @dataProvider lessThanProvider
*/
public function testMatchesReturnsTrueWhenActualValueIsLessThanExpected($expected, $actual)
{
$this->assertTrue((new LessThan($expected))->matches($actual));
}
public function greaterThanOrEqualToProvider()
{
return [
[10, 10],
[10, 12],
[null, 200],
[-1, 10]
];
}
/**
* @dataProvider greaterThanOrEqualToProvider
*/
public function testMatchesReturnsFalseWhenActualValueIsGreaterThanOrEqualToExpected($expected, $actual)
{
$this->assertFalse((new LessThan($expected))->matches($actual));
}
}
PK t?Vڪ test/unit/Matcher/HasKeyTest.phpnu W+A
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Counterpart\Test
* @copyright 2014 Christopher Davis
* @license http://opensource.org/licenses/apache-2.0 Apache-2.0
*/
namespace Counterpart\Matcher;
use Counterpart\TestCase;
class HasKeyTest extends TestCase
{
public function testHasKeyWithNonArrayAlwaysReturnsFalse()
{
$matcher = new HasKey('one');
$this->assertFalse($matcher->matches('not an array'));
$this->assertFalse($matcher->matches(null));
$this->assertFalse($matcher->matches(false));
}
public function testHasKeyWithArrayMatchesAsExpected()
{
$matcher = new HasKey('one');
$this->assertTrue($matcher->matches(['one' => true]));
$this->assertTrue($matcher->matches(['one' => null]));
$this->assertFalse($matcher->matches(['two' => null]));
$this->assertFalse($matcher->matches([]));
}
public function testHasKeyArrayAccessImplementation()
{
$aa = new \ArrayObject(['one' => true]);
$this->assertTrue((new HasKey('one'))->matches($aa));
$this->assertFalse((new HasKey('two'))->matches($aa));
}
}
PK t?Vo ! test/unit/Matcher/IsEqualTest.phpnu W+A
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Counterpart\Test
* @copyright 2014 Christopher Davis
* @license http://opensource.org/licenses/apache-2.0 Apache-2.0
*/
namespace Counterpart\Matcher;
use Counterpart\TestCase;
class IsEqualTest extends TestCase
{
public function equalityProvider()
{
return [
[null, ''],
[false, ''],
[true, 'non empty string'],
[new \stdClass, new \stdClass]
];
}
public function exactEqualityProvider()
{
$cls = new \stdClass;
return [
[false, false],
[true, true],
[null, null],
[12, 12],
['one', 'one'],
[1.0, 1.0],
[$cls, $cls],
];
}
/**
* @dataProvider equalityProvider
*/
public function testMatchesReturnsTrueForEqualValues($expected, $actual)
{
$this->assertTrue((new IsEqual($expected))->matches($actual));
}
/**
* @dataProvider exactEqualityProvider
*/
public function testMatchesReturnsTrueForExactlyEqualValue($expected, $actual)
{
$this->assertTrue((new IsEqual($expected))->matches($actual));
}
/**
* @dataProvider exactEqualityProvider
*/
public function testMatchesWithStrictReturnsTrueOnlyForExactlyEqualsItems($expected, $actual)
{
$this->assertTrue((new IsEqual($expected, true))->matches($actual));
}
/**
* @dataProvider equalityProvider
*/
public function testMatchesWithStrictReturnsFalseForFuzzyEqualValues($expected, $actual)
{
$this->assertFalse((new IsEqual($expected, true))->matches($actual));
}
public function inequalityProvider()
{
$ob = new \stdClass;
$ob->prop = true;
return [
[false, 'not empty'],
['one', 'two'],
[false, true],
[new \stdClass, $ob]
];
}
/**
* @dataProvider inequalityProvider
*/
public function testMatchesReturnsFalseForNotEqualValues($expected, $actual)
{
$this->assertFalse((new IsEqual($expected))->matches($actual));
}
/**
* @dataProvider inequalityProvider
*/
public function testMatchesWithStrictReturnsFalseForNotEqualValues($expected, $actual)
{
$this->assertFalse((new IsEqual($expected, true))->matches($actual));
}
}
PK t?V0
test/unit/Matcher/CountTest.phpnu W+A
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Counterpart\Test
* @copyright 2014 Christopher Davis
* @license http://opensource.org/licenses/apache-2.0 Apache-2.0
*/
namespace Counterpart\Matcher;
use Counterpart\TestCase;
class _CountIteratorAgStub implements \IteratorAggregate
{
private $it;
public function __construct(\Iterator $it)
{
$this->it = $it;
}
public function getIterator()
{
return $this->it;
}
}
class _CountIteratorStub implements \Iterator
{
private $store;
public function __construct(array $store)
{
$this->store = $store;
}
public function current()
{
return current($this->store);
}
public function key()
{
return key($this->store);
}
public function next()
{
next($this->store);
}
public function rewind()
{
reset($this->store);
}
public function valid()
{
return null !== $this->key();
}
}
class CountTest extends TestCase
{
/**
* @expectedException Counterpart\Exception\InvalidArgumentException
*/
public function testConstructorThrowsExceptionWhenGivenANonInteger()
{
new Count('not an integer');
}
public function testNonArrayTraversableOrCountableReturnsFalse()
{
$this->assertFalse((new Count(1))->matches('not an array'));
}
public function countProvider()
{
return [
[['one']],
[new \ArrayIterator(['one'])],
[new _CountIteratorAgStub(new \ArrayIterator(['one']))],
[new _CountIteratorStub(['one'])],
];
}
/**
* @dataProvider countProvider
*/
public function testMatchesReturnsTrueWhenCountEqualsExpected($countable)
{
$this->assertTrue((new Count(1))->matches($countable));
}
/**
* @dataProvider countProvider
*/
public function testMatchesReturnsFalseWhenCountDoesNotEqualExpected($countable)
{
$this->assertFalse((new Count(2))->matches($countable));
}
}
PK t?Vl &