├── .atoum.php ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── classes ├── asserters │ ├── assertThat.php │ ├── phpArray.php │ ├── phpObject.php │ └── variable.php ├── constraint.php ├── constraint │ └── exception.php ├── constraints │ ├── arrayHasKey.php │ ├── arraySubset.php │ ├── boolean.php │ ├── contains.php │ ├── containsOnly.php │ ├── containsOnlyInstancesOf.php │ ├── count.php │ ├── equals.php │ ├── finite.php │ ├── greaterThan.php │ ├── greaterThanOrEqual.php │ ├── infinite.php │ ├── internalType.php │ ├── isEmpty.php │ ├── isInstanceOf.php │ ├── isNotEmpty.php │ ├── isNotInstanceOf.php │ ├── isNotNull.php │ ├── isNull.php │ ├── nan.php │ ├── notCount.php │ ├── notSame.php │ ├── objectHasAttribute.php │ ├── objectNotHasAttribute.php │ └── same.php ├── extension.php └── test.php ├── composer.json ├── configuration.php ├── phpunit.xml.dist ├── phpunit ├── AssertionFailedError.php ├── Constraint.php ├── Exception.php ├── ExpectationFailedException.php └── TestCase.php └── tests └── units └── classes ├── asserters └── assertThatTest.php ├── constraintTest.php ├── constraints ├── arrayHasKeyTest.php ├── arraySubsetTest.php ├── booleanTest.php ├── containsOnlyInstancesOfTest.php ├── containsOnlyTest.php ├── containsTest.php ├── countTest.php ├── equalsTest.php ├── finiteTest.php ├── greaterThanOrEqualTest.php ├── greaterThanTest.php ├── infiniteTest.php ├── internalTypeTest.php ├── isEmpty.php ├── isInstanceofTest.php ├── isNotEmpty.php ├── isNotNullTest.php ├── isNullTest.php ├── nanTest.php ├── notCountTest.php ├── objectHasAttributeTest.php ├── objectNotHasAttributeTest.php └── sameTest.php └── extensionTest.php /.atoum.php: -------------------------------------------------------------------------------- 1 | noCodeCoverageForClasses('mageekguy\atoum\asserter'); 4 | $script->noCodeCoverageForNamespaces('mageekguy\atoum\asserters'); 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | composer.lock 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.6 5 | - 7.0 6 | - 7.1 7 | - 7.2 8 | - nightly 9 | 10 | cache: 11 | directories: 12 | - vendor 13 | 14 | matrix: 15 | allow_failures: 16 | - php: nightly 17 | 18 | sudo: false 19 | 20 | before_script: 21 | - composer install 22 | 23 | script: 24 | - vendor/bin/phpunit 25 | - vendor/bin/atoum --test-ext -ulr 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2016, atoum contributors. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of atoum contributors nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY ATOUM CONTRIBUTORS ``AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL ATOUM CONTRIBUTORS BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # atoum/phpunit-extension [![Build Status](https://travis-ci.org/atoum/phpunit-extension.svg?branch=master)](https://travis-ci.org/atoum/phpunit-extension) 2 | 3 | This atoum extensions allows to run your existing PHPUnit test suites 4 | with atoum's engine! If you want to migrate from PHPUnit to atoum, 5 | this extension is your best companion! 6 | 7 | ## Goals 8 | 9 | Your project already has PHPUnit test suites. You felt in love with 10 | atoum. You want to replace PHPUnit by atoum on your project. This 11 | extension will allow you to run your PHPUnit test suites with atoum, 12 | ensuring a smooth migration. 13 | 14 | ## Install it 15 | 16 | The extension is still a work in progress. You need to require a 17 | developpement branch of atoum. 18 | 19 | Note: We need your help to complete the extension, so feel free to 20 | test the extension and submit issues when you found one. 21 | 22 | Install extension using [Composer](https://getcomposer.org): 23 | 24 | ```json 25 | { 26 | "require-dev": { 27 | "atoum/atoum": "dev-virtual-hooks", 28 | "atoum/phpunit-extension": "~0.6" 29 | } 30 | } 31 | ``` 32 | 33 | Enable the extension using atoum configuration file: 34 | 35 | ```php 36 | addToRunner($runner); 46 | ``` 47 | 48 | ## Use it 49 | 50 | By default, everything should work, simply run `atoum` as usual and 51 | your test suites will execute. 52 | 53 | If you want to switch a test suite from PHPUnit to atoum, and get all 54 | the features from atoum, replace the parent class of your test suites 55 | from `PHPUnit\Framework\TestCase` to `mageekguy\atoum\phpunit`: 56 | 57 | ```diff 58 | -class EnumTest extends \PHPUnit\Framework\TestCase 59 | +class EnumTest extends \mageekguy\atoum\phpunit 60 | ``` 61 | 62 | Enjoy! 63 | 64 | ## Support 65 | 66 | ### Helpers 67 | 68 | | Method | Supported | 69 | |------------------------------------------------------------------------------------------|:---------:| 70 | | `fail` | ❌ | 71 | | `markTestIncomplete` | ❌ | 72 | | `markTestSkipped` | ✅ | 73 | | *Total* | 33% | 74 | 75 | ### Assertions 76 | 77 | | Method | Supported | 78 | |--------------------------------------------------------------------------------------------------------------------|:---------:| 79 | | `assertArrayHasKey(mixed $key, array $array[, string $message = ''])` | ✅ | 80 | | `assertArrayNotHasKey` | ❌ | 81 | | `assertClassHasAttribute` | ❌ | 82 | | `assertClassNotHasAttribute` | ❌ | 83 | | `assertArraySubset(array $subset, array $array[, bool $strict = '', string $message = ''])` | ✅ | 84 | | `assertClassHasStaticAttribute` | ❌ | 85 | | `assertClassNotHasStaticAttribute` | ❌ | 86 | | `assertContains(mixed $needle, iterable $haystack[, string $message = ''])` | ✅ | 87 | | `assertContains(string $needle, string $haystack[, string $message = '', boolean $ignoreCase = FALSE])` | ✅ | 88 | | `assertNotContains` | ❌ | 89 | | `assertContainsOnly(string $type, iterable $haystack[, boolean $isNativeType = NULL, string $message = ''])` | ✅ | 90 | | `assertContainsOnlyInstancesOf(string $classname, iterable $haystack[, string $message = ''])` | ✅ | 91 | | `assertNotContainsOnly` | ❌ | 92 | | `assertCount($expectedCount, $haystack[, string $message = ''])` | ✅ | 93 | | `assertNotCount($expectedCount, $haystack[, string $message = ''])` | ✅ | 94 | | `assertEmpty(mixed $actual[, string $message = ''])` | ✅ | 95 | | `assertNotEmpty(mixed $actual[, string $message = ''])` | ✅ | 96 | | `assertEqualXMLStructure` | ❌ | 97 | | `assertEquals(mixed $expected, mixed $actual[, string $message = ''])` | ✅ | 98 | | `assertEquals(float $expected, float $actual[, string $message = '', float $delta = 0])` | ✅ | 99 | | `assertEquals(DOMDocument $expected, DOMDocument $actual[, string $message = ''])` | ❌ | 100 | | `assertEquals(object $expected, object $actual[, string $message = ''])` | ✅ | 101 | | `assertEquals(array $expected, array $actual[, string $message = ''])` | ✅ | 102 | | `assertNotEquals` | ❌ | 103 | | `assertFalse(bool $condition[, string $message = ''])` | ✅ | 104 | | `assertNotFalse` | ❌ | 105 | | `assertFileEquals` | ❌ | 106 | | `assertFileNotEquals` | ❌ | 107 | | `assertFileExists` | ❌ | 108 | | `assertFileNotExists` | ❌ | 109 | | `assertGreaterThan(mixed $expected, mixed $actual[, string $message = ''])` | ✅ | 110 | | `assertGreaterThanOrEqual(mixed $expected, mixed $actual[, string $message = ''])` | ✅ | 111 | | `assertInfinite(mixed $variable[, string $message = ''])` | ✅ | 112 | | `assertFinite(mixed $variable[, string $message = ''])` | ✅ | 113 | | `assertInstanceOf($expected, $actual[, $message = ''])` | ✅ | 114 | | `assertNotInstanceOf($expected, $actual[, $message = ''])` | ❌ | 115 | | `assertInternalType($expected, $actual[, $message = ''])` | ✅ | 116 | | `assertNotInternalType` | ❌ | 117 | | `assertJsonFileEqualsJsonFile` | ❌ | 118 | | `assertJsonStringEqualsJsonFile` | ❌ | 119 | | `assertJsonStringEqualsJsonString` | ❌ | 120 | | `assertLessThan` | ❌ | 121 | | `assertLessThanOrEqual` | ❌ | 122 | | `assertNan(mixed $variable[, string $message = ''])` | ✅ | 123 | | `assertNull(mixed $variable[, string $message = ''])` | ✅ | 124 | | `assertNotNull(mixed $variable[, string $message = ''])` | ✅ | 125 | | `assertObjectHasAttribute(string $attribute[, string $message = ''])` | ✅ | 126 | | `assertObjectNotHasAttribute(string $attribute[, string $message = ''])` | ✅ | 127 | | `assertRegExp` | ❌ | 128 | | `assertNotRegExp` | ❌ | 129 | | `assertStringMatchesFormat` | ❌ | 130 | | `assertStringNotMatchesFormat` | ❌ | 131 | | `assertStringMatchesFormatFile` | ❌ | 132 | | `assertStringNotMatchesFormatFile` | ❌ | 133 | | `assertSame(mixed $expected, mixed $actual[, string $message = ''])` | ✅ | 134 | | `assertNotSame(mixed $expected, mixed $actual[, string $message = ''])` | ✅ | 135 | | `assertStringEndsWith` | ❌ | 136 | | `assertStringEndsNotWith` | ❌ | 137 | | `assertStringEqualsFile` | ❌ | 138 | | `assertStringNotEqualsFile` | ❌ | 139 | | `assertStringStartsWith` | ❌ | 140 | | `assertStringStartsNotWith` | ❌ | 141 | | `assertThat(mixed $value, PHPUnit_Framework_Constraint $constraint[, $message = ''])` | ✅ | 142 | | `assertTrue(bool $condition[, string $message = ''])` | ✅ | 143 | | `assertNotTrue` | ❌ | 144 | | `assertXmlFileEqualsXmlFile` | ❌ | 145 | | `assertXmlFileNotEqualsXmlFile` | ❌ | 146 | | `assertXmlStringEqualsXmlFile` | ❌ | 147 | | `assertXmlStringNotEqualsXmlFile` | ❌ | 148 | | `assertXmlStringEqualsXmlString` | ❌ | 149 | | `assertXmlStringNotEqualsXmlString` | ❌ | 150 | | *Total* | 42.25% | 151 | 152 | ### Classes 153 | 154 | | Class | Supported | Mapped to | 155 | |--------------------------------|:---------:|--------------------------------------| 156 | | `PHPUnit\Framework\TestCase` | ✅ | `mageekguy\atoum\phpunit\test` | 157 | | `PHPUnit\Framework\Constraint` | ✅ | `mageekguy\atoum\phpunit\constraint` | 158 | | *Total* | 100% | | 159 | 160 | ### Exceptions 161 | 162 | | Class | Supported | Mapped to | 163 | |------------------------------------------------|:---------:|------------------------------------------------| 164 | | `PHPUnit\Framework\AssertionFailedError` | ✅ | `mageekguy\atoum\asserter\exception` | 165 | | `PHPUnit\Framework\Exception` | ✅ | `mageekguy\atoum\exceptions\runtime` | 166 | | `PHPUnit\Framework\ExpectationFailedException` | ✅ | `mageekguy\atoum\phpunit\constraint\exception` | 167 | | *Total* | 100% | | 168 | 169 | ### Annotations 170 | 171 | | Annotation | Supported | Note | 172 | |-----------------------------------|:---------:|:-------------------------------------------------:| 173 | | `@author` | ✅ | | 174 | | `@after` | ❌ | | 175 | | `@afterClass` | ❌ | | 176 | | `@backupGlobals` | ❌ | | 177 | | `@backupStaticAttributes` | ❌ | | 178 | | `@before` | ❌ | | 179 | | `@beforeClass` | ❌ | | 180 | | `@codeCoverageIgnore*` | ❌ | | 181 | | `@covers` | ✅ | Does only consider the class name. | 182 | | `@coversDefaultClass` | ✅ | | 183 | | `@coversNothing` | ✅ | | 184 | | `@dataProvider` | ✅ | | 185 | | `@depends` | ❌ | | 186 | | `@expectedException` | ❌ | | 187 | | `@expectedExceptionCode` | ❌ | | 188 | | `@expectedExceptionMessage` | ❌ | | 189 | | `@expectedExceptionMessageRegExp` | ❌ | | 190 | | `@group` | ✅ | | 191 | | `@large` | ✅ | Does not support strict-mode failures | 192 | | `@medium` | ✅ | Does not support strict-mode failures | 193 | | `@preserveGlobalState` | ❌ | | 194 | | `@requires` | ❌ | | 195 | | `@runTestsInSeparateProcesses` | ✅ | Does not preserve global state in child processes | 196 | | `@runInSeparateProcess` | ✅ | Does not preserve global state in child processes | 197 | | `@small` | ✅ | Does not support strict-mode failures | 198 | | `@test` | ❌ | | 199 | | `@testdox` | ❌ | | 200 | | `@ticket` | ❌ | | 201 | | `@uses` | ❌ | | 202 | | *Total* | 37.93% | | 203 | 204 | ## Links 205 | 206 | * [atoum](http://atoum.org) 207 | * [atoum's documentation](http://docs.atoum.org) 208 | * [PHPUnit](https://phpunit.de/) 209 | 210 | 211 | ## License 212 | 213 | phpunit-extension is released under the BSD-3-Clause License. See the bundled LICENSE file for details. 214 | 215 | ![atoum](http://atoum.org/images/logo/atoum.png) 216 | -------------------------------------------------------------------------------- /classes/asserters/assertThat.php: -------------------------------------------------------------------------------- 1 | evaluate($actual, $failMessage); 23 | 24 | $this->pass(); 25 | } catch (constraint\exception $exception) { 26 | $this->fail($exception->getMessage()); 27 | } 28 | 29 | return $this; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /classes/asserters/phpArray.php: -------------------------------------------------------------------------------- 1 | valueIsSet()->value) != $size) { 12 | $this->pass(); 13 | } else { 14 | $this->fail($failMessage ?: $this->_('%s has size %d, expected different size', $this, count($this->valueIsSet()->value), $size)); 15 | } 16 | 17 | return $this; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /classes/asserters/phpObject.php: -------------------------------------------------------------------------------- 1 | valueIsSet()->value, $attribute)) { 12 | $this->pass(); 13 | } else { 14 | $this->fail($failMessage ?: $this->_('%s has no attribute `%s`', $this, $attribute)); 15 | } 16 | 17 | return $this; 18 | } 19 | 20 | public function hasNotAttribute($attribute, $failMessage = null) 21 | { 22 | if (false === property_exists($this->valueIsSet()->value, $attribute)) { 23 | $this->pass(); 24 | } else { 25 | $this->fail($failMessage ?: $this->_('%s has attribute `%s`', $this, $attribute)); 26 | } 27 | 28 | return $this; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /classes/asserters/variable.php: -------------------------------------------------------------------------------- 1 | valueIsSet()->value)) { 12 | $this->pass(); 13 | } else { 14 | $this->fail($failMessage ?: $this->_('%s is not empty', $this)); 15 | } 16 | 17 | return $this; 18 | } 19 | 20 | public function isNotEmpty($failMessage = null) 21 | { 22 | if (!empty($this->valueIsSet()->value)) { 23 | $this->pass(); 24 | } else { 25 | $this->fail($failMessage ?: $this->_('%s is empty', $this)); 26 | } 27 | 28 | return $this; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /classes/constraint.php: -------------------------------------------------------------------------------- 1 | doesMatch($actual); 16 | 17 | if ($return) { 18 | return $result; 19 | } 20 | 21 | if ($result === false) { 22 | $this->fail($actual, $description ?: $this->description); 23 | } 24 | 25 | return $this; 26 | } 27 | 28 | public function count() 29 | { 30 | return 1; 31 | } 32 | 33 | abstract protected function matches($actual); 34 | 35 | protected function fail($actual, $message) 36 | { 37 | throw new PHPUnit\Framework\ExpectationFailedException($message); 38 | } 39 | 40 | private function doesMatch($actual) 41 | { 42 | try { 43 | $this->matches($actual); 44 | } catch (exception $exception) { 45 | $this->description = $this->description ?: $exception->getMessage(); 46 | 47 | return false; 48 | } 49 | 50 | return true; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /classes/constraint/exception.php: -------------------------------------------------------------------------------- 1 | analyzer = $analyzer ?: new analyzer(); 19 | $this->expected = $expected; 20 | $this->description = $description; 21 | } 22 | 23 | protected function matches($actual) 24 | { 25 | if (is_null($this->expected)) { 26 | throw new PHPUnit\Framework\Exception('Expected value of ' . __CLASS__ . ' must not be null'); 27 | } 28 | 29 | if ($this->analyzer->isArray($actual) === false && $actual instanceof \arrayAccess === false) { 30 | throw new PHPUnit\Framework\Exception('Actual value of ' . __CLASS__ . ' must be an array or an arrayAccess instance'); 31 | } 32 | 33 | if ($this->analyzer->isArray($actual)) { 34 | $asserter = new asserters\phpArray(null, $this->analyzer); 35 | $asserter->setWith($actual)->hasKey($this->expected); 36 | } else { 37 | $asserter = new asserters\boolean(null, $this->analyzer); 38 | 39 | try { 40 | $asserter->setWith(isset($actual[$this->expected]))->isTrue(); 41 | } catch (exception $exception) { 42 | throw new exception($asserter, $this->analyzer->getTypeOf($actual) . ' has no key ' . $this->analyzer->getTypeOf($this->expected)); 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /classes/constraints/arraySubset.php: -------------------------------------------------------------------------------- 1 | analyzer = $analyzer ?: new analyzer(); 19 | $this->expected = $expected; 20 | $this->description = $description; 21 | $this->strict = (bool) $strict; 22 | } 23 | 24 | protected function matches($actual) 25 | { 26 | if ($this->analyzer->isArray($actual) === false) { 27 | throw new PHPUnit\Framework\Exception('Actual value of ' . __CLASS__ . ' must be an array'); 28 | } 29 | 30 | $patched = array_replace_recursive($actual, $this->expected); 31 | $asserter = new asserters\phpArray(null, $this->analyzer); 32 | $asserter->setWith($actual); 33 | 34 | if ($this->strict) { 35 | $asserter->isIdenticalTo($patched); 36 | } else { 37 | $asserter->isEqualTo($patched); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /classes/constraints/boolean.php: -------------------------------------------------------------------------------- 1 | analyzer = $analyzer ?: new analyzer(); 18 | $this->expected = $expected; 19 | $this->description = $description; 20 | } 21 | 22 | protected function matches($actual) 23 | { 24 | if ($this->analyzer->isBoolean($this->expected) === false) { 25 | throw new PHPUnit\Framework\Exception('Expected value of ' . __CLASS__ . ' must be a boolean'); 26 | } 27 | 28 | $asserter = new asserters\boolean(null, $this->analyzer); 29 | $asserter->setWith($actual); 30 | 31 | if ($this->expected) { 32 | $asserter->isTrue(); 33 | } else { 34 | $asserter->isFalse(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /classes/constraints/contains.php: -------------------------------------------------------------------------------- 1 | analyzer = $analyzer ?: new analyzer(); 22 | $this->expected = $expected; 23 | $this->description = $description; 24 | $this->ignoreCase = (bool) $ignoreCase; 25 | $this->checkForObjectIdentity = $checkForObjectIdentity === null ? true : (bool) $checkForObjectIdentity; 26 | $this->checkForNonObjectIdentity = (bool) $checkForNonObjectIdentity; 27 | } 28 | 29 | protected function matches($actual) 30 | { 31 | $expected = $this->expected; 32 | 33 | switch (true) { 34 | case $this->analyzer->isArray($actual): 35 | $asserter = new asserters\phpArray(null, $this->analyzer); 36 | $asserter->setWith($actual); 37 | break; 38 | 39 | case $actual instanceof \iterator: 40 | $asserter = new asserters\iterator(null, $this->analyzer); 41 | $asserter = $asserter->setWith($actual)->toArray; 42 | break; 43 | 44 | case $this->analyzer->isString($actual): 45 | $asserter = new asserters\phpString(null, $this->analyzer); 46 | 47 | if ($this->ignoreCase) { 48 | $actual = strtolower($actual); 49 | $expected = strtolower($expected); 50 | } 51 | 52 | $asserter->setWith($actual); 53 | break; 54 | 55 | default: 56 | throw new PHPUnit\Framework\Exception('Actual value of ' . __CLASS__ . ' must be an array, a string or a traversable object'); 57 | } 58 | 59 | try { 60 | if ($this->analyzer->isObject($expected)) { 61 | if ($this->checkForObjectIdentity) { 62 | $asserter->strictlyContains($expected); 63 | } else { 64 | $asserter->contains($expected); 65 | } 66 | } else { 67 | if ($this->checkForNonObjectIdentity) { 68 | $asserter->strictlyContains($expected); 69 | } else { 70 | $asserter->contains($expected); 71 | } 72 | } 73 | } catch (exception $exception) { 74 | throw new exception($asserter, $this->analyzer->getTypeOf($actual) . ' does not contain ' . $this->analyzer->getTypeOf($expected)); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /classes/constraints/containsOnly.php: -------------------------------------------------------------------------------- 1 | analyzer = $analyzer ?: new analyzer(); 20 | $this->expected = $expected; 21 | $this->description = $description; 22 | $this->isNativeType = $isNativeType; 23 | } 24 | 25 | protected function matches($actual) 26 | { 27 | if (self::isType($this->expected) === false) { 28 | throw new PHPUnit\Framework\Exception('Expected value of ' . __CLASS__ . ' must be a valid type or class name'); 29 | } 30 | 31 | if ($this->analyzer->isArray($actual) === false && $actual instanceof \traversable === false) { 32 | throw new PHPUnit\Framework\Exception('Actual value of ' . __CLASS__ . ' must be an array or a traversable object'); 33 | } 34 | 35 | try { 36 | $assertion = self::getAssertion($this->expected); 37 | 38 | foreach ($actual as $value) { 39 | $assertion($value); 40 | } 41 | } catch (exceptions\logic $exception) { 42 | throw new PHPUnit\Framework\Exception('Expected value of ' . __CLASS__ . ' must be a class instance or class name'); 43 | } 44 | } 45 | 46 | private static function getAssertion($type) 47 | { 48 | $assertion = null; 49 | $transform = null; 50 | $expected = null; 51 | 52 | switch ($type) { 53 | case 'int': 54 | $classname = asserters\integer::class; 55 | break; 56 | 57 | case 'float': 58 | $classname = asserters\phpFloat::class; 59 | break; 60 | 61 | case 'bool': 62 | $classname = asserters\boolean::class; 63 | break; 64 | 65 | case 'string': 66 | $classname = asserters\phpString::class; 67 | break; 68 | 69 | case 'array': 70 | $classname = asserters\phpArray::class; 71 | break; 72 | 73 | case 'null': 74 | $classname = asserters\variable::class; 75 | $assertion = 'isNull'; 76 | break; 77 | 78 | case 'scalar': 79 | case 'numeric': 80 | case 'double': 81 | case 'real': 82 | case 'callable': 83 | $classname = asserters\boolean::class; 84 | $transform = 'is_' . $type; 85 | $assertion = 'isTrue'; 86 | break; 87 | 88 | case 'boolean': 89 | case 'integer': 90 | case 'resource': 91 | $classname = 'mageekguy\atoum\asserters\\' . $type; 92 | break; 93 | 94 | default: 95 | $classname = asserters\phpObject::class; 96 | 97 | if ($type !== 'object') { 98 | $assertion = 'isInstanceOf'; 99 | $expected = $type; 100 | } 101 | } 102 | 103 | return function ($actual) use ($classname, $assertion, $transform, $expected) { 104 | $asserter = new $classname(); 105 | 106 | if ($transform !== null) { 107 | $actual = call_user_func($transform, $actual); 108 | } 109 | 110 | try { 111 | $asserter->setWith($actual); 112 | } catch (exceptions\logic $exception) { 113 | throw new PHPUnit\Framework\Exception('Expected value of ' . __CLASS__ . ' must be a valid type or class name'); 114 | } 115 | 116 | if ($assertion !== null) { 117 | $asserter->{$assertion}($expected); 118 | } 119 | }; 120 | } 121 | 122 | private static function isType($type, $isNativeType = null) 123 | { 124 | $isClassOrInterface = class_exists($type) || interface_exists($type); 125 | $isNative = in_array( 126 | $type, 127 | [ 128 | 'array', 129 | 'boolean', 130 | 'bool', 131 | 'double', 132 | 'float', 133 | 'integer', 134 | 'int', 135 | 'null', 136 | 'numeric', 137 | 'object', 138 | 'real', 139 | 'resource', 140 | 'string', 141 | 'scalar', 142 | 'callable' 143 | ] 144 | ); 145 | 146 | if ($isNativeType === null) { 147 | return $isClassOrInterface || $isNative; 148 | } 149 | 150 | return $isNativeType === true ? $isNative : $isClassOrInterface; 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /classes/constraints/containsOnlyInstancesOf.php: -------------------------------------------------------------------------------- 1 | analyzer = $analyzer ?: new analyzer(); 19 | $this->expected = $expected; 20 | $this->description = $description; 21 | } 22 | 23 | protected function matches($actual) 24 | { 25 | if ($this->analyzer->isArray($actual) === false && $actual instanceof \traversable === false) { 26 | throw new PHPUnit\Framework\Exception('Actual value of ' . __CLASS__ . ' must be an array or a traversable object'); 27 | } 28 | 29 | try { 30 | $asserter = new asserters\phpObject(null, $this->analyzer); 31 | 32 | foreach ($actual as $value) { 33 | $asserter->setWith($value)->isInstanceOf($this->expected); 34 | } 35 | } catch (exceptions\logic $exception) { 36 | throw new PHPUnit\Framework\Exception('Expected value of ' . __CLASS__ . ' must be a class instance or class name'); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /classes/constraints/count.php: -------------------------------------------------------------------------------- 1 | analyzer = $analyzer ?: new analyzer(); 18 | $this->expected = $expected; 19 | $this->description = $description; 20 | } 21 | 22 | protected function matches($actual) 23 | { 24 | if ($this->analyzer->isInteger($this->expected) === false) { 25 | throw new PHPUnit\Framework\Exception('Expected value of ' . __CLASS__ . ' must be an integer'); 26 | } 27 | 28 | switch (true) { 29 | case $this->analyzer->isArray($actual): 30 | $asserter = new asserters\phpArray(null, $this->analyzer); 31 | $asserter->setWith($actual)->hasSize($this->expected, $this->description); 32 | break; 33 | 34 | case $actual instanceof \countable: 35 | $asserter = new asserters\sizeOf(null, $this->analyzer); 36 | $asserter->setWith($actual)->isEqualTo($this->expected, $this->description); 37 | break; 38 | 39 | case $actual instanceof \iteratorAggregate: 40 | $asserter = new asserters\integer(null, $this->analyzer); 41 | $asserter->setWith(iterator_count($actual->getIterator()))->isEqualTo($this->expected, $this->description); 42 | break; 43 | 44 | case $actual instanceof \traversable: 45 | case $actual instanceof \iterator: 46 | $asserter = new asserters\integer(null, $this->analyzer); 47 | $asserter->setWith(iterator_count($actual))->isEqualTo($this->expected); 48 | break; 49 | 50 | default: 51 | throw new PHPUnit\Framework\Exception('Actual value of ' . __CLASS__ . ' must be an array, a countable object or a traversable object'); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /classes/constraints/equals.php: -------------------------------------------------------------------------------- 1 | expected = $expected; 21 | $this->description = $description; 22 | $this->delta = $delta; 23 | $this->maxDepth = $maxDepth ?: 10; 24 | $this->canonicalize = (bool) $canonicalize; 25 | $this->ignoreCase = (bool) $ignoreCase; 26 | $this->analyzer = $analyzer ?: new analyzer(); 27 | } 28 | 29 | protected function matches($actual) 30 | { 31 | if ($this->delta == null && $this->analyzer->isFloat($actual) === false && $this->analyzer->isFloat($this->expected) === false) { 32 | $asserter = new asserters\variable(null, $this->analyzer); 33 | 34 | if ($this->analyzer->isString($actual) && $this->ignoreCase) { 35 | $actual = strtolower($actual); 36 | } 37 | 38 | if ($this->analyzer->isArray($actual) && $this->canonicalize) { 39 | $actual = sort($actual); 40 | } 41 | 42 | $asserter->setWith($actual); 43 | 44 | if (($actual === 0 && $this->expected == '') || ($actual == '' && $this->expected === 0)) { 45 | $asserter->isIdenticalTo($this->expected); 46 | } else { 47 | $expected = $this->expected; 48 | 49 | if ($this->analyzer->isString($expected) && $this->ignoreCase) { 50 | $expected = strtolower($expected); 51 | } 52 | 53 | if ($this->analyzer->isArray($expected) && $this->canonicalize) { 54 | $expected = sort($expected); 55 | } 56 | 57 | $asserter->isEqualTo($expected); 58 | } 59 | } else { 60 | $asserter = new asserters\phpFloat(null, $this->analyzer); 61 | $asserter->setWith((float) $actual)->isNearlyEqualTo((float) $this->expected, $this->delta); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /classes/constraints/finite.php: -------------------------------------------------------------------------------- 1 | description = $description; 17 | $this->analyzer = $analyzer ?: new analyzer(); 18 | } 19 | 20 | protected function matches($actual) 21 | { 22 | $asserter = new asserters\boolean(); 23 | 24 | try { 25 | $asserter->setWith(is_finite($actual))->isTrue(); 26 | } catch (exception $exception) { 27 | throw new exception($asserter, $this->analyzer->getTypeOf($actual) . ' is not finite'); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /classes/constraints/greaterThan.php: -------------------------------------------------------------------------------- 1 | expected = $expected; 17 | $this->description = $description; 18 | $this->analyzer = $analyzer ?: new analyzer(); 19 | } 20 | 21 | protected function matches($actual) 22 | { 23 | if (is_float($actual)) { 24 | $asserter = new asserters\phpFloat(); 25 | } else { 26 | $asserter = new asserters\integer(); 27 | } 28 | 29 | 30 | $asserter->setWith($actual)->isGreaterThan($this->expected); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /classes/constraints/greaterThanOrEqual.php: -------------------------------------------------------------------------------- 1 | expected = $expected; 18 | } 19 | 20 | protected function matches($actual) 21 | { 22 | try { 23 | parent::matches($actual); 24 | } catch (exception $exception) { 25 | if (is_float($actual)) { 26 | $asserter = new asserters\phpFloat(); 27 | } else { 28 | $asserter = new asserters\integer(); 29 | } 30 | 31 | 32 | $asserter->setWith($actual)->isGreaterThanOrEqualTo($this->expected); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /classes/constraints/infinite.php: -------------------------------------------------------------------------------- 1 | description = $description; 17 | $this->analyzer = $analyzer ?: new analyzer(); 18 | } 19 | 20 | protected function matches($actual) 21 | { 22 | $asserter = new asserters\boolean(); 23 | 24 | try { 25 | $asserter->setWith(is_infinite($actual))->isTrue(); 26 | } catch (exception $exception) { 27 | throw new exception($asserter, $this->analyzer->getTypeOf($actual) . ' is not infinite'); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /classes/constraints/internalType.php: -------------------------------------------------------------------------------- 1 | expected = $expected; 18 | $this->description = $description; 19 | $this->analyzer = $analyzer ?: new analyzer(); 20 | } 21 | 22 | protected function matches($actual) 23 | { 24 | if (self::isType($this->expected) === false) { 25 | throw new PHPUnit\Framework\Exception('Expected value of ' . __CLASS__ . ' must be a valid type'); 26 | } 27 | 28 | $assertion = self::getAssertion($this->expected, $this->analyzer); 29 | $assertion($actual); 30 | } 31 | 32 | private static function getAssertion($type, analyzer $analyzer) 33 | { 34 | $namespace = 'mageekguy\atoum\asserters'; 35 | $assertion = null; 36 | $transform = null; 37 | $expected = null; 38 | $message = null; 39 | 40 | switch ($type) { 41 | case 'int': 42 | $classname = $namespace . '\\integer'; 43 | break; 44 | 45 | case 'float': 46 | $classname = $namespace . '\\phpFloat'; 47 | break; 48 | 49 | case 'bool': 50 | $classname = $namespace . '\\boolean'; 51 | break; 52 | 53 | case 'string': 54 | $classname = $namespace . '\\phpString'; 55 | break; 56 | 57 | case 'array': 58 | $classname = $namespace . '\\phpArray'; 59 | break; 60 | 61 | case 'null': 62 | $classname = $namespace . '\\variable'; 63 | $assertion = 'isNull'; 64 | break; 65 | 66 | case 'scalar': 67 | case 'numeric': 68 | case 'double': 69 | case 'real': 70 | case 'callable': 71 | $classname = $namespace . '\\boolean'; 72 | $transform = 'is_' . $type; 73 | $assertion = 'isTrue'; 74 | $message = '%s is not a %s'; 75 | break; 76 | 77 | case 'boolean': 78 | case 'integer': 79 | case 'resource': 80 | $classname = $namespace . '\\' . $type; 81 | break; 82 | 83 | default: 84 | $classname = $namespace . '\\object'; 85 | } 86 | 87 | return function ($actual) use ($classname, $assertion, $transform, $expected, $message, $type, $analyzer) { 88 | $asserter = new $classname(); 89 | 90 | if ($message !== null) { 91 | $message = sprintf($message, $analyzer->getTypeOf($actual), $type); 92 | } 93 | 94 | if ($transform !== null) { 95 | $actual = call_user_func($transform, $actual); 96 | } 97 | 98 | try { 99 | $asserter->setWith($actual, $message); 100 | } catch (exceptions\logic $exception) { 101 | throw new PHPUnit\Framework\Exception('Expected value of ' . __CLASS__ . ' must be a valid type or class name'); 102 | } 103 | 104 | if ($assertion !== null) { 105 | $asserter->{$assertion}($expected ?: $message, $message); 106 | } 107 | }; 108 | } 109 | 110 | private static function isType($type) 111 | { 112 | return in_array( 113 | $type, 114 | [ 115 | 'array', 116 | 'boolean', 117 | 'bool', 118 | 'double', 119 | 'float', 120 | 'integer', 121 | 'int', 122 | 'null', 123 | 'numeric', 124 | 'object', 125 | 'real', 126 | 'resource', 127 | 'string', 128 | 'scalar', 129 | 'callable' 130 | ] 131 | ); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /classes/constraints/isEmpty.php: -------------------------------------------------------------------------------- 1 | description = $description; 17 | $this->analyzer = $analyzer ?: new analyzer(); 18 | } 19 | 20 | protected function matches($actual) 21 | { 22 | if ($actual instanceof \countable) { 23 | $asserter = new atoumAsserters\sizeOf(null, $this->analyzer); 24 | $asserter->setWith($actual)->isEqualTo(0, $this->description); 25 | } else { 26 | $asserter = new atoumPHPUnitAsserters\variable(null, $this->analyzer); 27 | $asserter->setWith($actual)->isEmpty($this->description); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /classes/constraints/isInstanceOf.php: -------------------------------------------------------------------------------- 1 | expected = $expected; 17 | $this->description = $description; 18 | } 19 | 20 | protected function matches($actual) 21 | { 22 | $asserter = new asserters\phpObject(); 23 | 24 | try { 25 | $asserter->setWith($actual)->isInstanceOf($this->expected); 26 | } catch (logic $exception) { 27 | throw new PHPUnit\Framework\Exception($exception->getMessage()); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /classes/constraints/isNotEmpty.php: -------------------------------------------------------------------------------- 1 | description = $description; 17 | $this->analyzer = $analyzer ?: new analyzer(); 18 | } 19 | 20 | protected function matches($actual) 21 | { 22 | if ($actual instanceof \countable) { 23 | $asserter = new atoumAsserters\sizeOf(null, $this->analyzer); 24 | $asserter->setWith($actual)->isNotEqualTo(0, $this->description); 25 | } else { 26 | $asserter = new atoumPHPUnitAsserters\variable(null, $this->analyzer); 27 | $asserter->setWith($actual)->isNotEmpty($this->description); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /classes/constraints/isNotInstanceOf.php: -------------------------------------------------------------------------------- 1 | expected = $expected; 17 | $this->description = $description; 18 | } 19 | 20 | protected function matches($actual) 21 | { 22 | $asserter = new asserters\phpObject(); 23 | 24 | try { 25 | $asserter->setWith($actual)->isNotInstanceOf($this->expected); 26 | } catch (logic $exception) { 27 | throw new PHPUnit\Framework\Exception($exception->getMessage()); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /classes/constraints/isNotNull.php: -------------------------------------------------------------------------------- 1 | description = $description; 13 | } 14 | 15 | protected function matches($actual) 16 | { 17 | $asserter = new asserters\variable(); 18 | $asserter->setWith($actual)->isNotNull(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /classes/constraints/isNull.php: -------------------------------------------------------------------------------- 1 | description = $description; 13 | } 14 | 15 | protected function matches($actual) 16 | { 17 | $asserter = new asserters\variable(); 18 | $asserter->setWith($actual)->isNull(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /classes/constraints/nan.php: -------------------------------------------------------------------------------- 1 | description = $description; 17 | $this->analyzer = $analyzer ?: new analyzer(); 18 | } 19 | 20 | protected function matches($actual) 21 | { 22 | $asserter = new asserters\boolean(); 23 | 24 | try { 25 | $asserter->setWith(is_nan($actual))->isTrue(); 26 | } catch (exception $exception) { 27 | throw new exception($asserter, $this->analyzer->getTypeOf($actual) . ' is not NaN'); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /classes/constraints/notCount.php: -------------------------------------------------------------------------------- 1 | analyzer->isInteger($this->expected) === false) { 16 | throw new PHPUnit\Framework\Exception('Expected value of ' . __CLASS__ . ' must be an integer'); 17 | } 18 | 19 | switch (true) { 20 | case $this->analyzer->isArray($actual): 21 | $asserter = new atoumPHPUnitAsserters\phpArray(null, $this->analyzer); 22 | $asserter->setWith($actual)->hasNotSize($this->expected, $this->description); 23 | break; 24 | 25 | case $actual instanceof \countable: 26 | $asserter = new atoumAsserters\sizeOf(null, $this->analyzer); 27 | $asserter->setWith($actual)->isNotEqualTo($this->expected, $this->description); 28 | break; 29 | 30 | case $actual instanceof \iteratorAggregate: 31 | $asserter = new atoumAsserters\integer(null, $this->analyzer); 32 | $asserter->setWith(iterator_count($actual->getIterator()))->isNotEqualTo($this->expected, $this->description); 33 | break; 34 | 35 | case $actual instanceof \traversable: 36 | case $actual instanceof \iterator: 37 | $asserter = new atoumAsserters\integer(null, $this->analyzer); 38 | $asserter->setWith(iterator_count($actual))->isNotEqualTo($this->expected); 39 | break; 40 | 41 | default: 42 | throw new PHPUnit\Framework\Exception('Actual value of ' . __CLASS__ . ' must be an array, a countable object or a traversable object'); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /classes/constraints/notSame.php: -------------------------------------------------------------------------------- 1 | expected = $expected; 15 | $this->description = $description; 16 | } 17 | 18 | protected function matches($actual) 19 | { 20 | $asserter = new asserters\variable(); 21 | $asserter->setWith($actual)->isNotIdenticalTo($this->expected); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /classes/constraints/objectHasAttribute.php: -------------------------------------------------------------------------------- 1 | analyzer = $analyzer ?: new analyzer(); 20 | $this->attribute = $attribute; 21 | $this->description = $description; 22 | $this->asserter = new asserters\phpObject(null, $this->analyzer); 23 | } 24 | 25 | protected function matches($actual) 26 | { 27 | if ($this->analyzer->isObject($actual) === false) { 28 | throw new PHPUnit\Framework\Exception('Actual value of ' . __CLASS__ . ' must be an object'); 29 | } 30 | 31 | if ($this->analyzer->isString($this->attribute) === false) { 32 | throw new PHPUnit\Framework\Exception('Attribute value of ' . __CLASS__ . ' must be a string'); 33 | } 34 | 35 | $this->asserter->setWith($actual); 36 | $this->asserter->hasAttribute($this->attribute, $this->description); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /classes/constraints/objectNotHasAttribute.php: -------------------------------------------------------------------------------- 1 | analyzer = $analyzer ?: new analyzer(); 20 | $this->attribute = $attribute; 21 | $this->description = $description; 22 | $this->asserter = new asserters\phpObject(null, $this->analyzer); 23 | } 24 | 25 | protected function matches($actual) 26 | { 27 | if ($this->analyzer->isObject($actual) === false) { 28 | throw new PHPUnit\Framework\Exception('Actual value of ' . __CLASS__ . ' must be an object'); 29 | } 30 | 31 | if ($this->analyzer->isString($this->attribute) === false) { 32 | throw new PHPUnit\Framework\Exception('Attribute value of ' . __CLASS__ . ' must be a string'); 33 | } 34 | 35 | $this->asserter->setWith($actual); 36 | $this->asserter->hasNotAttribute($this->attribute, $this->description); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /classes/constraints/same.php: -------------------------------------------------------------------------------- 1 | expected = $expected; 15 | $this->description = $description; 16 | } 17 | 18 | protected function matches($actual) 19 | { 20 | $asserter = new asserters\variable(); 21 | $asserter->setWith($actual)->isIdenticalTo($this->expected); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /classes/extension.php: -------------------------------------------------------------------------------- 1 | getScript()->getArgumentsParser(); 18 | 19 | $handler = function ($script, $argument, $values) { 20 | $script->getRunner()->addTestsFromDirectory(dirname(__DIR__) . '/tests/units/classes'); 21 | }; 22 | 23 | $parser 24 | ->addHandler($handler, ['--test-ext']) 25 | ->addHandler($handler, ['--test-it']) 26 | ; 27 | } 28 | } 29 | 30 | public function addToRunner(runner $runner) 31 | { 32 | $runner->addExtension($this); 33 | 34 | return $this; 35 | } 36 | 37 | public function setRunner(runner $runner) 38 | { 39 | $this->runner = $runner; 40 | 41 | return $this; 42 | } 43 | 44 | public function getRunner() 45 | { 46 | return $this->runner; 47 | } 48 | 49 | public function setTest(atoum\test $test) 50 | { 51 | $this->test = $test; 52 | 53 | return $this; 54 | } 55 | 56 | public function getTest() 57 | { 58 | return $this->test; 59 | } 60 | 61 | public function handleEvent($event, observable $observable) 62 | { 63 | return $this; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /classes/test.php: -------------------------------------------------------------------------------- 1 | setDefaultEngine(static::defaultEngine); 30 | } 31 | 32 | public function setAsserterGenerator(atoum\test\asserter\generator $generator = null) 33 | { 34 | $generator = $generator ?: new atoum\test\asserter\generator($this); 35 | 36 | $generator 37 | ->addNamespace(__NAMESPACE__ . '\\asserters'); 38 | 39 | return parent::setAsserterGenerator($generator); 40 | } 41 | 42 | public function setAssertionManager(assertion\manager $assertionManager = null) 43 | { 44 | parent::setAssertionManager($assertionManager); 45 | 46 | $test = $this; 47 | 48 | $this->getAssertionManager() 49 | ->setHandler( 50 | 'assertArrayHasKey', 51 | function ($expected, $actual, $failMessage = null) use ($test) { 52 | $test->assertThat($actual, new atoum\phpunit\constraints\arrayHasKey($expected, $failMessage, $test->getAnalyzer())); 53 | 54 | return $test; 55 | } 56 | ) 57 | ->setHandler( 58 | 'assertArraySubset', 59 | function (array $expected, array $actual, $failMessage = null, $strict = null) use ($test) { 60 | $test->assertThat($actual, new atoum\phpunit\constraints\arraySubset($expected, $failMessage, $strict, $test->getAnalyzer())); 61 | 62 | return $test; 63 | } 64 | ) 65 | ->setHandler( 66 | 'assertContainsOnly', 67 | function ($expected, $actual, $isNativeType = null, $failMessage = null) use ($test) { 68 | $test->assertThat($actual, new atoum\phpunit\constraints\containsOnly($expected, $isNativeType, $failMessage, $test->getAnalyzer())); 69 | 70 | return $test; 71 | } 72 | ) 73 | ->setHandler( 74 | 'assertContainsOnlyInstancesOf', 75 | function ($expected, $actual, $failMessage = null) use ($test) { 76 | $test->assertThat($actual, new atoum\phpunit\constraints\containsOnlyInstancesOf($expected, $failMessage, $test->getAnalyzer())); 77 | 78 | return $test; 79 | } 80 | ) 81 | ->setHandler( 82 | 'assertCount', 83 | function ($expected, $actual, $failMessage = null) use ($test) { 84 | $test->assertThat($actual, new atoum\phpunit\constraints\count($expected, $failMessage, $test->getAnalyzer())); 85 | 86 | return $test; 87 | } 88 | ) 89 | ->setHandler( 90 | 'assertNotCount', 91 | function ($expected, $actual, $failMessage = null) use ($test) { 92 | $test->assertThat($actual, new atoum\phpunit\constraints\notCount($expected, $failMessage, $test->getAnalyzer())); 93 | 94 | return $test; 95 | } 96 | ) 97 | ->setHandler( 98 | 'assertEmpty', 99 | function ($actual, $failMessage = null) use ($test) { 100 | $test->assertThat($actual, new atoum\phpunit\constraints\isEmpty($failMessage, $test->getAnalyzer())); 101 | 102 | return $test; 103 | } 104 | ) 105 | ->setHandler( 106 | 'assertNotEmpty', 107 | function ($actual, $failMessage = null) use ($test) { 108 | $test->assertThat($actual, new atoum\phpunit\constraints\isNotEmpty($failMessage, $test->getAnalyzer())); 109 | 110 | return $test; 111 | } 112 | ) 113 | ->setHandler( 114 | 'assertEquals', 115 | function ($expected, $actual, $failMessage = null, $delta = null, $maxDepth = null, $canonicalize = null, $ignoreCase = null) use ($test) { 116 | $test->assertThat($actual, new atoum\phpunit\constraints\equals($expected, $failMessage, $delta, $maxDepth, $canonicalize, $ignoreCase, $test->getAnalyzer())); 117 | 118 | return $test; 119 | } 120 | ) 121 | ->setHandler( 122 | 'assertFalse', 123 | function ($actual, $failMessage = null) use ($test) { 124 | $test->assertThat($actual, new atoum\phpunit\constraints\boolean(false, $failMessage, $test->getAnalyzer())); 125 | 126 | return $test; 127 | } 128 | ) 129 | ->setHandler( 130 | 'assertFinite', 131 | function ($actual, $failMessage = null) use ($test) { 132 | $test->assertThat($actual, new atoum\phpunit\constraints\finite($failMessage, $test->getAnalyzer())); 133 | 134 | return $test; 135 | } 136 | ) 137 | ->setHandler( 138 | 'assertGreaterThan', 139 | function ($expected, $actual, $failMessage = null) use ($test) { 140 | $test->assertThat($actual, new atoum\phpunit\constraints\greaterThan($expected, $failMessage, $test->getAnalyzer())); 141 | 142 | return $test; 143 | } 144 | ) 145 | ->setHandler( 146 | 'assertGreaterThanOrEqual', 147 | function ($expected, $actual, $failMessage = null) use ($test) { 148 | $test->assertThat($actual, new atoum\phpunit\constraints\greaterThanOrEqual($expected, $failMessage, $test->getAnalyzer())); 149 | 150 | return $test; 151 | } 152 | ) 153 | ->setHandler( 154 | 'assertInfinite', 155 | function ($actual, $failMessage = null) use ($test) { 156 | $test->assertThat($actual, new atoum\phpunit\constraints\infinite($failMessage)); 157 | 158 | return $test; 159 | } 160 | ) 161 | ->setHandler( 162 | 'assertInstanceOf', 163 | function ($expected, $actual, $failMessage = null) use ($test) { 164 | $test->assertThat($actual, new atoum\phpunit\constraints\isInstanceOf($expected, $failMessage)); 165 | 166 | return $test; 167 | } 168 | ) 169 | ->setHandler( 170 | 'assertInternalType', 171 | function ($expected, $actual, $failMessage = null) use ($test) { 172 | $test->assertThat($actual, new atoum\phpunit\constraints\internalType($expected, $failMessage)); 173 | 174 | return $test; 175 | } 176 | ) 177 | ->setHandler( 178 | 'assertNaN', 179 | function ($actual, $failMessage = null) use ($test) { 180 | $test->assertThat($actual, new atoum\phpunit\constraints\nan($failMessage)); 181 | 182 | return $test; 183 | } 184 | ) 185 | ->setHandler( 186 | 'assertNotInstanceOf', 187 | function ($expected, $actual, $failMessage = null) use ($test) { 188 | $test->assertThat($actual, new atoum\phpunit\constraints\isNotInstanceOf($expected, $failMessage)); 189 | 190 | return $test; 191 | } 192 | ) 193 | ->setHandler( 194 | 'assertNotNull', 195 | function ($actual, $failMessage = null) use ($test) { 196 | $test->assertThat($actual, new atoum\phpunit\constraints\isNotNull($failMessage)); 197 | 198 | return $test; 199 | } 200 | ) 201 | ->setHandler( 202 | 'assertNotSame', 203 | function ($expected, $actual, $failMessage = null) use ($test) { 204 | $test->assertThat($actual, new atoum\phpunit\constraints\notSame($expected, $failMessage)); 205 | 206 | return $test; 207 | } 208 | ) 209 | ->setHandler( 210 | 'assertNull', 211 | function ($actual, $failMessage = null) use ($test) { 212 | $test->assertThat($actual, new atoum\phpunit\constraints\isNull($failMessage)); 213 | 214 | return $test; 215 | } 216 | ) 217 | ->setHandler( 218 | 'assertObjectHasAttribute', 219 | function ($attribute, $object, $failMessage = null) use ($test) { 220 | $test->assertThat($object, new atoum\phpunit\constraints\objectHasAttribute($attribute, $failMessage)); 221 | 222 | return $test; 223 | } 224 | ) 225 | ->setHandler( 226 | 'assertObjectNotHasAttribute', 227 | function ($attribute, $object, $failMessage = null) use ($test) { 228 | $test->assertThat($object, new atoum\phpunit\constraints\objectNotHasAttribute($attribute, $failMessage)); 229 | 230 | return $test; 231 | } 232 | ) 233 | ->setHandler( 234 | 'assertSame', 235 | function ($expected, $actual, $failMessage = null) use ($test) { 236 | $test->assertThat($actual, new atoum\phpunit\constraints\same($expected, $failMessage)); 237 | 238 | return $test; 239 | } 240 | ) 241 | ->setHandler( 242 | 'assertTrue', 243 | function ($actual, $failMessage = null) use ($test) { 244 | $test->assertThat($actual, new atoum\phpunit\constraints\boolean(true, $failMessage, $test->getAnalyzer())); 245 | 246 | return $test; 247 | } 248 | ) 249 | ->setHandler( 250 | 'getMock', 251 | function () use ($test) { 252 | $test->skip('getMock is not supported.'); 253 | } 254 | ) 255 | ->setHandler( 256 | 'getMockForAbstractClass', 257 | function () use ($test) { 258 | $test->skip('getMockForAbstractClass is not supported.'); 259 | } 260 | ) 261 | ->setHandler( 262 | 'setExpectedException', 263 | function () use ($test) { 264 | $test->skip('setExpectedException is not supported.'); 265 | } 266 | ) 267 | ; 268 | 269 | return $this; 270 | } 271 | 272 | /** 273 | * Override the parent definition to allow to re-assign a new value for 274 | * the tested class name. 275 | */ 276 | public function setTestedClassName($className) 277 | { 278 | static $reflectionProperty = null; 279 | 280 | if (null === $reflectionProperty) { 281 | $reflectionProperty = (new \ReflectionClass(parent::class))->getProperty('testedClassName'); 282 | $reflectionProperty->setAccessible(true); 283 | } 284 | 285 | $reflectionProperty->setValue($this, null); 286 | 287 | return parent::setTestedClassName($className); 288 | } 289 | 290 | public function getTestedClassName() 291 | { 292 | // atoum creates a default relation between a test suite and a class, 293 | // they are correlated. PHPUnit doesn't do that. If a test suite extends 294 | // `PHPUnit\Framework\TestCase`, then it is assumed that this relation 295 | // must be canceled, if a test suite extends `atoum\phpunit\test`, 296 | // then the relation is kept. The former is a child of the latter, so 297 | // it is easy to implement. 298 | // 299 | // The constant and function mock engines, and the code coverage 300 | // scores will not work. 301 | if (true === $this->breakRelationBetweenTestSuiteAndSUT && 302 | $this instanceof PHPUnit\Framework\TestCase) { 303 | return 304 | null !== $this->defaultTestedClassName 305 | ? $this->defaultTestedClassName 306 | : 'StdClass'; 307 | } 308 | 309 | $testedClassName = parent::getTestedClassName(); 310 | 311 | return preg_replace('/(?skip($message); 328 | } 329 | 330 | protected function setMethodAnnotations(annotations\extractor $extractor, & $methodName) 331 | { 332 | parent::setMethodAnnotations($extractor, $methodName); 333 | 334 | $tagHandler = function ($value) use (& $methodName) { 335 | $this->setMethodTags($methodName, annotations\extractor::toArray($value)); 336 | }; 337 | 338 | $extractor 339 | ->setHandler('author', $tagHandler) 340 | ->setHandler( 341 | 'expectedException', 342 | function ($value) use (& $methodName) { 343 | if ($value) { 344 | $this->addUnsupportedMethod($methodName, '@expectedException is not supported.'); 345 | } 346 | } 347 | ) 348 | ->setHandler('group', $tagHandler) 349 | ->setHandler( 350 | 'large', 351 | function () use ($tagHandler) { 352 | $tagHandler('large'); 353 | } 354 | ) 355 | ->setHandler( 356 | 'medium', 357 | function () use ($tagHandler) { 358 | $tagHandler('medium'); 359 | } 360 | ) 361 | ->setHandler( 362 | 'runInSeparateProcess', 363 | function () use (& $methodName) { 364 | $this->setMethodEngine($methodName, 'isolate'); 365 | } 366 | ) 367 | ->setHandler( 368 | 'small', 369 | function () use ($tagHandler) { 370 | $tagHandler('small'); 371 | } 372 | ) 373 | ->setHandler( 374 | 'covers', 375 | function ($value) use (& $methodName) { 376 | // We only care about the classname to compute the real 377 | // code coverage score, nothing else. 378 | if (0 !== preg_match('/^([^:]+)(::)?/', $value, $matches)) { 379 | $this->testedClassNames[$methodName] = $matches[1]; 380 | } 381 | } 382 | ) 383 | ->setHandler( 384 | 'coversNothing', 385 | function () use (& $methodName) { 386 | $this->testedClassNames[$methodName] = 'StdClass'; 387 | } 388 | ); 389 | 390 | return $this; 391 | } 392 | 393 | protected function setClassAnnotations(annotations\extractor $extractor) 394 | { 395 | parent::setClassAnnotations($extractor); 396 | 397 | $extractor 398 | ->setHandler( 399 | 'runTestsInSeparateProcesses', 400 | function () use (& $methodName) { 401 | $this->setMethodEngine($methodName, 'isolate'); 402 | } 403 | ) 404 | ->setHandler( 405 | 'coversDefaultClass', 406 | function ($value) { 407 | $this->defaultTestedClassName = $value; 408 | $this->setTestedClassName($value); 409 | } 410 | ); 411 | 412 | return $this; 413 | } 414 | 415 | 416 | public function addUnsupportedMethod($testMethod, $reason) 417 | { 418 | if (isset($this->unsupportedMethods[$testMethod]) === false) { 419 | $this->unsupportedMethods[$testMethod] = $reason; 420 | } 421 | 422 | return $this; 423 | } 424 | 425 | /** 426 | * The `setUp` method in atoum maps to the `setUpBeforeClass` method in 427 | * PHPUnit. 428 | */ 429 | protected function callSetUp() 430 | { 431 | static::setUpBeforeClass(); 432 | } 433 | 434 | /** 435 | * The `tearDown` method in atoum maps to the `tearDownAfterClass` method 436 | * in PHPUnit. 437 | */ 438 | protected function callTearDown() 439 | { 440 | static::tearDownAfterClass(); 441 | } 442 | 443 | /** 444 | * The `beforeTestMethod` method in atoum maps to the `setUp` method in 445 | * PHPUnit. 446 | */ 447 | protected function callBeforeTestMethod($testMethod) 448 | { 449 | $this->beforeTestMethod($testMethod); 450 | $this->setUp(); 451 | } 452 | 453 | /** 454 | * The `afterTestMethod` method in atoum maps to the `tearDown` method in 455 | * PHPUnit. 456 | */ 457 | protected function callAfterTestMethod($testMethod) 458 | { 459 | $this->afterTestMethod($testMethod); 460 | $this->tearDown(); 461 | } 462 | 463 | public static function setUpBeforeClass() 464 | { 465 | } 466 | 467 | public static function tearDownAfterClass() 468 | { 469 | } 470 | 471 | protected function setUp() 472 | { 473 | } 474 | 475 | protected function tearDown() 476 | { 477 | } 478 | 479 | public function beforeTestMethod($testMethod) 480 | { 481 | if (isset($this->unsupportedMethods[$testMethod])) { 482 | $this->markTestSkipped($this->unsupportedMethods[$testMethod]); 483 | } else { 484 | if (isset($this->testedClassNames[$testMethod])) { 485 | $this->setTestedClassName($this->testedClassNames[$testMethod]); 486 | $this->breakRelationBetweenTestSuiteAndSUT = false; 487 | } 488 | 489 | // Based on the comment in `self::getTestedClassName`, it is 490 | // required to re-adjust the mock engines for constants and 491 | // functions. 492 | $testedClassName = self::getTestedClassNameFromTestClass( 493 | $this->getClass(), 494 | $this->getTestNamespace() 495 | ); 496 | $testedNamespace = substr( 497 | $testedClassName, 498 | 0, 499 | strrpos($testedClassName, '\\') 500 | ); 501 | 502 | $this->getPhpFunctionMocker()->setDefaultNamespace($testedNamespace); 503 | $this->getPhpConstantMocker()->setDefaultNamespace($testedNamespace); 504 | } 505 | } 506 | 507 | public function afterTestMethod($testMethod) 508 | { 509 | $this->breakRelationBetweenTestSuiteAndSUT = true; 510 | } 511 | } 512 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "atoum/phpunit-extension", 3 | "type": "library", 4 | "description": "atoum PHPUnit extension - Run your PHPUnit tests with atoum", 5 | "keywords": ["TDD", "atoum", "test", "unit testing", "PHPUnit", "atoum-extension"], 6 | "homepage": "http://www.atoum.org", 7 | "license": "BSD-3-Clause", 8 | "authors": [ 9 | { 10 | "name": "jubianchi", 11 | "email": "contact@jubianchi.fr" 12 | } 13 | ], 14 | "require": { 15 | "atoum/atoum": "dev-virtual-hooks as 3.3.0" 16 | }, 17 | "require-dev": { 18 | "phpunit/phpunit": "@stable" 19 | }, 20 | "autoload": { 21 | "psr-4": { 22 | "mageekguy\\atoum\\phpunit\\": "classes" 23 | }, 24 | "classmap": [ "phpunit/" ], 25 | "files": ["configuration.php"] 26 | }, 27 | "extra": { 28 | "branch-alias": { 29 | "dev-master": "0.x-dev" 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /configuration.php: -------------------------------------------------------------------------------- 1 | =') === true)) { 8 | scripts\runner::addConfigurationCallable(function (atoum\configurator $script, atoum\runner $runner) { 9 | $extension = new phpunit\extension($script); 10 | $extension->addToRunner($runner); 11 | }); 12 | } 13 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | ./tests/units/ 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /phpunit/AssertionFailedError.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\asserter', new testedClass()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/units/classes/constraintTest.php: -------------------------------------------------------------------------------- 1 | evaluate(uniqid(), $message); 39 | 40 | $this->fail(); 41 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 42 | $this->assertEquals($message, $exception->getMessage()); 43 | } 44 | 45 | $this->assertEquals(false, $constraint->evaluate(uniqid(), null, true)); 46 | 47 | $constraint = new passingConstraint(); 48 | 49 | $this->assertSame($constraint, $constraint->evaluate(uniqid())); 50 | $this->assertEquals(true, $constraint->evaluate(uniqid(), null, true)); 51 | } 52 | 53 | public function testCount() 54 | { 55 | $constraint = new passingConstraint(); 56 | 57 | $this->assertEquals(1, $constraint->count()); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/arrayHasKeyTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass(uniqid())); 14 | } 15 | 16 | public function testAssertArrayHasKeyThrowsExceptionForInvalidFirstArgument() 17 | { 18 | $constraint = new testedClass(null); 19 | 20 | try { 21 | $constraint->evaluate([]); 22 | 23 | $this->fail(); 24 | } catch (\PHPUnit\Framework\Exception $exception) { 25 | $this->assertEquals('Expected value of mageekguy\atoum\phpunit\constraints\arrayHasKey must not be null', $exception->getMessage()); 26 | } 27 | } 28 | 29 | public function testAssertArrayHasKeyThrowsExceptionForInvalidSecondArgument() 30 | { 31 | $constraint = new testedClass(0); 32 | 33 | try { 34 | $constraint->evaluate(null); 35 | 36 | $this->fail(); 37 | } catch (\PHPUnit\Framework\Exception $exception) { 38 | $this->assertEquals('Actual value of mageekguy\atoum\phpunit\constraints\arrayHasKey must be an array or an arrayAccess instance', $exception->getMessage()); 39 | } 40 | } 41 | 42 | public function testAssertArrayHasIntegerKey() 43 | { 44 | $actual = [uniqid()]; 45 | 46 | $constraint = new testedClass(0); 47 | $constraint->evaluate($actual); 48 | 49 | $constraint = new testedClass(1); 50 | 51 | try { 52 | $constraint->evaluate($actual); 53 | 54 | $this->fail(); 55 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 56 | $this->assertEquals('array(1) has no key integer(1)', $exception->getMessage()); 57 | } 58 | } 59 | 60 | public function testAssertArrayHasStringKey() 61 | { 62 | $key = uniqid(); 63 | $otherKey = uniqid(); 64 | $actual = [$key => uniqid()]; 65 | 66 | $constraint = new testedClass($key); 67 | $constraint->evaluate($actual); 68 | 69 | $constraint = new testedClass($otherKey); 70 | 71 | try { 72 | $constraint->evaluate($actual); 73 | 74 | $this->fail(); 75 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 76 | $this->assertEquals('array(1) has no key string(' . strlen($otherKey) . ') \'' . $otherKey . '\'', $exception->getMessage()); 77 | } 78 | } 79 | 80 | public function testAssertArrayAccessHasStringKey() 81 | { 82 | $key = uniqid(); 83 | $otherKey = uniqid(); 84 | $actual = new \sampleArrayAccess(); 85 | $actual[$key] = uniqid(); 86 | 87 | $constraint = new testedClass($key); 88 | $constraint->evaluate($actual); 89 | 90 | $constraint = new testedClass($otherKey); 91 | 92 | try { 93 | $constraint->evaluate($actual); 94 | 95 | $this->fail(); 96 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 97 | $this->assertEquals('object(SampleArrayAccess) has no key string(' . strlen($otherKey) . ') \'' . $otherKey . '\'', $exception->getMessage()); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/arraySubsetTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass([])); 13 | } 14 | 15 | public function testAssertArraySubset() 16 | { 17 | $array = [ 18 | 'a' => 'item a', 19 | 'b' => 'item b', 20 | 'c' => ['a2' => 'item a2', 'b2' => 'item b2'], 21 | 'd' => ['a2' => ['a3' => 'item a3', 'b3' => 'item b3']] 22 | ]; 23 | 24 | $constraint = new testedClass(['a' => 'item a', 'c' => ['a2' => 'item a2']]); 25 | $this->assertSame($constraint, $constraint->evaluate($array)); 26 | 27 | $constraint = new testedClass(['a' => 'item a', 'd' => ['a2' => ['b3' => 'item b3']]]); 28 | $this->assertSame($constraint, $constraint->evaluate($array)); 29 | 30 | $expected = ['a' => 'bad value']; 31 | $constraint = new testedClass($expected); 32 | 33 | $analyzer = new atoum\tools\variable\analyzer(); 34 | 35 | try { 36 | $constraint->evaluate($array); 37 | 38 | $this->fail(); 39 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 40 | $patched = array_replace_recursive($array, $expected); 41 | $diff = new atoum\tools\diffs\variable($patched, $array); 42 | $this->assertEquals($analyzer->getTypeOf($array) . ' is not equal to ' . $analyzer->getTypeOf($patched) . PHP_EOL . $diff, $exception->getMessage()); 43 | } 44 | 45 | $expected = ['d' => ['a2' => ['bad index' => 'item b3']]]; 46 | $constraint = new testedClass($expected); 47 | 48 | try { 49 | $constraint->evaluate($array); 50 | 51 | $this->fail(); 52 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 53 | $patched = array_replace_recursive($array, $expected); 54 | $diff = new atoum\tools\diffs\variable($patched, $array); 55 | $this->assertEquals($analyzer->getTypeOf($array) . ' is not equal to ' . $analyzer->getTypeOf($patched) . PHP_EOL . $diff, $exception->getMessage()); 56 | } 57 | } 58 | 59 | public function testAssertArraySubsetWithDeepNestedArrays() 60 | { 61 | $array = [ 62 | 'path' => [ 63 | 'to' => [ 64 | 'the' => [ 65 | 'cake' => 'is a lie' 66 | ] 67 | ] 68 | ] 69 | ]; 70 | 71 | $constraint = new testedClass(['path' => []]); 72 | $this->assertSame($constraint, $constraint->evaluate($array)); 73 | 74 | $constraint = new testedClass(['path' => ['to' => []]]); 75 | $this->assertSame($constraint, $constraint->evaluate($array)); 76 | 77 | $constraint = new testedClass(['path' => ['to' => ['the' => []]]]); 78 | $this->assertSame($constraint, $constraint->evaluate($array)); 79 | 80 | $constraint = new testedClass(['path' => ['to' => ['the' => ['cake' => 'is a lie']]]]); 81 | $this->assertSame($constraint, $constraint->evaluate($array)); 82 | 83 | $expected = ['path' => ['to' => ['the' => ['cake' => 'is not a lie']]]]; 84 | $constraint = new testedClass($expected); 85 | $analyzer = new atoum\tools\variable\analyzer(); 86 | 87 | try { 88 | $constraint->evaluate($array); 89 | 90 | $this->fail(); 91 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 92 | $patched = array_replace_recursive($array, $expected); 93 | $diff = new atoum\tools\diffs\variable($patched, $array); 94 | $this->assertEquals($analyzer->getTypeOf($array) . ' is not equal to ' . $analyzer->getTypeOf($patched) . PHP_EOL . $diff, $exception->getMessage()); 95 | } 96 | } 97 | 98 | public function testAssertArraySubsetWithNoStrictCheckAndObjects() 99 | { 100 | $obj = new \stdClass; 101 | $reference = &$obj; 102 | $array = ['a' => $obj]; 103 | 104 | $constraint = new testedClass(['a' => $reference]); 105 | $this->assertSame($constraint, $constraint->evaluate($array)); 106 | 107 | $constraint = new testedClass(['a' => new \stdClass]); 108 | $this->assertSame($constraint, $constraint->evaluate($array)); 109 | } 110 | 111 | public function testAssertArraySubsetWithStrictCheckAndObjects() 112 | { 113 | $obj = new \stdClass; 114 | $reference = &$obj; 115 | $array = ['a' => $obj]; 116 | 117 | $constraint = new testedClass(['a' => $reference], null, true); 118 | $this->assertSame($constraint, $constraint->evaluate($array)); 119 | 120 | $expected = ['a' => new \stdClass]; 121 | $constraint = new testedClass($expected, null, true); 122 | $analyzer = new atoum\tools\variable\analyzer(); 123 | 124 | try { 125 | $constraint->evaluate($array); 126 | 127 | $this->fail('Strict recursive array check fail.'); 128 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 129 | $patched = array_replace_recursive($array, $expected); 130 | $diff = new atoum\tools\diffs\variable($patched, $array); 131 | $this->assertEquals($analyzer->getTypeOf($array) . ' is not identical to ' . $analyzer->getTypeOf($patched) . PHP_EOL . $diff, $exception->getMessage()); 132 | } 133 | } 134 | 135 | /** 136 | * @dataProvider assertArraySubsetInvalidArgumentProvider 137 | */ 138 | public function testAssertArraySubsetRaisesExceptionForInvalidArguments($expected, $actual) 139 | { 140 | $constraint = new testedClass($expected); 141 | $analyzer = new atoum\tools\variable\analyzer(); 142 | 143 | try { 144 | $this->assertSame($constraint, $constraint->evaluate($actual)); 145 | 146 | $this->fail(); 147 | } catch (\PHPUnit\Framework\Exception $exception) { 148 | $this->assertEquals('Actual value of mageekguy\atoum\phpunit\constraints\arraySubset must be an array', $exception->getMessage()); 149 | } 150 | } 151 | 152 | public function assertArraySubsetInvalidArgumentProvider() 153 | { 154 | return [ 155 | //array(false, array()), 156 | [[], false], 157 | ]; 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/booleanTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass(true)); 13 | } 14 | 15 | public function testThrowsExceptionIfExpectedCountIsNoBoolean() 16 | { 17 | $constraint = new testedClass([]); 18 | 19 | try { 20 | $constraint->evaluate(true); 21 | 22 | $this->fail(); 23 | } catch (\PHPUnit\Framework\Exception $exception) { 24 | $this->assertEquals('Expected value of mageekguy\atoum\phpunit\constraints\boolean must be a boolean', $exception->getMessage()); 25 | } 26 | } 27 | 28 | public function testFailsIfActualIsNoBoolean() 29 | { 30 | $constraint = new testedClass(true); 31 | $actual = []; 32 | 33 | try { 34 | $constraint->evaluate($actual); 35 | 36 | $this->fail(); 37 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 38 | $analyzer = new atoum\tools\variable\analyzer(); 39 | $this->assertEquals($analyzer->getTypeOf($actual) . ' is not a boolean', $exception->getMessage()); 40 | } 41 | } 42 | 43 | public function testFails() 44 | { 45 | $constraint = new testedClass(true); 46 | 47 | try { 48 | $constraint->evaluate(false); 49 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 50 | $analyzer = new atoum\tools\variable\analyzer(); 51 | $diff = new atoum\tools\diff($analyzer->dump(true), $analyzer->dump(false)); 52 | $this->assertEquals($analyzer->getTypeOf(false) . ' is not true' . PHP_EOL . $diff, $exception->getMessage()); 53 | } 54 | 55 | $constraint = new testedClass(false); 56 | 57 | try { 58 | $constraint->evaluate(true); 59 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 60 | $analyzer = new atoum\tools\variable\analyzer(); 61 | $diff = new atoum\tools\diff($analyzer->dump(false), $analyzer->dump(true)); 62 | $this->assertEquals($analyzer->getTypeOf(true) . ' is not false' . PHP_EOL . $diff, $exception->getMessage()); 63 | } 64 | } 65 | 66 | public function testPasses() 67 | { 68 | $constraint = new testedClass(true); 69 | $this->assertSame($constraint, $constraint->evaluate(true)); 70 | 71 | $constraint = new testedClass(false); 72 | $this->assertSame($constraint, $constraint->evaluate(false)); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/containsOnlyInstancesOfTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass(__CLASS__)); 15 | } 16 | 17 | public function testAssertContainsOnlyInstancesOf() 18 | { 19 | $constraint = new testedClass('Book'); 20 | $this->assertSame($constraint, $constraint->evaluate([new \book(), new \book()])); 21 | $this->assertSame($constraint, $constraint->evaluate(new \arrayIterator([new \book(), new \book()]))); 22 | 23 | $constraint = new testedClass('stdClass'); 24 | $this->assertSame($constraint, $constraint->evaluate([new \stdClass()])); 25 | 26 | $actual = [new \author('Test')]; 27 | $expected = 'Book'; 28 | $constraint = new testedClass($expected); 29 | 30 | try { 31 | $constraint->evaluate($actual); 32 | 33 | $this->fail(); 34 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 35 | $analyzer = new atoum\tools\variable\analyzer(); 36 | $this->assertEquals($analyzer->getTypeOf($actual[0]) . ' is not an instance of Book', $exception->getMessage()); 37 | } 38 | } 39 | 40 | public function testAssertContainsOnlyInstancesOfThrowsException() 41 | { 42 | $constraint = new testedClass(null); 43 | 44 | try { 45 | $constraint->evaluate([new \stdClass()]); 46 | } catch (\PHPUnit\Framework\Exception $exception) { 47 | $this->assertEquals('Expected value of mageekguy\atoum\phpunit\constraints\containsOnlyInstancesOf must be a class instance or class name', $exception->getMessage()); 48 | } 49 | 50 | $constraint = new testedClass('stdClass'); 51 | 52 | try { 53 | $constraint->evaluate(null); 54 | } catch (\PHPUnit\Framework\Exception $exception) { 55 | $this->assertEquals('Actual value of mageekguy\atoum\phpunit\constraints\containsOnlyInstancesOf must be an array or a traversable object', $exception->getMessage()); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/containsOnlyTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass(__CLASS__)); 15 | } 16 | 17 | public function testAssertContainsOnlyThrowsException() 18 | { 19 | $constraint = new testedClass(null); 20 | 21 | try { 22 | $constraint->evaluate([rand(0, PHP_INT_MAX)]); 23 | } catch (\PHPUnit\Framework\Exception $exception) { 24 | $this->assertEquals('Expected value of mageekguy\atoum\phpunit\constraints\containsOnly must be a valid type or class name', $exception->getMessage()); 25 | } 26 | 27 | $constraint = new testedClass(uniqid()); 28 | 29 | try { 30 | $constraint->evaluate([rand(0, PHP_INT_MAX)]); 31 | } catch (\PHPUnit\Framework\Exception $exception) { 32 | $this->assertEquals('Expected value of mageekguy\atoum\phpunit\constraints\containsOnly must be a valid type or class name', $exception->getMessage()); 33 | } 34 | 35 | $constraint = new testedClass('integer'); 36 | 37 | try { 38 | $constraint->evaluate(null); 39 | } catch (\PHPUnit\Framework\Exception $exception) { 40 | $this->assertEquals('Actual value of mageekguy\atoum\phpunit\constraints\containsOnly must be an array or a traversable object', $exception->getMessage()); 41 | } 42 | } 43 | 44 | public function testAssertArrayContainsOnlyIntegers() 45 | { 46 | $constraint = new testedClass('integer'); 47 | $this->assertSame($constraint, $constraint->evaluate([1, 2, 3])); 48 | 49 | $actual = ['1', 2, 3]; 50 | 51 | try { 52 | $constraint->evaluate($actual); 53 | 54 | $this->fail(); 55 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 56 | $analyzer = new atoum\tools\variable\analyzer(); 57 | $this->assertEquals($analyzer->getTypeOf($actual[0]) . ' is not an integer', $exception->getMessage()); 58 | } 59 | } 60 | 61 | public function testAssertArrayContainsOnlyStdClass() 62 | { 63 | $constraint = new testedClass('StdClass'); 64 | $this->assertSame($constraint, $constraint->evaluate([new \stdClass()])); 65 | 66 | $actual = ['StdClass']; 67 | 68 | try { 69 | $constraint->evaluate($actual); 70 | 71 | $this->fail(); 72 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 73 | $analyzer = new atoum\tools\variable\analyzer(); 74 | $this->assertEquals($analyzer->getTypeOf($actual[0]) . ' is not an object', $exception->getMessage()); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/containsTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass(uniqid())); 15 | } 16 | 17 | public function testAssertSplObjectStorageContainsObject() 18 | { 19 | $expected = new \stdClass(); 20 | $b = new \stdClass(); 21 | $actual = new \splObjectStorage(); 22 | $actual->attach($expected); 23 | 24 | $constraint = new testedClass($expected); 25 | $this->assertSame($constraint, $constraint->evaluate($actual)); 26 | 27 | $constraint = new testedClass($b); 28 | 29 | try { 30 | $constraint->evaluate($actual); 31 | 32 | $this->fail(); 33 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 34 | $analyzer = new atoum\tools\variable\analyzer(); 35 | $this->assertEquals($analyzer->getTypeOf($actual) . ' does not contain ' . $analyzer->getTypeOf($expected), $exception->getMessage()); 36 | } 37 | } 38 | 39 | public function testAssertArrayContainsObject() 40 | { 41 | $expected = new \stdClass(); 42 | $b = new \stdClass(); 43 | 44 | $constraint = new testedClass($expected); 45 | $this->assertSame($constraint, $constraint->evaluate([$expected])); 46 | 47 | $actual = [$b]; 48 | 49 | try { 50 | $constraint->evaluate($actual); 51 | 52 | $this->fail(); 53 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 54 | $analyzer = new atoum\tools\variable\analyzer(); 55 | $this->assertEquals($analyzer->getTypeOf($actual) . ' does not contain ' . $analyzer->getTypeOf($expected), $exception->getMessage()); 56 | } 57 | } 58 | 59 | public function testAssertArrayContainsString() 60 | { 61 | $expected = 'foo'; 62 | $constraint = new testedClass($expected); 63 | $this->assertSame($constraint, $constraint->evaluate(['foo'])); 64 | 65 | $actual = ['bar']; 66 | 67 | try { 68 | $constraint->evaluate($actual); 69 | 70 | $this->fail(); 71 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 72 | $analyzer = new atoum\tools\variable\analyzer(); 73 | $this->assertEquals($analyzer->getTypeOf($actual) . ' does not contain ' . $analyzer->getTypeOf($expected), $exception->getMessage()); 74 | } 75 | } 76 | 77 | public function testAssertArrayContainsNonObject() 78 | { 79 | $expected = 'foo'; 80 | $constraint = new testedClass($expected); 81 | $this->assertSame($constraint, $constraint->evaluate('foo')); 82 | 83 | $constraint = new testedClass($expected, null, false, true, true); 84 | $actual = [true]; 85 | 86 | try { 87 | $constraint->evaluate($actual); 88 | 89 | $this->fail(); 90 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 91 | $analyzer = new atoum\tools\variable\analyzer(); 92 | $this->assertEquals($analyzer->getTypeOf($actual) . ' does not contain ' . $analyzer->getTypeOf($expected), $exception->getMessage()); 93 | } 94 | } 95 | 96 | public function testAssertContainsThrowsException() 97 | { 98 | $constraint = new testedClass(null); 99 | 100 | try { 101 | $constraint->evaluate(null); 102 | } catch (\PHPUnit\Framework\Exception $exception) { 103 | $this->assertEquals('Actual value of mageekguy\atoum\phpunit\constraints\contains must be an array, a string or a traversable object', $exception->getMessage()); 104 | } 105 | } 106 | 107 | public function testAssertIteratorContainsObject() 108 | { 109 | $expected = new \stdClass(); 110 | $constraint = new testedClass($expected); 111 | $this->assertSame($constraint, $constraint->evaluate([$expected])); 112 | 113 | $actual = new \testIterator([new \stdClass()]); 114 | 115 | try { 116 | $constraint->evaluate($actual); 117 | 118 | $this->fail(); 119 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 120 | $analyzer = new atoum\tools\variable\analyzer(); 121 | $this->assertEquals($analyzer->getTypeOf($actual) . ' does not contain ' . $analyzer->getTypeOf($expected), $exception->getMessage()); 122 | } 123 | } 124 | 125 | public function testAssertIteratorContainsString() 126 | { 127 | $expected = 'foo'; 128 | $constraint = new testedClass($expected); 129 | $this->assertSame($constraint, $constraint->evaluate(new \testIterator([$expected]))); 130 | 131 | $actual = new \testIterator(['bar']); 132 | 133 | try { 134 | $constraint->evaluate($actual); 135 | 136 | $this->fail(); 137 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 138 | $analyzer = new atoum\tools\variable\analyzer(); 139 | $this->assertEquals($analyzer->getTypeOf($actual) . ' does not contain ' . $analyzer->getTypeOf($expected), $exception->getMessage()); 140 | } 141 | } 142 | 143 | public function testAssertStringContainsString() 144 | { 145 | $expected = 'foo'; 146 | $constraint = new testedClass($expected); 147 | $this->assertSame($constraint, $constraint->evaluate('foobar')); 148 | 149 | $actual = 'bar'; 150 | 151 | try { 152 | $constraint->evaluate($actual); 153 | 154 | $this->fail(); 155 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 156 | $analyzer = new atoum\tools\variable\analyzer(); 157 | $this->assertEquals($analyzer->getTypeOf($actual) . ' does not contain ' . $analyzer->getTypeOf($expected), $exception->getMessage()); 158 | } 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/countTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass(rand(0, PHP_INT_MAX))); 13 | } 14 | 15 | public function testAssertCount() 16 | { 17 | $constraint = new testedClass(2); 18 | $constraint->evaluate([1, 2]); 19 | 20 | try { 21 | $constraint->evaluate([1, 2, 3]); 22 | 23 | $this->fail(); 24 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 25 | $this->assertEquals('array(3) has size 3, expected size 2', $exception->getMessage()); 26 | } 27 | } 28 | 29 | public function testAssertCountTraversable() 30 | { 31 | $constraint = new testedClass(2); 32 | $constraint->evaluate(new \arrayIterator([1, 2])); 33 | 34 | try { 35 | $constraint->evaluate(new \arrayIterator([1, 2, 3])); 36 | 37 | $this->fail(); 38 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 39 | $analyzer = new atoum\tools\variable\analyzer(); 40 | $diff = new atoum\tools\diff($analyzer->dump(2), $analyzer->dump(3)); 41 | $this->assertEquals('integer(3) is not equal to integer(2)' . PHP_EOL . $diff, $exception->getMessage()); 42 | } 43 | } 44 | 45 | public function testAssertCountThrowsExceptionIfExpectedCountIsNoInteger() 46 | { 47 | $constraint = new testedClass('a'); 48 | 49 | try { 50 | $constraint->evaluate([]); 51 | 52 | $this->fail(); 53 | } catch (\PHPUnit\Framework\Exception $exception) { 54 | $this->assertEquals('Expected value of mageekguy\atoum\phpunit\constraints\count must be an integer', $exception->getMessage()); 55 | } 56 | } 57 | 58 | public function testAssertCountThrowsExceptionIfElementIsNotCountable() 59 | { 60 | $constraint = new testedClass(2); 61 | 62 | try { 63 | $constraint->evaluate(''); 64 | 65 | $this->fail(); 66 | } catch (\PHPUnit\Framework\Exception $exception) { 67 | $this->assertEquals('Actual value of mageekguy\atoum\phpunit\constraints\count must be an array, a countable object or a traversable object', $exception->getMessage()); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/equalsTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass(uniqid())); 18 | } 19 | 20 | /** 21 | * @dataProvider equalProvider 22 | */ 23 | public function testAssertEqualsSucceeds($expected, $actual, $delta = null, $canonicalize = null, $ignoreCase = null) 24 | { 25 | $constraint = new testedClass($expected, null, $delta, 10, $canonicalize, $ignoreCase); 26 | 27 | $this->assertSame($constraint, $constraint->evaluate($actual)); 28 | } 29 | 30 | public function equalProvider() 31 | { 32 | return array_merge($this->equalValues(), $this->sameValues()); 33 | } 34 | 35 | protected function equalValues() 36 | { 37 | $book1 = new \book(); 38 | $book1->author = new \author('Terry Pratchett'); 39 | $book1->author->books[] = $book1; 40 | $book2 = new \book(); 41 | $book2->author = new \author('Terry Pratchett'); 42 | $book2->author->books[] = $book2; 43 | 44 | $object1 = new \sampleClass(4, 8, 15); 45 | $object2 = new \sampleClass(4, 8, 15); 46 | $storage1 = new \splObjectStorage(); 47 | $storage1->attach($object1); 48 | $storage2 = new \splObjectStorage(); 49 | $storage2->attach($object1); 50 | 51 | return [ 52 | ['a', 'A', 0, false, true], 53 | [['a' => 1, 'b' => 2], ['b' => 2, 'a' => 1]], 54 | [[1], ['1']], 55 | [[3, 2, 1], [2, 3, 1], 0, true], 56 | [2.3, 2.5, 0.5], 57 | // Asserting on floats (with delta) in arrays is not supported 58 | //array(array(2.3), array(2.5), 0.5), 59 | // Asserting on floats (with delta) in nested arrays is not supported 60 | //array(array(array(2.3)), array(array(2.5)), 0.5), 61 | // Asserting on floats (with delta) on objects\' properties is not supported 62 | //array(new \struct(2.3), new \struct(2.5), 0.5), 63 | // Asserting on floats (with delta) on objects\' properties in arrays is not supported 64 | //array(array(new \struct(2.3)), array(new \struct(2.5)), 0.5), 65 | [1, 2, 1], 66 | [$object1, $object2], 67 | // Asserting on objects with cyclic dependencies is not supported 68 | //array($book1, $book2), 69 | [$storage1, $storage2], 70 | [ 71 | new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 72 | new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 73 | ], 74 | // Asserting on dates with delta is not supported 75 | //array( 76 | // new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 77 | // new \dateTime('2013-03-29 04:13:25', new \dateTimeZone('America/New_York')), 78 | // 10 79 | //), 80 | //array( 81 | // new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 82 | // new \dateTime('2013-03-29 04:14:40', new \dateTimeZone('America/New_York')), 83 | // 65 84 | //), 85 | [ 86 | new \dateTime('2013-03-29', new \dateTimeZone('America/New_York')), 87 | new \dateTime('2013-03-29', new \dateTimeZone('America/New_York')), 88 | ], 89 | [ 90 | new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 91 | new \dateTime('2013-03-29 03:13:35', new \dateTimeZone('America/Chicago')), 92 | ], 93 | // Asserting on dates with delta is not supported 94 | //array( 95 | // new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 96 | // new \dateTime('2013-03-29 03:13:49', new \dateTimeZone('America/Chicago')), 97 | // 15 98 | //), 99 | [ 100 | new \dateTime('2013-03-30', new \dateTimeZone('America/New_York')), 101 | new \dateTime('2013-03-29 23:00:00', new \dateTimeZone('America/Chicago')), 102 | ], 103 | // Asserting on dates with delta is not supported 104 | //array( 105 | // new \dateTime('2013-03-30', new \dateTimeZone('America/New_York')), 106 | // new \dateTime('2013-03-29 23:01:30', new \dateTimeZone('America/Chicago')), 107 | // 100 108 | //), 109 | [ 110 | new \dateTime('@1364616000'), 111 | new \dateTime('2013-03-29 23:00:00', new \dateTimeZone('America/Chicago')), 112 | ], 113 | [ 114 | new \dateTime('2013-03-29T05:13:35-0500'), 115 | new \dateTime('2013-03-29T04:13:35-0600'), 116 | ], 117 | [0, '0'], 118 | ['0', 0], 119 | [2.3, '2.3'], 120 | ['2.3', 2.3], 121 | [(string) (1/3), 1 - 2/3], 122 | [1/3, (string) (1 - 2/3)], 123 | ['string representation', new \classWithToString()], 124 | [new \classWithToString(), 'string representation'], 125 | ]; 126 | } 127 | 128 | protected function sameValues() 129 | { 130 | $object = new \sampleClass(4, 8, 15); 131 | $resource = fopen(__FILE__, 'r'); 132 | 133 | return [ 134 | [null, null], 135 | ['a', 'a'], 136 | [0, 0], 137 | [2.3, 2.3], 138 | [1/3, 1 - 2/3], 139 | [log(0), log(0)], 140 | [[], []], 141 | [[0 => 1], [0 => 1]], 142 | [[0 => null], [0 => null]], 143 | [['a', 'b' => [1, 2]], ['a', 'b' => [1, 2]]], 144 | [$object, $object], 145 | [$resource, $resource], 146 | ]; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/finiteTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass()); 13 | } 14 | 15 | public function testAssertFinite() 16 | { 17 | $constraint = new testedClass(); 18 | $this->assertSame($constraint, $constraint->evaluate(rand(0, PHP_INT_MAX))); 19 | 20 | $actual = INF; 21 | 22 | try { 23 | $constraint->evaluate($actual); 24 | 25 | $this->fail(); 26 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 27 | $analyzer = new atoum\tools\variable\analyzer(); 28 | $this->assertEquals($analyzer->getTypeOf($actual) . ' is not finite', $exception->getMessage()); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/greaterThanOrEqualTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraints\greaterThan', new testedClass(rand(0, PHP_INT_MAX))); 13 | } 14 | 15 | public function testGreaterThanOrEqualWithIntegers() 16 | { 17 | $expected = 1; 18 | $constraint = new testedClass($expected); 19 | $this->assertSame($constraint, $constraint->evaluate(1)); 20 | $this->assertSame($constraint, $constraint->evaluate(2)); 21 | 22 | $actual = 0; 23 | 24 | try { 25 | $constraint->evaluate($actual); 26 | 27 | $this->fail(); 28 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 29 | $analyzer = new atoum\tools\variable\analyzer(); 30 | $this->assertEquals($analyzer->getTypeOf($actual) . ' is not greater than or equal to ' . $analyzer->getTypeOf($expected), $exception->getMessage()); 31 | } 32 | } 33 | 34 | public function testGreaterThanOrEqualWithFloats() 35 | { 36 | $expected = 1; 37 | $constraint = new testedClass($expected); 38 | $this->assertSame($constraint, $constraint->evaluate((float) $expected)); 39 | $this->assertSame($constraint, $constraint->evaluate(4 / 3)); 40 | 41 | $actual = 1 / 3; 42 | 43 | try { 44 | $constraint->evaluate($actual); 45 | 46 | $this->fail(); 47 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 48 | $analyzer = new atoum\tools\variable\analyzer(); 49 | $this->assertEquals($analyzer->getTypeOf($actual) . ' is not greater than or equal to ' . $analyzer->getTypeOf($expected), $exception->getMessage()); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/greaterThanTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass(rand(0, PHP_INT_MAX))); 13 | } 14 | 15 | public function testGreaterThanWithIntegers() 16 | { 17 | $expected = 1; 18 | $constraint = new testedClass($expected); 19 | $this->assertSame($constraint, $constraint->evaluate(2)); 20 | 21 | $actual = 1; 22 | 23 | try { 24 | $constraint->evaluate($actual); 25 | 26 | $this->fail(); 27 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 28 | $analyzer = new atoum\tools\variable\analyzer(); 29 | $this->assertEquals($analyzer->getTypeOf($actual) . ' is not greater than ' . $analyzer->getTypeOf($expected), $exception->getMessage()); 30 | } 31 | } 32 | 33 | public function testGreaterThanWithFloats() 34 | { 35 | $expected = 1; 36 | $constraint = new testedClass($expected); 37 | $this->assertSame($constraint, $constraint->evaluate(4 / 3)); 38 | 39 | $actual = 1 / 3; 40 | 41 | try { 42 | $constraint->evaluate($actual); 43 | 44 | $this->fail(); 45 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 46 | $analyzer = new atoum\tools\variable\analyzer(); 47 | $this->assertEquals($analyzer->getTypeOf($actual) . ' is not greater than ' . $analyzer->getTypeOf($expected), $exception->getMessage()); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/infiniteTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass()); 13 | } 14 | 15 | public function testAssertInfinite() 16 | { 17 | $constraint = new testedClass(); 18 | $this->assertSame($constraint, $constraint->evaluate(INF)); 19 | 20 | $actual = rand(0, PHP_INT_MAX); 21 | 22 | try { 23 | $constraint->evaluate($actual); 24 | 25 | $this->fail(); 26 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 27 | $analyzer = new atoum\tools\variable\analyzer(); 28 | $this->assertEquals($analyzer->getTypeOf($actual) . ' is not infinite', $exception->getMessage()); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/internalTypeTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass(__CLASS__)); 13 | } 14 | 15 | public function testAssertInternalType() 16 | { 17 | $constraint = new testedClass('integer'); 18 | $this->assertSame($constraint, $constraint->evaluate(1)); 19 | 20 | $actual = uniqid(); 21 | 22 | try { 23 | $constraint->evaluate($actual); 24 | 25 | $this->fail(); 26 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 27 | $analyzer = new atoum\tools\variable\analyzer(); 28 | $this->assertEquals($analyzer->getTypeOf($actual) . ' is not an integer', $exception->getMessage()); 29 | } 30 | } 31 | 32 | public function testAssertInternalTypeDouble() 33 | { 34 | $constraint = new testedClass('double'); 35 | $this->assertSame($constraint, $constraint->evaluate(1.0)); 36 | 37 | $actual = rand(0, PHP_INT_MAX); 38 | 39 | try { 40 | $constraint->evaluate($actual); 41 | 42 | $this->fail(); 43 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 44 | $analyzer = new atoum\tools\variable\analyzer(); 45 | $diff = new atoum\tools\diffs\variable(true, false); 46 | $this->assertEquals($analyzer->getTypeOf($actual) . ' is not a double' . PHP_EOL . $diff, $exception->getMessage()); 47 | } 48 | } 49 | 50 | public function testAssertInternalTypeThrowsExceptionForInvalidArgument() 51 | { 52 | $constraint = new testedClass(null); 53 | 54 | try { 55 | $constraint->evaluate(1); 56 | 57 | $this->fail(); 58 | } catch (\PHPUnit\Framework\Exception $exception) { 59 | $this->assertEquals('Expected value of mageekguy\atoum\phpunit\constraints\internalType must be a valid type', $exception->getMessage()); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/isEmpty.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass()); 13 | } 14 | 15 | public function testAssertStringIsEmpty() 16 | { 17 | $constraint = new testedClass(); 18 | $constraint->evaluate(''); 19 | 20 | try { 21 | $constraint->evaluate('foo'); 22 | 23 | $this->fail(); 24 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 25 | $this->assertEquals('string(3) \'foo\' is not empty', $exception->getMessage()); 26 | } 27 | } 28 | 29 | public function testAssertArrayIsEmpty() 30 | { 31 | $constraint = new testedClass(); 32 | $constraint->evaluate([]); 33 | 34 | try { 35 | $constraint->evaluate([1, 2]); 36 | 37 | $this->fail(); 38 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 39 | $this->assertEquals('array(2) is not empty', $exception->getMessage()); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/isInstanceofTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf(atoum\phpunit\constraint::class, new testedClass(new \stdClass)); 13 | } 14 | 15 | public function testAssertInstanceOf() 16 | { 17 | $constraint = new testedClass(\stdClass::class); 18 | $this->assertSame($constraint, $constraint->evaluate(new \stdClass())); 19 | 20 | try { 21 | $constraint->evaluate(new \exception()); 22 | 23 | $this->fail(); 24 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 25 | $this->assertEquals('object(Exception) is not an instance of stdClass', $exception->getMessage()); 26 | } 27 | } 28 | 29 | public function testAssertInstanceOfThrowsExceptionForInvalidArgument() 30 | { 31 | $constraint = new testedClass(null); 32 | 33 | try { 34 | $constraint->evaluate(new \stdClass); 35 | 36 | $this->fail(); 37 | } catch (\PHPUnit\Framework\Exception $exception) { 38 | $this->assertEquals('Argument of mageekguy\atoum\asserters\phpObject::isInstanceOf() must be a class instance or a class name', $exception->getMessage()); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/isNotEmpty.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass()); 13 | } 14 | 15 | public function testAssertStringIsNotEmpty() 16 | { 17 | $constraint = new testedClass(); 18 | $constraint->evaluate('foo'); 19 | 20 | try { 21 | $constraint->evaluate(''); 22 | 23 | $this->fail(); 24 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 25 | $this->assertEquals('string(0) \'\' is empty', $exception->getMessage()); 26 | } 27 | } 28 | 29 | public function testAssertArrayIsNotEmpty() 30 | { 31 | $constraint = new testedClass(); 32 | $constraint->evaluate([1, 2]); 33 | 34 | try { 35 | $constraint->evaluate([]); 36 | 37 | $this->fail(); 38 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 39 | $this->assertEquals('array(0) is empty', $exception->getMessage()); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/isNotNullTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass()); 13 | } 14 | 15 | public function testFails() 16 | { 17 | $constraint = new testedClass(); 18 | 19 | try { 20 | $constraint->evaluate(null); 21 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 22 | $analyzer = new atoum\tools\variable\analyzer(); 23 | 24 | $this->assertEquals($analyzer->getTypeOf(null) . ' is null', $exception->getMessage()); 25 | } 26 | } 27 | 28 | /** 29 | * @dataProvider notNullProvider 30 | */ 31 | public function testPasses($actual) 32 | { 33 | $constraint = new testedClass(); 34 | $this->assertSame($constraint, $constraint->evaluate($actual)); 35 | } 36 | 37 | public function notNullProvider() 38 | { 39 | return [ 40 | [''], 41 | [0], 42 | [false], 43 | [uniqid()] 44 | ]; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/isNullTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass()); 13 | } 14 | 15 | /** 16 | * @dataProvider notNullProvider 17 | */ 18 | public function testFails($actual) 19 | { 20 | $constraint = new testedClass(); 21 | 22 | try { 23 | $constraint->evaluate($actual); 24 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 25 | $analyzer = new atoum\tools\variable\analyzer(); 26 | 27 | $this->assertEquals($analyzer->getTypeOf($actual) . ' is not null', $exception->getMessage()); 28 | } 29 | } 30 | 31 | public function testPasses() 32 | { 33 | $constraint = new testedClass(); 34 | $this->assertSame($constraint, $constraint->evaluate(null)); 35 | } 36 | 37 | public function notNullProvider() 38 | { 39 | return [ 40 | [''], 41 | [0], 42 | [false], 43 | [uniqid()] 44 | ]; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/nanTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass()); 13 | } 14 | 15 | public function testAssertNan() 16 | { 17 | $constraint = new testedClass(); 18 | $this->assertSame($constraint, $constraint->evaluate(NAN)); 19 | 20 | $actual = rand(0, PHP_INT_MAX); 21 | 22 | try { 23 | $constraint->evaluate($actual); 24 | 25 | $this->fail(); 26 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 27 | $analyzer = new atoum\tools\variable\analyzer(); 28 | $this->assertEquals($analyzer->getTypeOf($actual) . ' is not NaN', $exception->getMessage()); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/notCountTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass(rand(0, PHP_INT_MAX))); 13 | } 14 | 15 | public function testAssertNotCount() 16 | { 17 | $constraint = new testedClass(2); 18 | $constraint->evaluate([1, 2, 3]); 19 | 20 | try { 21 | $constraint->evaluate([1, 2]); 22 | 23 | $this->fail(); 24 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 25 | $this->assertEquals('array(2) has size 2, expected different size', $exception->getMessage()); 26 | } 27 | } 28 | 29 | public function testAssertNotCountTraversable() 30 | { 31 | $constraint = new testedClass(2); 32 | $constraint->evaluate(new \arrayIterator([1, 2, 3])); 33 | 34 | try { 35 | $constraint->evaluate(new \arrayIterator([1, 2])); 36 | 37 | $this->fail(); 38 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 39 | $this->assertEquals('integer(2) is equal to integer(2)', $exception->getMessage()); 40 | } 41 | } 42 | 43 | public function testAssertNotCountThrowsExceptionIfExpectedCountIsNoInteger() 44 | { 45 | $constraint = new testedClass('a'); 46 | 47 | try { 48 | $constraint->evaluate([]); 49 | 50 | $this->fail(); 51 | } catch (\PHPUnit\Framework\Exception $exception) { 52 | $this->assertEquals('Expected value of mageekguy\atoum\phpunit\constraints\notCount must be an integer', $exception->getMessage()); 53 | } 54 | } 55 | 56 | public function testAssertNotCountThrowsExceptionIfElementIsNotCountable() 57 | { 58 | $constraint = new testedClass(2); 59 | 60 | try { 61 | $constraint->evaluate(''); 62 | 63 | $this->fail(); 64 | } catch (\PHPUnit\Framework\Exception $exception) { 65 | $this->assertEquals('Actual value of mageekguy\atoum\phpunit\constraints\notCount must be an array, a countable object or a traversable object', $exception->getMessage()); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/objectHasAttributeTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass('foo')); 13 | } 14 | 15 | public function testAssertObjectHasAttribute() 16 | { 17 | $constraint = new testedClass('foo'); 18 | $object = new \StdClass(); 19 | $object->foo = 42; 20 | 21 | $this->assertSame($constraint, $constraint->evaluate($object)); 22 | } 23 | 24 | public function testAssertObjectHasNotAttribute() 25 | { 26 | $constraint = new testedClass('foo'); 27 | $object = new \StdClass(); 28 | 29 | try { 30 | $this->assertSame($constraint, $constraint->evaluate($object)); 31 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 32 | $analyzer = new atoum\tools\variable\analyzer(); 33 | $this->assertEquals( 34 | $analyzer->getTypeOf($object) . ' has no attribute `foo`', 35 | $exception->getMessage() 36 | ); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/objectNotHasAttributeTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass('foo')); 13 | } 14 | 15 | public function testAssertObjectNotHasAttribute() 16 | { 17 | $constraint = new testedClass('foo'); 18 | $object = new \StdClass(); 19 | 20 | $this->assertSame($constraint, $constraint->evaluate($object)); 21 | } 22 | 23 | public function testAssertObjectHasNotAttribute() 24 | { 25 | $constraint = new testedClass('foo'); 26 | $object = new \StdClass(); 27 | $object->foo = 42; 28 | 29 | try { 30 | $this->assertSame($constraint, $constraint->evaluate($object)); 31 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 32 | $analyzer = new atoum\tools\variable\analyzer(); 33 | $this->assertEquals( 34 | $analyzer->getTypeOf($object) . ' has attribute `foo`', 35 | $exception->getMessage() 36 | ); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/units/classes/constraints/sameTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\phpunit\constraint', new testedClass(uniqid())); 18 | } 19 | 20 | /** 21 | * @dataProvider sameProvider 22 | */ 23 | public function testAssertSameSucceeds($expected, $actual) 24 | { 25 | $constraint = new testedClass($expected); 26 | $this->assertSame($constraint, $constraint->evaluate($actual)); 27 | } 28 | 29 | /** 30 | * @dataProvider notSameProvider 31 | */ 32 | public function testAssertSameFails($expected, $actual) 33 | { 34 | $constraint = new testedClass($expected); 35 | 36 | try { 37 | $constraint->evaluate($actual); 38 | 39 | $this->fail(); 40 | } catch (\PHPUnit\Framework\ExpectationFailedException $exception) { 41 | $this->assertInstanceOf('PHPUnit\Framework\ExpectationFailedException', $exception); 42 | } 43 | } 44 | 45 | public function sameProvider() 46 | { 47 | return $this->sameValues(); 48 | } 49 | 50 | public function notSameProvider() 51 | { 52 | return array_merge($this->equalValues(), $this->notEqualValues()); 53 | } 54 | 55 | protected function equalValues() 56 | { 57 | $book1 = new \book(); 58 | $book1->author = new \author('Terry Pratchett'); 59 | $book1->author->books[] = $book1; 60 | $book2 = new \book(); 61 | $book2->author = new \author('Terry Pratchett'); 62 | $book2->author->books[] = $book2; 63 | 64 | $object1 = new \sampleClass(4, 8, 15); 65 | $object2 = new \sampleClass(4, 8, 15); 66 | $storage1 = new \splObjectStorage(); 67 | $storage1->attach($object1); 68 | $storage2 = new \splObjectStorage(); 69 | $storage2->attach($object1); 70 | 71 | return [ 72 | ['a', 'A', 0, false, true], 73 | [['a' => 1, 'b' => 2], ['b' => 2, 'a' => 1]], 74 | [[1], ['1']], 75 | [[3, 2, 1], [2, 3, 1], 0, true], 76 | [2.3, 2.5, 0.5], 77 | // Asserting on floats (with delta) in arrays is not supported 78 | //array(array(2.3), array(2.5), 0.5), 79 | // Asserting on floats (with delta) in nested arrays is not supported 80 | //array(array(array(2.3)), array(array(2.5)), 0.5), 81 | // Asserting on floats (with delta) on objects\' properties is not supported 82 | //array(new \struct(2.3), new \struct(2.5), 0.5), 83 | // Asserting on floats (with delta) on objects\' properties in arrays is not supported 84 | //array(array(new \struct(2.3)), array(new \struct(2.5)), 0.5), 85 | [1, 2, 1], 86 | [$object1, $object2], 87 | // Asserting on objects with cyclic dependencies is not supported 88 | //array($book1, $book2), 89 | [$storage1, $storage2], 90 | [ 91 | new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 92 | new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 93 | ], 94 | // Asserting on dates with delta is not supported 95 | //array( 96 | // new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 97 | // new \dateTime('2013-03-29 04:13:25', new \dateTimeZone('America/New_York')), 98 | // 10 99 | //), 100 | //array( 101 | // new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 102 | // new \dateTime('2013-03-29 04:14:40', new \dateTimeZone('America/New_York')), 103 | // 65 104 | //), 105 | [ 106 | new \dateTime('2013-03-29', new \dateTimeZone('America/New_York')), 107 | new \dateTime('2013-03-29', new \dateTimeZone('America/New_York')), 108 | ], 109 | [ 110 | new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 111 | new \dateTime('2013-03-29 03:13:35', new \dateTimeZone('America/Chicago')), 112 | ], 113 | // Asserting on dates with delta is not supported 114 | //array( 115 | // new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 116 | // new \dateTime('2013-03-29 03:13:49', new \dateTimeZone('America/Chicago')), 117 | // 15 118 | //), 119 | [ 120 | new \dateTime('2013-03-30', new \dateTimeZone('America/New_York')), 121 | new \dateTime('2013-03-29 23:00:00', new \dateTimeZone('America/Chicago')), 122 | ], 123 | // Asserting on dates with delta is not supported 124 | //array( 125 | // new \dateTime('2013-03-30', new \dateTimeZone('America/New_York')), 126 | // new \dateTime('2013-03-29 23:01:30', new \dateTimeZone('America/Chicago')), 127 | // 100 128 | //), 129 | [ 130 | new \dateTime('@1364616000'), 131 | new \dateTime('2013-03-29 23:00:00', new \dateTimeZone('America/Chicago')), 132 | ], 133 | [ 134 | new \dateTime('2013-03-29T05:13:35-0500'), 135 | new \dateTime('2013-03-29T04:13:35-0600'), 136 | ], 137 | [0, '0'], 138 | ['0', 0], 139 | [2.3, '2.3'], 140 | ['2.3', 2.3], 141 | [(string) (1/3), 1 - 2/3], 142 | [1/3, (string) (1 - 2/3)], 143 | ['string representation', new \classWithToString()], 144 | [new \classWithToString(), 'string representation'], 145 | ]; 146 | } 147 | 148 | protected function notEqualValues() 149 | { 150 | $book1 = new \book(); 151 | $book1->author = new \author('Terry Pratchett'); 152 | $book1->author->books[] = $book1; 153 | $book2 = new \book(); 154 | $book2->author = new \author('Terry Pratch'); 155 | $book2->author->books[] = $book2; 156 | 157 | $book3 = new \book(); 158 | $book3->author = 'Terry Pratchett'; 159 | $book4 = new \stdClass; 160 | $book4->author = 'Terry Pratchett'; 161 | 162 | $object1 = new \sampleClass(4, 8, 15); 163 | $object2 = new \sampleClass(16, 23, 42); 164 | $object3 = new \sampleClass(4, 8, 15); 165 | $storage1 = new \splObjectStorage; 166 | $storage1->attach($object1); 167 | $storage2 = new \splObjectStorage; 168 | $storage2->attach($object3); // same content, different object 169 | 170 | return [ 171 | ['a', 'b'], 172 | ['a', 'A'], 173 | ['9E6666666','9E7777777'], 174 | [1, 2], 175 | [2, 1], 176 | [2.3, 4.2], 177 | [2.3, 4.2, 0.5], 178 | [[2.3], [4.2], 0.5], 179 | [[[2.3]], [[4.2]], 0.5], 180 | [new \struct(2.3), new \struct(4.2), 0.5], 181 | [[new \struct(2.3)], [new \struct(4.2)], 0.5], 182 | [NAN, NAN], 183 | [[], [0 => 1]], 184 | [[0 => 1], []], 185 | [[0 => null], []], 186 | [[0 => 1, 1 => 2], [0 => 1, 1 => 3]], 187 | [['a', 'b' => [1, 2]], ['a', 'b' => [2, 1]]], 188 | [new \sampleClass(4, 8, 15), new \sampleClass(16, 23, 42)], 189 | [$object1, $object2], 190 | [$book1, $book2], 191 | [$book3, $book4], 192 | [fopen(__FILE__, 'r'), fopen(__FILE__, 'r')], 193 | [$storage1, $storage2], 194 | [ 195 | new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 196 | new \dateTime('2013-03-29 03:13:35', new \dateTimeZone('America/New_York')), 197 | ], 198 | [ 199 | new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 200 | new \dateTime('2013-03-29 03:13:35', new \dateTimeZone('America/New_York')), 201 | 3500 202 | ], 203 | [ 204 | new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 205 | new \dateTime('2013-03-29 05:13:35', new \dateTimeZone('America/New_York')), 206 | 3500 207 | ], 208 | [ 209 | new \dateTime('2013-03-29', new \dateTimeZone('America/New_York')), 210 | new \dateTime('2013-03-30', new \dateTimeZone('America/New_York')), 211 | ], 212 | [ 213 | new \dateTime('2013-03-29', new \dateTimeZone('America/New_York')), 214 | new \dateTime('2013-03-30', new \dateTimeZone('America/New_York')), 215 | 43200 216 | ], 217 | [ 218 | new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 219 | new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/Chicago')), 220 | ], 221 | [ 222 | new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/New_York')), 223 | new \dateTime('2013-03-29 04:13:35', new \dateTimeZone('America/Chicago')), 224 | 3500 225 | ], 226 | [ 227 | new \dateTime('2013-03-30', new \dateTimeZone('America/New_York')), 228 | new \dateTime('2013-03-30', new \dateTimeZone('America/Chicago')), 229 | ], 230 | [ 231 | new \dateTime('2013-03-29T05:13:35-0600'), 232 | new \dateTime('2013-03-29T04:13:35-0600'), 233 | ], 234 | [ 235 | new \dateTime('2013-03-29T05:13:35-0600'), 236 | new \dateTime('2013-03-29T05:13:35-0500'), 237 | ], 238 | [new \sampleClass(4, 8, 15), false], 239 | [false, new \sampleClass(4, 8, 15)], 240 | [[0 => 1, 1 => 2], false], 241 | [false, [0 => 1, 1 => 2]], 242 | [[], new \stdClass()], 243 | [new \stdClass(), []], 244 | [0, 'Foobar'], 245 | ['Foobar', 0], 246 | [3, acos(8)], 247 | [acos(8), 3] 248 | ]; 249 | } 250 | 251 | protected function sameValues() 252 | { 253 | $object = new \sampleClass(4, 8, 15); 254 | $resource = fopen(__FILE__, 'r'); 255 | 256 | return [ 257 | [null, null], 258 | ['a', 'a'], 259 | [0, 0], 260 | [2.3, 2.3], 261 | // Asserting on float is not supported 262 | //array(1/3, 1 - 2/3), 263 | [log(0), log(0)], 264 | [[], []], 265 | [[0 => 1], [0 => 1]], 266 | [[0 => null], [0 => null]], 267 | [['a', 'b' => [1, 2]], ['a', 'b' => [1, 2]]], 268 | [$object, $object], 269 | [$resource, $resource], 270 | ]; 271 | } 272 | } 273 | -------------------------------------------------------------------------------- /tests/units/classes/extensionTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('mageekguy\atoum\extension', new testedClass()); 12 | } 13 | } 14 | --------------------------------------------------------------------------------