diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index 5877bfbd6..270d20ccf 100644 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -222,52 +222,6 @@ final class ArrayUtils return true; } - /** - * Stringify array. - * - * @param array $array Array to stringify - * - * @return string - * - * @throws \InvalidArgumentException - * - * @since 1.0.0 - */ - public static function stringify(array $array) : string - { - $str = '['; - - foreach ($array as $key => $value) { - if (\is_string($key)) { - $key = '\'' . $key . '\''; - } - - switch (\gettype($value)) { - case 'array': - $str .= $key . ' => ' . self::stringify($value) . ', '; - break; - case 'integer': - case 'double': - case 'float': - $str .= $key . ' => ' . $value . ', '; - break; - case 'string': - $str .= $key . ' => \'' . $value . '\', '; - break; - case 'boolean': - $str .= $key . ' => ' . ($value ? 'true' : 'false') . ', '; - break; - case 'NULL': - $str .= $key . ' => null, '; - break; - default: - throw new \InvalidArgumentException('Unknown default type'); - } - } - - return $str . ']'; - } - /** * Convert array to csv string. * @@ -328,10 +282,10 @@ final class ArrayUtils * * @since 1.0.0 */ - public static function hasArg(string $id, array $args) : ?int + public static function hasArg(string $id, array $args) : int { if (($key = \array_search($id, $args)) === false) { - return null; + return -1; } return (int) $key; diff --git a/Utils/JsonBuilder.php b/Utils/JsonBuilder.php deleted file mode 100644 index 2b5ce3d24..000000000 --- a/Utils/JsonBuilder.php +++ /dev/null @@ -1,101 +0,0 @@ -json; - } - - /** - * Add data. - * - * @param string $path Path used for storage - * @param mixed $value Data to add - * @param bool $overwrite Should overwrite existing data - * - * @return void - * - * @since 1.0.0 - */ - public function add(string $path, $value, bool $overwrite = true) : void - { - $this->json = ArrayUtils::setArray($path, $this->json, $value, '/', $overwrite); - } - - /** - * Remove data. - * - * @param string $path Path to the element to delete - * - * @return void - * - * @since 1.0.0 - */ - public function remove(string $path) : void - { - $this->json = ArrayUtils::unsetArray($path, $this->json, '/'); - } - - /** - * {@inheritdoc} - */ - public function serialize() : string - { - return (string) \json_encode($this->json); - } - - /** - * {@inheritdoc} - */ - public function unserialize($serialized) : void - { - $this->json = \json_decode($serialized, true); - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() - { - return $this->getJson(); - } -} diff --git a/Utils/TaskSchedule/Cron.php b/Utils/TaskSchedule/Cron.php index b5976b2d6..e4b5674b3 100644 --- a/Utils/TaskSchedule/Cron.php +++ b/Utils/TaskSchedule/Cron.php @@ -158,7 +158,7 @@ class Cron extends SchedulerAbstract if ($line[0] !== '#' && \stripos($line, '# name="' . $name) !== false) { $elements = []; $elements[] = $name; - $elements += \explode(' ', $line); + $elements = \array_merge($elements, \explode(' ', $line)); $jobs[] = CronJob::createWith($elements); } diff --git a/Utils/TaskSchedule/CronJob.php b/Utils/TaskSchedule/CronJob.php index e7dcbb618..2bf08fc6c 100644 --- a/Utils/TaskSchedule/CronJob.php +++ b/Utils/TaskSchedule/CronJob.php @@ -29,7 +29,7 @@ class CronJob extends TaskAbstract */ public function __toString() : string { - return $this->interval . ' ' . $this->command . ' # name="' . $this->id . '" ' . $this->comment; + return $this->interval === '' ? '' : $this->interval . ' ' . $this->command . ' # name="' . $this->id . '" ' . $this->comment; } /** @@ -37,7 +37,7 @@ class CronJob extends TaskAbstract */ public static function createWith(array $jobData) : TaskAbstract { - $interval = \array_splice($jobData, 1, 4); + $interval = \array_splice($jobData, 1, 5); $job = new self($jobData[0], $jobData[1], \implode(' ', $interval)); return $job; diff --git a/Utils/TaskSchedule/Schedule.php b/Utils/TaskSchedule/Schedule.php index 67a46b2fb..0a7adb263 100644 --- a/Utils/TaskSchedule/Schedule.php +++ b/Utils/TaskSchedule/Schedule.php @@ -31,7 +31,7 @@ class Schedule extends TaskAbstract */ public function __toString() : string { - return '/tn ' . $this->id . ' ' . $this->interval . ' ' . $this->command; + return $this->interval === '' ? '' : '/tn ' . $this->id . ' ' . $this->interval . ' ' . $this->command; } /** @@ -39,7 +39,8 @@ class Schedule extends TaskAbstract */ public static function createWith(array $jobData) : TaskAbstract { - $job = new self($jobData[1], $jobData[8]); + // todo: fix interval this is just a dummy|!!! + $job = new self($jobData[1], $jobData[8], 'asdf'); $job->setStatus($jobData[3]); @@ -51,7 +52,7 @@ class Schedule extends TaskAbstract $job->setLastRuntime(new \DateTime($jobData[5])); } - $job->setComment($jobData[10]); + $job->setComment($jobData[10] ?? ''); return $job; } diff --git a/Utils/TaskSchedule/SchedulerAbstract.php b/Utils/TaskSchedule/SchedulerAbstract.php index 3e6ca873a..e5043f49f 100644 --- a/Utils/TaskSchedule/SchedulerAbstract.php +++ b/Utils/TaskSchedule/SchedulerAbstract.php @@ -101,33 +101,6 @@ abstract class SchedulerAbstract return false; } - /** - * Test git. - * - * @return bool - * - * @since 1.0.0 - * @codeCoverageIgnore - */ - public static function test() : bool - { - $pipes = []; - $resource = \proc_open(\escapeshellarg(self::$bin), [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes); - - if ($resource === false) { - return false; - } - - $stdout = \stream_get_contents($pipes[1]); - $stderr = \stream_get_contents($pipes[2]); - - foreach ($pipes as $pipe) { - \fclose($pipe); - } - - return \proc_close($resource) !== 127; - } - /** * Run command * diff --git a/tests/Account/AccountStatusTest.php b/tests/Account/AccountStatusTest.php index 1a9e8c81e..dc124d4e8 100644 --- a/tests/Account/AccountStatusTest.php +++ b/tests/Account/AccountStatusTest.php @@ -31,6 +31,14 @@ class AccountStatusTest extends \PHPUnit\Framework\TestCase self::assertCount(4, AccountStatus::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(AccountStatus::getConstants(), \array_unique(AccountStatus::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/Account/AccountTypeTest.php b/tests/Account/AccountTypeTest.php index e69ed7242..abcd89e07 100644 --- a/tests/Account/AccountTypeTest.php +++ b/tests/Account/AccountTypeTest.php @@ -31,6 +31,14 @@ class AccountTypeTest extends \PHPUnit\Framework\TestCase self::assertCount(2, AccountType::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(AccountType::getConstants(), \array_unique(AccountType::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/Account/GroupStatusTest.php b/tests/Account/GroupStatusTest.php index 25a5bc633..48b63f2d9 100644 --- a/tests/Account/GroupStatusTest.php +++ b/tests/Account/GroupStatusTest.php @@ -31,6 +31,14 @@ class GroupStatusTest extends \PHPUnit\Framework\TestCase self::assertCount(3, GroupStatus::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(GroupStatus::getConstants(), \array_unique(GroupStatus::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/ApplicationAbstractTest.php b/tests/ApplicationAbstractTest.php index 324d3c61b..3f310d1d0 100644 --- a/tests/ApplicationAbstractTest.php +++ b/tests/ApplicationAbstractTest.php @@ -17,17 +17,33 @@ namespace phpOMS\tests; use phpOMS\ApplicationAbstract; /** + * @testdox phpOMS\tests\ApplicationAbstractTest: Application abstraction + * * @internal */ class ApplicationAbstractTest extends \PHPUnit\Framework\TestCase { - public function testGetSet() : void + /** + * @testdox Application values can be set and returned + * @covers phpOMS\ApplicationAbstract + */ + public function testInputOutput() : void { $obj = new class() extends ApplicationAbstract {}; $obj->appName = 'Test'; self::assertEquals('Test', $obj->appName); + } + /** + * @testdox Application values cannot be overwritten + * @covers phpOMS\ApplicationAbstract + */ + public function testInvalidInputOutput() : void + { + $obj = new class() extends ApplicationAbstract {}; + + $obj->appName = 'Test'; $obj->appName = 'ABC'; self::assertEquals('Test', $obj->appName); } diff --git a/tests/Asset/AssetTypeTest.php b/tests/Asset/AssetTypeTest.php index daffff885..163ee0da3 100644 --- a/tests/Asset/AssetTypeTest.php +++ b/tests/Asset/AssetTypeTest.php @@ -31,6 +31,14 @@ class AssetTypeTest extends \PHPUnit\Framework\TestCase self::assertCount(3, AssetType::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(AssetType::getConstants(), \array_unique(AssetType::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/Auth/LoginReturnTypeTest.php b/tests/Auth/LoginReturnTypeTest.php index dda77f403..e93e770bb 100644 --- a/tests/Auth/LoginReturnTypeTest.php +++ b/tests/Auth/LoginReturnTypeTest.php @@ -31,6 +31,14 @@ class LoginReturnTypeTest extends \PHPUnit\Framework\TestCase self::assertCount(11, LoginReturnType::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(LoginReturnType::getConstants(), \array_unique(LoginReturnType::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/AutoloaderTest.php b/tests/AutoloaderTest.php index e80c2a977..24fde0438 100644 --- a/tests/AutoloaderTest.php +++ b/tests/AutoloaderTest.php @@ -17,10 +17,16 @@ namespace phpOMS\tests; use phpOMS\Autoloader; /** + * @testdox phpOMS\tests\AutoloaderTest: Class autoloader + * * @internal */ class AutoloaderTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox Classes can be checked for existence + * @covers phpOMS\Autoloader + */ public function testAutoloader() : void { self::assertTrue(Autoloader::exists('\phpOMS\Autoloader')); diff --git a/tests/DataStorage/Cache/CacheStatusTest.php b/tests/DataStorage/Cache/CacheStatusTest.php index 749cb0177..82e982254 100644 --- a/tests/DataStorage/Cache/CacheStatusTest.php +++ b/tests/DataStorage/Cache/CacheStatusTest.php @@ -29,6 +29,14 @@ class CacheStatusTest extends \PHPUnit\Framework\TestCase self::assertCount(4, CacheStatus::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(CacheStatus::getConstants(), \array_unique(CacheStatus::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/DataStorage/Cache/CacheTypeTest.php b/tests/DataStorage/Cache/CacheTypeTest.php index 90849f910..5cd8bd99d 100644 --- a/tests/DataStorage/Cache/CacheTypeTest.php +++ b/tests/DataStorage/Cache/CacheTypeTest.php @@ -29,6 +29,14 @@ class CacheTypeTest extends \PHPUnit\Framework\TestCase self::assertCount(4, CacheType::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(CacheType::getConstants(), \array_unique(CacheType::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/DataStorage/Cache/Connection/CacheValueTypeTest.php b/tests/DataStorage/Cache/Connection/CacheValueTypeTest.php index 2e656e82c..3a5d3566e 100644 --- a/tests/DataStorage/Cache/Connection/CacheValueTypeTest.php +++ b/tests/DataStorage/Cache/Connection/CacheValueTypeTest.php @@ -29,6 +29,14 @@ class CacheValueTypeTest extends \PHPUnit\Framework\TestCase self::assertCount(8, CacheValueType::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(CacheValueType::getConstants(), \array_unique(CacheValueType::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/DataStorage/Cache/Connection/FileCacheTest.php b/tests/DataStorage/Cache/Connection/FileCacheTest.php index 1667c188f..3f4f6e40c 100644 --- a/tests/DataStorage/Cache/Connection/FileCacheTest.php +++ b/tests/DataStorage/Cache/Connection/FileCacheTest.php @@ -48,6 +48,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox The file cache connection has the expected default values after initialization + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testDefault() : void { @@ -69,6 +70,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox The connection to a dedicated cache directory can be established (none-exising directories get created) + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testConnect() : void { @@ -77,6 +79,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox Different cache data (types) can be set and returned + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testSetInputOutput() : void { @@ -107,6 +110,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox Cache data can bet added and returned + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testAddInputOutput() : void { @@ -116,6 +120,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox Cache data cannot be added if it already exists + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testInvalidOverwrite() : void { @@ -126,6 +131,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox Existing cache data can be replaced + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testReplace() : void { @@ -138,6 +144,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox None-existing cache data cannot be replaced + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testInvalidReplace() : void { @@ -146,6 +153,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox Existing cache data can be deleted + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testDelete() : void { @@ -158,6 +166,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox The cache correctly handles general cache information + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testStats() : void { @@ -179,6 +188,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox The cache can be flushed + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testFlush() : void { @@ -203,6 +213,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox Cache data can be set and returned with expiration limits + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testUnexpiredInputOutput() : void { @@ -212,6 +223,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox Expired cache data cannot be returned + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testExpiredInputOutput() : void { @@ -224,6 +236,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox Expired cache data can be forced to return + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testForceExpiredInputOutput() : void { @@ -234,6 +247,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox Unexpired cache data connot be delete if lower expiration is defined + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testInvalidDeleteUnexpired() : void { @@ -243,6 +257,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox Expired cache data can be deleted if equal expiration is defined + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testDeleteExpired() : void { @@ -253,6 +268,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox Unexpired data can be force deleted with lower expiration date + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testForceDeleteUnexpired() : void { @@ -264,6 +280,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox Cach data can be flushed by expiration date + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testFlushExpired() : void { @@ -276,6 +293,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox A bad cache status will prevent all cache actions + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testBadCacheStatus() : void { @@ -293,6 +311,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox A invalid cache connection will throw an InvalidConnectionConfigException + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testInvalidCachePath() : void { @@ -303,12 +322,12 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase /** * @testdox A invalid data type will throw an InvalidArgumentException + * @covers phpOMS\DataStorage\Cache\Connection\FileCache */ public function testInvalidDataType() : void { self::expectException(\InvalidArgumentException::class); $this->cache->add('invalid', $this->cache); - } } diff --git a/tests/DataStorage/Cache/Connection/MemCachedTest.php b/tests/DataStorage/Cache/Connection/MemCachedTest.php index bb59e52ea..e99839bf9 100644 --- a/tests/DataStorage/Cache/Connection/MemCachedTest.php +++ b/tests/DataStorage/Cache/Connection/MemCachedTest.php @@ -20,10 +20,14 @@ use phpOMS\DataStorage\Cache\Connection\MemCached; use phpOMS\Utils\TestUtils; /** + * @testdox phpOMS\tests\DataStorage\Cache\Connection\MemCachedTest: Memcache connection + * * @internal */ class MemCachedTest extends \PHPUnit\Framework\TestCase { + protected MemCached $cache; + protected function setUp() : void { if (!\extension_loaded('memcached')) { @@ -31,19 +35,36 @@ class MemCachedTest extends \PHPUnit\Framework\TestCase 'The Memcached extension is not available.' ); } + + $this->cache = new MemCached($GLOBALS['CONFIG']['cache']['memcached']); } + /** + * @testdox The memcached connection has the expected default values after initialization + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ public function testDefault() : void { - $cache = new MemCached($GLOBALS['CONFIG']['cache']['memcached']); - - self::assertEquals('', $cache->getPrefix()); - self::assertEquals(CacheType::MEMCACHED, $cache->getType()); - self::assertTrue($cache->flushAll()); - self::assertEquals(0, $cache->getThreshold()); - self::assertNull($cache->get('test')); + self::assertEquals('', $this->cache->getPrefix()); + self::assertEquals(CacheType::MEMCACHED, $this->cache->getType()); + self::assertTrue(\is_dir(__DIR__ . '/Cache')); + self::assertTrue($this->cache->flushAll()); + self::assertEquals(50, $this->cache->getThreshold()); + self::assertNull($this->cache->get('test')); + self::assertEquals( + [ + 'status' => CacheStatus::OK, + 'count' => 0, + 'size' => 0, + ], + $this->cache->stats() + ); } + /** + * @testdox The connection to a cache can be established (none-exising directories get created) + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ public function testConnect() : void { $cache = new MemCached($GLOBALS['CONFIG']['cache']['memcached']); @@ -53,94 +74,253 @@ class MemCachedTest extends \PHPUnit\Framework\TestCase self::assertEquals((int) $GLOBALS['CONFIG']['cache']['memcached']['port'], $cache->getPort()); } - public function testGetSet() : void + /** + * @testdox Different cache data (types) can be set and returned + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ + public function testSetInputOutput() : void { - $cache = new MemCached($GLOBALS['CONFIG']['cache']['memcached']); + $this->cache->set('key1', 'testVal'); + self::assertEquals('testVal', $this->cache->get('key1')); - $cache->flushAll(); + $this->cache->set('key2', false); + self::assertFalse($this->cache->get('key2')); - $cache->set('key1', 'testVal'); // 1 - self::assertEquals('testVal', $cache->get('key1')); + $this->cache->set('key3', null); + self::assertNull($this->cache->get('key3')); - self::assertTrue($cache->add('addKey', 'testValAdd')); // 2 - self::assertFalse($cache->add('addKey', 'testValAdd2')); - self::assertEquals('testValAdd', $cache->get('addKey')); + $this->cache->set('key4', 4); + self::assertEquals(4, $this->cache->get('key4')); - $cache->set('key2', false); // 3 - self::assertFalse($cache->get('key2')); + $this->cache->set('key5', 5.12); + self::assertEquals(5.12, $this->cache->get('key5')); - $cache->set('key3', null); // 4 - self::assertNull($cache->get('key3')); + $this->cache->set('key6', ['asdf', 1, true, 2.3]); + self::assertEquals(['asdf', 1, true, 2.3], $this->cache->get('key6')); - $cache->set('key4', 4); // 5 - self::assertEquals(4, $cache->get('key4')); + $this->cache->set('key7', new FileCacheSerializable()); + self::assertEquals('abc', $this->cache->get('key7')->val); - $cache->set('key5', 5.12); // 6 - self::assertEquals(5.12, $cache->get('key5')); - - $cache->set('key6', ['asdf', 1, true, 2.3]); // 7 - self::assertEquals(\json_encode(['asdf', 1, true, 2.3]), $cache->get('key6')); - - self::assertTrue($cache->replace('key4', 5)); - self::assertFalse($cache->replace('keyInvalid', 5)); - self::assertEquals(5, $cache->get('key4')); - - self::assertTrue($cache->delete('key4')); // 6 - self::assertFalse($cache->delete('keyInvalid')); - self::assertNull($cache->get('key4')); - - $arr = [ - 'status' => CacheStatus::OK, - 'count' => 6, - ]; - $isSubset = true; - $parent = $cache->stats(); - foreach ($arr as $key => $value) { - if (!isset($parent[$key]) || $parent[$key] !== $value) { - $isSubset = false; - break; - } - } - self::assertTrue($isSubset); - - self::assertTrue($cache->flushAll()); - self::assertTrue($cache->flush()); - self::assertNull($cache->get('key5')); // This reduces the stat count by one see stat comment. Stupid memcached! - - $cache->flushAll(); - - $arr = [ - 'status' => CacheStatus::OK, - 'count' => 5, // Carefull memcached is dumb and keeps expired elements which were not acessed after flushing in stats - ]; - $isSubset = true; - $parent = $cache->stats(); - foreach ($arr as $key => $value) { - if (!isset($parent[$key]) || $parent[$key] !== $value) { - $isSubset = false; - break; - } - } - self::assertTrue($isSubset); + $this->cache->set('key8', new FileCacheJsonSerializable()); + self::assertEquals('abc', $this->cache->get('key8')->val); } + /** + * @testdox Cache data can bet added and returned + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ + public function testAddInputOutput() : void + { + self::assertTrue($this->cache->add('addKey', 'testValAdd')); + self::assertEquals('testValAdd', $this->cache->get('addKey')); + } + + /** + * @testdox Cache data cannot be added if it already exists + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ + public function testInvalidOverwrite() : void + { + self::assertTrue($this->cache->add('addKey', 'testValAdd')); + self::assertFalse($this->cache->add('addKey', 'testValAdd2')); + self::assertEquals('testValAdd', $this->cache->get('addKey')); + } + + /** + * @testdox Existing cache data can be replaced + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ + public function testReplace() : void + { + $this->cache->set('key4', 4); + self::assertEquals(4, $this->cache->get('key4')); + + self::assertTrue($this->cache->replace('key4', 5)); + self::assertEquals(5, $this->cache->get('key4')); + } + + /** + * @testdox None-existing cache data cannot be replaced + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ + public function testInvalidReplace() : void + { + self::assertFalse($this->cache->replace('keyInvalid', 5)); + } + + /** + * @testdox Existing cache data can be deleted + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ + public function testDelete() : void + { + $this->cache->set('key4', 4); + self::assertEquals(4, $this->cache->get('key4')); + + self::assertTrue($this->cache->delete('key4')); + self::assertNull($this->cache->get('key4')); + } + + /** + * @testdox The cache correctly handles general cache information + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ + public function testStats() : void + { + $this->cache->set('key1', 'testVal'); + self::assertEquals('testVal', $this->cache->get('key1')); + + $this->cache->set('key2', false); + self::assertFalse($this->cache->get('key2')); + + self::assertEquals( + [ + 'status' => CacheStatus::OK, + 'count' => 2, + 'size' => 17, + ], + $this->cache->stats() + ); + } + + /** + * @testdox The cache can be flushed + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ + public function testFlush() : void + { + $this->cache->set('key1', 'testVal'); + self::assertEquals('testVal', $this->cache->get('key1')); + + $this->cache->set('key2', false); + self::assertFalse($this->cache->get('key2')); + + self::assertTrue($this->cache->flushAll()); + self::assertNull($this->cache->get('key5')); + + self::assertEquals( + [ + 'status' => CacheStatus::OK, + 'count' => 0, + 'size' => 0, + ], + $this->cache->stats() + ); + } + + /** + * @testdox Cache data can be set and returned with expiration limits + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ + public function testUnexpiredInputOutput() : void + { + $this->cache->set('key1', 'testVal', 1); + self::assertEquals('testVal', $this->cache->get('key1')); + } + + /** + * @testdox Expired cache data cannot be returned + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ + public function testExpiredInputOutput() : void + { + $this->cache->set('key2', 'testVal2', 1); + self::assertEquals('testVal2', $this->cache->get('key2', 1)); + \sleep(2); + self::assertNull($this->cache->get('key2', 1)); + self::assertNull($this->cache->get('key2')); // this causes a side effect of deleting the outdated cache element!!! + } + + /** + * @testdox Expired cache data can be forced to return + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ + public function testForceExpiredInputOutput() : void + { + $this->cache->set('key2', 'testVal2', 1); + \sleep(2); + self::assertEquals('testVal2', $this->cache->get('key2', 10)); + } + + /** + * @testdox Unexpired cache data connot be delete if lower expiration is defined + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ + public function testInvalidDeleteUnexpired() : void + { + $this->cache->set('key4', 'testVal4', 60); + self::assertFalse($this->cache->delete('key4', 0)); + } + + /** + * @testdox Expired cache data can be deleted if equal expiration is defined + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ + public function testDeleteExpired() : void + { + $this->cache->set('key4', 'testVal4', 1); + \sleep(2); + self::assertTrue($this->cache->delete('key4', 1)); + } + + /** + * @testdox Unexpired data can be force deleted with lower expiration date + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ + public function testForceDeleteUnexpired() : void + { + $this->cache->set('key5', 'testVal5', 10000); + \sleep(2); + self::assertFalse($this->cache->delete('key5', 1000000)); + self::assertTrue($this->cache->delete('key5', 1)); + } + + /** + * @testdox Cach data can be flushed by expiration date + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ + public function testFlushExpired() : void + { + $this->cache->set('key6', 'testVal6', 1); + \sleep(2); + + $this->cache->flush(0); + self::assertNull($this->cache->get('key6', 0)); + } + + /** + * @testdox A bad cache status will prevent all cache actions + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ public function testBadCacheStatus() : void { - $cache = new MemCached($GLOBALS['CONFIG']['cache']['memcached']); - $cache->flushAll(); + TestUtils::setMember($this->cache, 'status', CacheStatus::FAILURE); - TestUtils::setMember($cache, 'status', CacheStatus::FAILURE); - - $cache->set('key1', 'testVal'); - self::assertFalse($cache->add('key2', 'testVal2')); - self::assertNull($cache->get('key1')); - self::assertFalse($cache->replace('key1', 5)); - self::assertFalse($cache->delete('key1')); - self::assertFalse($cache->flushAll()); - self::assertFalse($cache->flush()); - self::assertEquals([], $cache->stats()); + $this->cache->set('key1', 'testVal'); + self::assertFalse($this->cache->add('key2', 'testVal2')); + self::assertNull($this->cache->get('key1')); + self::assertFalse($this->cache->replace('key1', 5)); + self::assertFalse($this->cache->delete('key1')); + self::assertFalse($this->cache->flushAll()); + self::assertFalse($this->cache->flush()); + self::assertEquals([], $this->cache->stats()); } + /** + * @testdox A invalid data type will throw an InvalidArgumentException + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ + public function testInvalidDataType() : void + { + self::expectException(\InvalidArgumentException::class); + + $this->cache->add('invalid', $this->cache); + } + + /** + * @testdox A invalid host throws a InvalidConnectionConfigException + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ public function testInvalidCacheHost() : void { self::expectException(\phpOMS\DataStorage\Cache\Exception\InvalidConnectionConfigException::class); @@ -151,6 +331,10 @@ class MemCachedTest extends \PHPUnit\Framework\TestCase $cache = new MemCached($db); } + /** + * @testdox A invalid port throws a InvalidConnectionConfigException + * @covers phpOMS\DataStorage\Cache\Connection\MemCached + */ public function testInvalidCachePort() : void { self::expectException(\phpOMS\DataStorage\Cache\Exception\InvalidConnectionConfigException::class); diff --git a/tests/DataStorage/Cache/Connection/NullCacheTest.php b/tests/DataStorage/Cache/Connection/NullCacheTest.php index 59bd6abca..4b6864405 100644 --- a/tests/DataStorage/Cache/Connection/NullCacheTest.php +++ b/tests/DataStorage/Cache/Connection/NullCacheTest.php @@ -18,10 +18,16 @@ use phpOMS\DataStorage\Cache\CacheType; use phpOMS\DataStorage\Cache\Connection\NullCache; /** + * @testdox phpOMS\tests\DataStorage\Cache\Connection\NullCacheTest: Null cache connection if no cache is available + * * @internal */ class NullCacheTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox The default cache has the expected default values after initialization + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ public function testCache() : void { $cache = new NullCache(); diff --git a/tests/DataStorage/Cache/Connection/RedisCacheTest.php b/tests/DataStorage/Cache/Connection/RedisCacheTest.php index 63e3385d4..5e1035270 100644 --- a/tests/DataStorage/Cache/Connection/RedisCacheTest.php +++ b/tests/DataStorage/Cache/Connection/RedisCacheTest.php @@ -20,10 +20,14 @@ use phpOMS\DataStorage\Cache\Connection\RedisCache; use phpOMS\Utils\TestUtils; /** + * @testdox phpOMS\tests\DataStorage\Cache\Connection\RedisCacheTest: Redis cache connection + * * @internal */ class RedisCacheTest extends \PHPUnit\Framework\TestCase { + protected RedisCache $cache; + protected function setUp() : void { if (!\extension_loaded('redis')) { @@ -31,20 +35,36 @@ class RedisCacheTest extends \PHPUnit\Framework\TestCase 'The Redis extension is not available.' ); } + + $this->cache = new RedisCache($GLOBALS['CONFIG']['cache']['redis']); } + /** + * @testdox The redis cache connection has the expected default values after initialization + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ public function testDefault() : void { - $cache = new RedisCache($GLOBALS['CONFIG']['cache']['redis']); - - self::assertEquals('', $cache->getPrefix()); - self::assertEquals(CacheType::REDIS, $cache->getType()); - self::assertTrue($cache->flushAll()); - self::assertTrue($cache->flush()); - self::assertEquals(0, $cache->getThreshold()); - self::assertNull($cache->get('test')); + self::assertEquals('', $this->cache->getPrefix()); + self::assertEquals(CacheType::REDIS, $this->cache->getType()); + self::assertTrue(\is_dir(__DIR__ . '/Cache')); + self::assertTrue($this->cache->flushAll()); + self::assertEquals(50, $this->cache->getThreshold()); + self::assertNull($this->cache->get('test')); + self::assertEquals( + [ + 'status' => CacheStatus::OK, + 'count' => 0, + 'size' => 0, + ], + $this->cache->stats() + ); } + /** + * @testdox The connection to a cache can be established (none-exising directories get created) + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ public function testConnect() : void { $cache = new RedisCache($GLOBALS['CONFIG']['cache']['redis']); @@ -55,94 +75,243 @@ class RedisCacheTest extends \PHPUnit\Framework\TestCase self::assertEquals((int) $GLOBALS['CONFIG']['cache']['redis']['port'], $cache->getPort()); } - public function testGetSet() : void + /** + * @testdox Different cache data (types) can be set and returned + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ + public function testSetInputOutput() : void { - $cache = new RedisCache($GLOBALS['CONFIG']['cache']['redis']); + $this->cache->set('key1', 'testVal'); + self::assertEquals('testVal', $this->cache->get('key1')); - $cache->flushAll(); + $this->cache->set('key2', false); + self::assertFalse($this->cache->get('key2')); - $cache->set('key1', 'testVal'); // 1 - self::assertEquals('testVal', $cache->get('key1')); + $this->cache->set('key3', null); + self::assertNull($this->cache->get('key3')); - self::assertTrue($cache->add('addKey', 'testValAdd')); // 2 - self::assertFalse($cache->add('addKey', 'testValAdd2')); - self::assertEquals('testValAdd', $cache->get('addKey')); + $this->cache->set('key4', 4); + self::assertEquals(4, $this->cache->get('key4')); - $cache->set('key2', false); // 3 - self::assertFalse($cache->get('key2')); + $this->cache->set('key5', 5.12); + self::assertEquals(5.12, $this->cache->get('key5')); - $cache->set('key3', null); // 4 - self::assertNull($cache->get('key3')); + $this->cache->set('key6', ['asdf', 1, true, 2.3]); + self::assertEquals(['asdf', 1, true, 2.3], $this->cache->get('key6')); - $cache->set('key4', 4); // 5 - self::assertEquals(4, $cache->get('key4')); + $this->cache->set('key7', new FileCacheSerializable()); + self::assertEquals('abc', $this->cache->get('key7')->val); - $cache->set('key5', 5.12); // 6 - self::assertEquals(5.12, $cache->get('key5')); - - $cache->set('key6', ['asdf', 1, true, 2.3]); // 7 - self::assertEquals(\json_encode(['asdf', 1, true, 2.3]), $cache->get('key6')); - - self::assertTrue($cache->replace('key4', 5)); - self::assertFalse($cache->replace('keyInvalid', 5)); - self::assertEquals(5, $cache->get('key4')); - - self::assertTrue($cache->delete('key4')); // 6 - self::assertFalse($cache->delete('keyInvalid')); - self::assertNull($cache->get('key4')); - - $arr = [ - 'status' => CacheStatus::OK, - 'count' => 6, - ]; - $isSubset = true; - $parent = $cache->stats(); - foreach ($arr as $key => $value) { - if (!isset($parent[$key]) || $parent[$key] !== $value) { - $isSubset = false; - break; - } - } - self::assertTrue($isSubset); - - self::assertTrue($cache->flushAll()); - self::assertTrue($cache->flush()); - self::assertNull($cache->get('key5')); - - $cache->flushAll(); - - $arr = [ - 'status' => CacheStatus::OK, - 'count' => 0, - ]; - $isSubset = true; - $parent = $cache->stats(); - foreach ($arr as $key => $value) { - if (!isset($parent[$key]) || $parent[$key] !== $value) { - $isSubset = false; - break; - } - } - self::assertTrue($isSubset); + $this->cache->set('key8', new FileCacheJsonSerializable()); + self::assertEquals('abc', $this->cache->get('key8')->val); } + /** + * @testdox Cache data can bet added and returned + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ + public function testAddInputOutput() : void + { + self::assertTrue($this->cache->add('addKey', 'testValAdd')); + self::assertEquals('testValAdd', $this->cache->get('addKey')); + } + + /** + * @testdox Cache data cannot be added if it already exists + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ + public function testInvalidOverwrite() : void + { + self::assertTrue($this->cache->add('addKey', 'testValAdd')); + self::assertFalse($this->cache->add('addKey', 'testValAdd2')); + self::assertEquals('testValAdd', $this->cache->get('addKey')); + } + + /** + * @testdox Existing cache data can be replaced + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ + public function testReplace() : void + { + $this->cache->set('key4', 4); + self::assertEquals(4, $this->cache->get('key4')); + + self::assertTrue($this->cache->replace('key4', 5)); + self::assertEquals(5, $this->cache->get('key4')); + } + + /** + * @testdox None-existing cache data cannot be replaced + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ + public function testInvalidReplace() : void + { + self::assertFalse($this->cache->replace('keyInvalid', 5)); + } + + /** + * @testdox Existing cache data can be deleted + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ + public function testDelete() : void + { + $this->cache->set('key4', 4); + self::assertEquals(4, $this->cache->get('key4')); + + self::assertTrue($this->cache->delete('key4')); + self::assertNull($this->cache->get('key4')); + } + + /** + * @testdox The cache correctly handles general cache information + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ + public function testStats() : void + { + $this->cache->set('key1', 'testVal'); + self::assertEquals('testVal', $this->cache->get('key1')); + + $this->cache->set('key2', false); + self::assertFalse($this->cache->get('key2')); + + self::assertEquals( + [ + 'status' => CacheStatus::OK, + 'count' => 2, + 'size' => 17, + ], + $this->cache->stats() + ); + } + + /** + * @testdox The cache can be flushed + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ + public function testFlush() : void + { + $this->cache->set('key1', 'testVal'); + self::assertEquals('testVal', $this->cache->get('key1')); + + $this->cache->set('key2', false); + self::assertFalse($this->cache->get('key2')); + + self::assertTrue($this->cache->flushAll()); + self::assertNull($this->cache->get('key5')); + + self::assertEquals( + [ + 'status' => CacheStatus::OK, + 'count' => 0, + 'size' => 0, + ], + $this->cache->stats() + ); + } + + /** + * @testdox Cache data can be set and returned with expiration limits + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ + public function testUnexpiredInputOutput() : void + { + $this->cache->set('key1', 'testVal', 1); + self::assertEquals('testVal', $this->cache->get('key1')); + } + + /** + * @testdox Expired cache data cannot be returned + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ + public function testExpiredInputOutput() : void + { + $this->cache->set('key2', 'testVal2', 1); + self::assertEquals('testVal2', $this->cache->get('key2', 1)); + \sleep(2); + self::assertNull($this->cache->get('key2', 1)); + self::assertNull($this->cache->get('key2')); // this causes a side effect of deleting the outdated cache element!!! + } + + /** + * @testdox Expired cache data can be forced to return + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ + public function testForceExpiredInputOutput() : void + { + $this->cache->set('key2', 'testVal2', 1); + \sleep(2); + self::assertEquals('testVal2', $this->cache->get('key2', 10)); + } + + /** + * @testdox Unexpired cache data connot be delete if lower expiration is defined + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ + public function testInvalidDeleteUnexpired() : void + { + $this->cache->set('key4', 'testVal4', 60); + self::assertFalse($this->cache->delete('key4', 0)); + } + + /** + * @testdox Expired cache data can be deleted if equal expiration is defined + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ + public function testDeleteExpired() : void + { + $this->cache->set('key4', 'testVal4', 1); + \sleep(2); + self::assertTrue($this->cache->delete('key4', 1)); + } + + /** + * @testdox Unexpired data can be force deleted with lower expiration date + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ + public function testForceDeleteUnexpired() : void + { + $this->cache->set('key5', 'testVal5', 10000); + \sleep(2); + self::assertFalse($this->cache->delete('key5', 1000000)); + self::assertTrue($this->cache->delete('key5', 1)); + } + + /** + * @testdox Cach data can be flushed by expiration date + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ + public function testFlushExpired() : void + { + $this->cache->set('key6', 'testVal6', 1); + \sleep(2); + + $this->cache->flush(0); + self::assertNull($this->cache->get('key6', 0)); + } + + /** + * @testdox A bad cache status will prevent all cache actions + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ public function testBadCacheStatus() : void { - $cache = new RedisCache($GLOBALS['CONFIG']['cache']['redis']); - $cache->flushAll(); + TestUtils::setMember($this->cache, 'status', CacheStatus::FAILURE); - TestUtils::setMember($cache, 'status', CacheStatus::FAILURE); - - $cache->set('key1', 'testVal'); - self::assertFalse($cache->add('key2', 'testVal2')); - self::assertNull($cache->get('key1')); - self::assertFalse($cache->replace('key1', 5)); - self::assertFalse($cache->delete('key1')); - self::assertFalse($cache->flushAll()); - self::assertFalse($cache->flush()); - self::assertEquals([], $cache->stats()); + $this->cache->set('key1', 'testVal'); + self::assertFalse($this->cache->add('key2', 'testVal2')); + self::assertNull($this->cache->get('key1')); + self::assertFalse($this->cache->replace('key1', 5)); + self::assertFalse($this->cache->delete('key1')); + self::assertFalse($this->cache->flushAll()); + self::assertFalse($this->cache->flush()); + self::assertEquals([], $this->cache->stats()); } + + /** + * @testdox A invalid host throws a InvalidConnectionConfigException + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ public function testInvalidCacheHost() : void { self::expectException(\phpOMS\DataStorage\Cache\Exception\InvalidConnectionConfigException::class); @@ -153,6 +322,10 @@ class RedisCacheTest extends \PHPUnit\Framework\TestCase $cache = new RedisCache($db); } + /** + * @testdox A invalid port throws a InvalidConnectionConfigException + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ public function testInvalidCachePort() : void { self::expectException(\phpOMS\DataStorage\Cache\Exception\InvalidConnectionConfigException::class); @@ -163,6 +336,10 @@ class RedisCacheTest extends \PHPUnit\Framework\TestCase $cache = new RedisCache($db); } + /** + * @testdox A invalid database throws a InvalidConnectionConfigException + * @covers phpOMS\DataStorage\Cache\Connection\RedisCache + */ public function testInvalidCacheDatabase() : void { self::expectException(\phpOMS\DataStorage\Cache\Exception\InvalidConnectionConfigException::class); diff --git a/tests/DataStorage/Database/DatabaseStatusTest.php b/tests/DataStorage/Database/DatabaseStatusTest.php index 1c768dd2e..63366a8d1 100644 --- a/tests/DataStorage/Database/DatabaseStatusTest.php +++ b/tests/DataStorage/Database/DatabaseStatusTest.php @@ -29,6 +29,14 @@ class DatabaseStatusTest extends \PHPUnit\Framework\TestCase self::assertCount(6, DatabaseStatus::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(DatabaseStatus::getConstants(), \array_unique(DatabaseStatus::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/DataStorage/Database/DatabaseTypeTest.php b/tests/DataStorage/Database/DatabaseTypeTest.php index e6a106bea..46bc6f634 100644 --- a/tests/DataStorage/Database/DatabaseTypeTest.php +++ b/tests/DataStorage/Database/DatabaseTypeTest.php @@ -29,6 +29,14 @@ class DatabaseTypeTest extends \PHPUnit\Framework\TestCase self::assertCount(5, DatabaseType::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(DatabaseType::getConstants(), \array_unique(DatabaseType::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/DataStorage/Database/RelationTypeTest.php b/tests/DataStorage/Database/RelationTypeTest.php index a0fdbfe7e..22c7c0421 100644 --- a/tests/DataStorage/Database/RelationTypeTest.php +++ b/tests/DataStorage/Database/RelationTypeTest.php @@ -29,6 +29,14 @@ class RelationTypeTest extends \PHPUnit\Framework\TestCase self::assertCount(7, RelationType::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(RelationType::getConstants(), \array_unique(RelationType::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/Dispatcher/DispatcherTest.php b/tests/Dispatcher/DispatcherTest.php index c8fed6f0b..02d365e8d 100644 --- a/tests/Dispatcher/DispatcherTest.php +++ b/tests/Dispatcher/DispatcherTest.php @@ -31,7 +31,7 @@ require_once __DIR__ . '/../Autoloader.php'; */ class DispatcherTest extends \PHPUnit\Framework\TestCase { - protected $app = null; + protected ApplicationAbstract $app; protected function setUp() : void { diff --git a/tests/Localization/Defaults/CityMapperTest.php b/tests/Localization/Defaults/CityMapperTest.php index 9902614b8..fb3fcdc0f 100644 --- a/tests/Localization/Defaults/CityMapperTest.php +++ b/tests/Localization/Defaults/CityMapperTest.php @@ -21,6 +21,8 @@ use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\Localization\Defaults\CityMapper; /** + * @testdox phpOMS\tests\Localization\Defaults\CityMapperTest: City database mapper + * * @internal */ class CityMapperTest extends \PHPUnit\Framework\TestCase @@ -36,6 +38,9 @@ class CityMapperTest extends \PHPUnit\Framework\TestCase DataMapperAbstract::setConnection($con); } + /** + * @testdox The model can be read from the database + */ public function testR() : void { $obj = CityMapper::get(101079); diff --git a/tests/Localization/Defaults/CityTest.php b/tests/Localization/Defaults/CityTest.php index 197fe368f..831429649 100644 --- a/tests/Localization/Defaults/CityTest.php +++ b/tests/Localization/Defaults/CityTest.php @@ -19,10 +19,15 @@ require_once __DIR__ . '/../../Autoloader.php'; use phpOMS\Localization\Defaults\City; /** + * @testdox phpOMS\tests\Localization\Defaults\CityTest: City database model + * * @internal */ class CityTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox The model has the expected member variables and default values + */ public function testDefaults() : void { $obj = new City(); diff --git a/tests/Localization/Defaults/CountryMapperTest.php b/tests/Localization/Defaults/CountryMapperTest.php index 92f81715d..a4ac41ee6 100644 --- a/tests/Localization/Defaults/CountryMapperTest.php +++ b/tests/Localization/Defaults/CountryMapperTest.php @@ -21,6 +21,8 @@ use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\Localization\Defaults\CountryMapper; /** + * @testdox phpOMS\tests\Localization\Defaults\CountryMapperTest: Country database mapper + * * @internal */ class CountryMapperTest extends \PHPUnit\Framework\TestCase @@ -36,6 +38,9 @@ class CountryMapperTest extends \PHPUnit\Framework\TestCase DataMapperAbstract::setConnection($con); } + /** + * @testdox The model can be read from the database + */ public function testR() : void { $obj = CountryMapper::get(83); diff --git a/tests/Localization/Defaults/CountryTest.php b/tests/Localization/Defaults/CountryTest.php index 94b650393..f58de98cb 100644 --- a/tests/Localization/Defaults/CountryTest.php +++ b/tests/Localization/Defaults/CountryTest.php @@ -19,10 +19,15 @@ require_once __DIR__ . '/../../Autoloader.php'; use phpOMS\Localization\Defaults\Country; /** + * @testdox phpOMS\tests\Localization\Defaults\CountryTest: Country database model + * * @internal */ class CountryTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox The model has the expected member variables and default values + */ public function testDefaults() : void { $obj = new Country(); diff --git a/tests/Localization/Defaults/CurrencyMapperTest.php b/tests/Localization/Defaults/CurrencyMapperTest.php index ffa430b45..39a55647a 100644 --- a/tests/Localization/Defaults/CurrencyMapperTest.php +++ b/tests/Localization/Defaults/CurrencyMapperTest.php @@ -21,6 +21,8 @@ use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\Localization\Defaults\CurrencyMapper; /** + * @testdox phpOMS\tests\Localization\Defaults\CurrencyMapperTest: Currency database mapper + * * @internal */ class CurrencyMapperTest extends \PHPUnit\Framework\TestCase @@ -36,6 +38,9 @@ class CurrencyMapperTest extends \PHPUnit\Framework\TestCase DataMapperAbstract::setConnection($con); } + /** + * @testdox The model can be read from the database + */ public function testR() : void { $obj = CurrencyMapper::get(50); diff --git a/tests/Localization/Defaults/CurrencyTest.php b/tests/Localization/Defaults/CurrencyTest.php index 36e6f26d1..0342f6b5b 100644 --- a/tests/Localization/Defaults/CurrencyTest.php +++ b/tests/Localization/Defaults/CurrencyTest.php @@ -19,10 +19,15 @@ require_once __DIR__ . '/../../Autoloader.php'; use phpOMS\Localization\Defaults\Currency; /** + * @testdox phpOMS\tests\Localization\Defaults\CurrencyTest: Currency database model + * * @internal */ class CurrencyTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox The model has the expected member variables and default values + */ public function testDefaults() : void { $obj = new Currency(); diff --git a/tests/Localization/Defaults/IbanMapperTest.php b/tests/Localization/Defaults/IbanMapperTest.php index 4088e2a14..8d3bda43b 100644 --- a/tests/Localization/Defaults/IbanMapperTest.php +++ b/tests/Localization/Defaults/IbanMapperTest.php @@ -21,6 +21,8 @@ use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\Localization\Defaults\IbanMapper; /** + * @testdox phpOMS\tests\Localization\Defaults\IbanMapperTest: Iban database mapper + * * @internal */ class IbanMapperTest extends \PHPUnit\Framework\TestCase @@ -36,6 +38,9 @@ class IbanMapperTest extends \PHPUnit\Framework\TestCase DataMapperAbstract::setConnection($con); } + /** + * @testdox The model can be read from the database + */ public function testR() : void { $obj = IbanMapper::get(22); diff --git a/tests/Localization/Defaults/IbanTest.php b/tests/Localization/Defaults/IbanTest.php index 5fb6c7ca1..58b32d9f5 100644 --- a/tests/Localization/Defaults/IbanTest.php +++ b/tests/Localization/Defaults/IbanTest.php @@ -19,10 +19,15 @@ require_once __DIR__ . '/../../Autoloader.php'; use phpOMS\Localization\Defaults\Iban; /** + * @testdox phpOMS\tests\Localization\Defaults\IbanTest: Iban database model + * * @internal */ class IbanTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox The model has the expected member variables and default values + */ public function testDefaults() : void { $obj = new Iban(); diff --git a/tests/Localization/Defaults/LanguageMapperTest.php b/tests/Localization/Defaults/LanguageMapperTest.php index 7404473b2..3fb6a9433 100644 --- a/tests/Localization/Defaults/LanguageMapperTest.php +++ b/tests/Localization/Defaults/LanguageMapperTest.php @@ -21,6 +21,8 @@ use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\Localization\Defaults\LanguageMapper; /** + * @testdox phpOMS\tests\Localization\Defaults\LanguageMapperTest: Language database mapper + * * @internal */ class LanguageMapperTest extends \PHPUnit\Framework\TestCase @@ -36,6 +38,9 @@ class LanguageMapperTest extends \PHPUnit\Framework\TestCase DataMapperAbstract::setConnection($con); } + /** + * @testdox The model can be read from the database + */ public function testR() : void { $obj = LanguageMapper::get(53); diff --git a/tests/Localization/Defaults/LanguageTest.php b/tests/Localization/Defaults/LanguageTest.php index 466180c18..6eafe64d4 100644 --- a/tests/Localization/Defaults/LanguageTest.php +++ b/tests/Localization/Defaults/LanguageTest.php @@ -19,10 +19,15 @@ require_once __DIR__ . '/../../Autoloader.php'; use phpOMS\Localization\Defaults\Language; /** + * @testdox phpOMS\tests\Localization\Defaults\LanguageTest: Language database model + * * @internal */ class LanguageTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox The model has the expected member variables and default values + */ public function testDefaults() : void { $obj = new Language(); diff --git a/tests/Log/LogLevelTest.php b/tests/Log/LogLevelTest.php index 10951cfa5..e87e335fb 100644 --- a/tests/Log/LogLevelTest.php +++ b/tests/Log/LogLevelTest.php @@ -31,6 +31,14 @@ class LogLevelTest extends \PHPUnit\Framework\TestCase self::assertCount(8, LogLevel::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(LogLevel::getConstants(), \array_unique(LogLevel::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/Math/Functions/FibunacciTest.php b/tests/Math/Functions/FibunacciTest.php index 340e21448..763ccadb2 100644 --- a/tests/Math/Functions/FibunacciTest.php +++ b/tests/Math/Functions/FibunacciTest.php @@ -28,11 +28,21 @@ class FibunacciTest extends \PHPUnit\Framework\TestCase self::assertTrue(Fibunacci::isFibunacci(89)); self::assertFalse(Fibunacci::isFibunacci(6)); self::assertFalse(Fibunacci::isFibunacci(87)); + } + public function testFibunacciByKey() : void + { self::assertEquals(1, Fibunacci::fib(1)); + } + + public function testIsFibunacci() : void + { self::assertTrue(Fibunacci::isFibunacci(Fibunacci::binet(3))); self::assertTrue(Fibunacci::isFibunacci(Fibunacci::binet(6))); + } + public function testBinet() : void + { self::assertEquals(Fibunacci::binet(6), Fibunacci::fib(6)); self::assertEquals(Fibunacci::binet(8), Fibunacci::fib(8)); } diff --git a/tests/Math/Functions/FunctionsTest.php b/tests/Math/Functions/FunctionsTest.php index 68cd298d4..3f97afbd3 100644 --- a/tests/Math/Functions/FunctionsTest.php +++ b/tests/Math/Functions/FunctionsTest.php @@ -25,7 +25,10 @@ class FunctionsTest extends \PHPUnit\Framework\TestCase { self::assertEquals(120, Functions::fact(5)); self::assertEquals(39916800, Functions::fact(11)); + } + public function testBinomialCoefficient() : void + { self::assertEquals(21, Functions::binomialCoefficient(7, 2)); self::assertEquals(6, Functions::binomialCoefficient(4, 2)); self::assertEquals(13983816, Functions::binomialCoefficient(49, 6)); @@ -46,13 +49,16 @@ class FunctionsTest extends \PHPUnit\Framework\TestCase self::assertEquals(5, Functions::invMod(-10, 17)); } - public function testProperties() : void + public function testOdd() : void { self::assertTrue(Functions::isOdd(3)); self::assertTrue(Functions::isOdd(-3)); self::assertFalse(Functions::isOdd(4)); self::assertFalse(Functions::isOdd(-4)); + } + public function testEven() : void + { self::assertTrue(Functions::isEven(4)); self::assertTrue(Functions::isEven(-4)); self::assertFalse(Functions::isEven(3)); diff --git a/tests/Math/Functions/GammaTest.php b/tests/Math/Functions/GammaTest.php index eac9ad32c..29c366351 100644 --- a/tests/Math/Functions/GammaTest.php +++ b/tests/Math/Functions/GammaTest.php @@ -27,24 +27,48 @@ class GammaTest extends \PHPUnit\Framework\TestCase self::assertEquals(Functions::fact(4), Gamma::getGammaInteger(5)); } - public function testApproximations() : void + public function testApproximationSpouge() : void + { + $spouge = [ + 2.67893853, 1.35411794, 1.00000000, 0.89297951, 0.90274529, 1.00000000, 1.19063935, 1.50457549, 2.00000000, 2.77815848, + ]; + + for ($i = 1; $i <= 10; ++$i) { + if (!(\abs($spouge[$i - 1] - Gamma::spougeApproximation($i / 3)) < 0.01)) { + self::assertTrue(false); + } + } + + self::assertTrue(true); + } + + public function testApproximationStirling() : void { $stirling = [ 2.15697602, 1.20285073, 0.92213701, 0.83974270, 0.85919025, 0.95950218, 1.14910642, 1.45849038, 1.94540320, 2.70976382, ]; - $spouge = [ - 2.67893853, 1.35411794, 1.00000000, 0.89297951, 0.90274529, 1.00000000, 1.19063935, 1.50457549, 2.00000000, 2.77815848, - ]; + for ($i = 1; $i <= 10; ++$i) { + if (!(\abs($stirling[$i - 1] - Gamma::stirlingApproximation($i / 3)) < 0.01)) { + self::assertTrue(false); + } + } + self::assertTrue(true); + } + + public function testApproximationLanzos() : void + { $gsl = [ 2.67893853, 1.35411794, 1.00000000, 0.89297951, 0.90274529, 1.00000000, 1.19063935, 1.50457549, 2.00000000, 2.77815848, ]; for ($i = 1; $i <= 10; ++$i) { - self::assertEqualsWithDelta($stirling[$i - 1], Gamma::stirlingApproximation($i / 3), 0.01); - self::assertEqualsWithDelta($spouge[$i - 1], Gamma::spougeApproximation($i / 3), 0.01); - self::assertEqualsWithDelta($gsl[$i - 1], Gamma::lanczosApproximationReal($i / 3), 0.01); + if (!(\abs($gsl[$i - 1] - Gamma::lanczosApproximationReal($i / 3)) < 0.01)) { + self::assertTrue(false); + } } + + self::assertTrue(true); } } diff --git a/tests/Math/Geometry/Shape/D2/CircleTest.php b/tests/Math/Geometry/Shape/D2/CircleTest.php index ecf42576a..813db9de9 100644 --- a/tests/Math/Geometry/Shape/D2/CircleTest.php +++ b/tests/Math/Geometry/Shape/D2/CircleTest.php @@ -21,11 +21,23 @@ use phpOMS\Math\Geometry\Shape\D2\Circle; */ class CircleTest extends \PHPUnit\Framework\TestCase { - public function testCircle() : void + public function testSurface() : void { self::assertEqualsWithDelta(12.57, Circle::getSurface(2), 0.01); + } + + public function testPerimeter() : void + { self::assertEqualsWithDelta(12.57, Circle::getPerimeter(2), 0.01); + } + + public function testRadiusBySurface() : void + { self::assertEqualsWithDelta(2.0, Circle::getRadiusBySurface(Circle::getSurface(2)), 0.001); + } + + public function testRadiusByPerimeter() : void + { self::assertEqualsWithDelta(2.0, Circle::getRadiusByPerimeter(Circle::getPerimeter(2)), 0.001); } } diff --git a/tests/Math/Geometry/Shape/D2/EllipseTest.php b/tests/Math/Geometry/Shape/D2/EllipseTest.php index 2f378101c..9ca4408f3 100644 --- a/tests/Math/Geometry/Shape/D2/EllipseTest.php +++ b/tests/Math/Geometry/Shape/D2/EllipseTest.php @@ -21,9 +21,13 @@ use phpOMS\Math\Geometry\Shape\D2\Ellipse; */ class EllipseTest extends \PHPUnit\Framework\TestCase { - public function testEllipse() : void + public function testSurface() : void { self::assertEqualsWithDelta(6.28, Ellipse::getSurface(2, 1), 0.01); + } + + public function testPerimeter() : void + { self::assertEqualsWithDelta(9.69, Ellipse::getPerimeter(2, 1), 0.01); } } diff --git a/tests/Math/Geometry/Shape/D2/PolygonTest.php b/tests/Math/Geometry/Shape/D2/PolygonTest.php index 0a8c78d9f..b4688b201 100644 --- a/tests/Math/Geometry/Shape/D2/PolygonTest.php +++ b/tests/Math/Geometry/Shape/D2/PolygonTest.php @@ -42,7 +42,7 @@ class PolygonTest extends \PHPUnit\Framework\TestCase self::assertEquals(-1, Polygon::isPointInPolygon(['x' => 1.8, 'y' => 1.1], $polyArray)); } - public function testAngle() : void + public function testInteriorAngle() : void { $polygon = new Polygon([[1, 2], [2, 3], [3, 4]]); self::assertEquals(180, $polygon->getInteriorAngleSum()); @@ -61,7 +61,11 @@ class PolygonTest extends \PHPUnit\Framework\TestCase $polygon = new Polygon([[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]); self::assertEquals(1080, $polygon->getInteriorAngleSum()); + } + public function testExteriorAngle() : void + { + $polygon = new Polygon([[1, 2], [2, 3], [3, 4]]); self::assertEquals(360, $polygon->getExteriorAngleSum()); } @@ -110,9 +114,13 @@ class PolygonTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(['x' => 3.5, 'y' => 1.5], $polygon->getBarycenter(), 0.5); } - public function testRegularArea() + public function testRegularAreaByLength() { self::assertEqualsWithDelta(3 * 3, Polygon::getRegularAreaByLength(3.0, 4), 0.01); + } + + public function testRegularAreaByRadius() + { self::assertEqualsWithDelta(3 * 3 , Polygon::getRegularAreaByRadius(1.5, 4), 0.01); } } diff --git a/tests/Math/Geometry/Shape/D2/RectangleTest.php b/tests/Math/Geometry/Shape/D2/RectangleTest.php index ffb5c87fe..38d0f69dc 100644 --- a/tests/Math/Geometry/Shape/D2/RectangleTest.php +++ b/tests/Math/Geometry/Shape/D2/RectangleTest.php @@ -21,10 +21,18 @@ use phpOMS\Math\Geometry\Shape\D2\Rectangle; */ class RectangleTest extends \PHPUnit\Framework\TestCase { - public function testRectanle() : void + public function testSurface() : void { self::assertEqualsWithDelta(10, Rectangle::getSurface(5, 2), 0.001); + } + + public function testPerimeter() : void + { self::assertEqualsWithDelta(10, Rectangle::getPerimeter(2, 3), 0.001); + } + + public function testDiagonal() : void + { self::assertEqualsWithDelta(32.7, Rectangle::getDiagonal(30, 13), 0.01); } } diff --git a/tests/Math/Geometry/Shape/D2/TrapezoidTest.php b/tests/Math/Geometry/Shape/D2/TrapezoidTest.php index c365124b4..90796215e 100644 --- a/tests/Math/Geometry/Shape/D2/TrapezoidTest.php +++ b/tests/Math/Geometry/Shape/D2/TrapezoidTest.php @@ -21,12 +21,23 @@ use phpOMS\Math\Geometry\Shape\D2\Trapezoid; */ class TrapezoidTest extends \PHPUnit\Framework\TestCase { - public function testTrapezoid() : void + public function testSurface() : void { self::assertEqualsWithDelta(10, Trapezoid::getSurface(2, 3, 4), 0.001); - self::assertEqualsWithDelta(14, Trapezoid::getPerimeter(2, 3, 4, 5), 0.001); - self::assertEqualsWithDelta(4, Trapezoid::getHeight(10, 2, 3), 0.001); + } + public function testPerimeter() : void + { + self::assertEqualsWithDelta(14, Trapezoid::getPerimeter(2, 3, 4, 5), 0.001); + } + + public function testHeight() : void + { + self::assertEqualsWithDelta(4, Trapezoid::getHeight(10, 2, 3), 0.001); + } + + public function testSideLength() : void + { self::assertEqualsWithDelta(2, Trapezoid::getA(10, 4, 3), 0.001); self::assertEqualsWithDelta(3, Trapezoid::getB(10, 4, 2), 0.001); self::assertEqualsWithDelta(4, Trapezoid::getC(14, 2, 3, 5), 0.001); diff --git a/tests/Math/Geometry/Shape/D2/TriangleTest.php b/tests/Math/Geometry/Shape/D2/TriangleTest.php index ace6bc5bb..eec0c2acd 100644 --- a/tests/Math/Geometry/Shape/D2/TriangleTest.php +++ b/tests/Math/Geometry/Shape/D2/TriangleTest.php @@ -21,11 +21,23 @@ use phpOMS\Math\Geometry\Shape\D2\Triangle; */ class TriangleTest extends \PHPUnit\Framework\TestCase { - public function testTriangle() : void + public function testSurface() : void { self::assertEqualsWithDelta(3, Triangle::getSurface(2, 3), 0.001); + } + + public function testPerimeter() : void + { self::assertEqualsWithDelta(9, Triangle::getPerimeter(2, 3, 4), 0.001); + } + + public function testHeight() : void + { self::assertEqualsWithDelta(3, Triangle::getHeight(3, 2), 0.001); + } + + public function testHypot() : void + { self::assertEqualsWithDelta(5, Triangle::getHypot(4, 3), 0.001); } } diff --git a/tests/Math/Geometry/Shape/D3/ConeTest.php b/tests/Math/Geometry/Shape/D3/ConeTest.php index 76742db03..271e8b1dc 100644 --- a/tests/Math/Geometry/Shape/D3/ConeTest.php +++ b/tests/Math/Geometry/Shape/D3/ConeTest.php @@ -21,11 +21,23 @@ use phpOMS\Math\Geometry\Shape\D3\Cone; */ class ConeTest extends \PHPUnit\Framework\TestCase { - public function testCone() : void + public function testVolume() : void { self::assertEqualsWithDelta(12.57, Cone::getVolume(2, 3), 0.01); + } + + public function testSurface() : void + { self::assertEqualsWithDelta(35.22, Cone::getSurface(2, 3), 0.01); + } + + public function testSlantHeight() : void + { self::assertEqualsWithDelta(3.61, Cone::getSlantHeight(2, 3), 0.01); + } + + public function testHeightFromVolume() : void + { self::assertEqualsWithDelta(3, Cone::getHeightFromVolume(12.57, 2), 0.01); } } diff --git a/tests/Math/Geometry/Shape/D3/CuboidTest.php b/tests/Math/Geometry/Shape/D3/CuboidTest.php index 39ec6c939..33dce8bb0 100644 --- a/tests/Math/Geometry/Shape/D3/CuboidTest.php +++ b/tests/Math/Geometry/Shape/D3/CuboidTest.php @@ -21,9 +21,13 @@ use phpOMS\Math\Geometry\Shape\D3\Cuboid; */ class CuboidTest extends \PHPUnit\Framework\TestCase { - public function testCuboid() : void + public function testVolume() : void { self::assertEqualsWithDelta(200, Cuboid::getVolume(10, 5, 4), 0.001); + } + + public function testSurface() : void + { self::assertEqualsWithDelta(220, Cuboid::getSurface(10, 5, 4), 0.001); } } diff --git a/tests/Math/Geometry/Shape/D3/CylinderTest.php b/tests/Math/Geometry/Shape/D3/CylinderTest.php index 5c22053aa..b7c17713c 100644 --- a/tests/Math/Geometry/Shape/D3/CylinderTest.php +++ b/tests/Math/Geometry/Shape/D3/CylinderTest.php @@ -21,10 +21,18 @@ use phpOMS\Math\Geometry\Shape\D3\Cylinder; */ class CylinderTest extends \PHPUnit\Framework\TestCase { - public function testCylinder() : void + public function testVolume() : void { self::assertEqualsWithDelta(37.7, Cylinder::getVolume(2, 3), 0.01); + } + + public function testSurface() : void + { self::assertEqualsWithDelta(62.83, Cylinder::getSurface(2, 3), 0.01); + } + + public function testLateralSurface() : void + { self::assertEqualsWithDelta(37.7, Cylinder::getLateralSurface(2, 3), 0.01); } } diff --git a/tests/Math/Geometry/Shape/D3/PrismTest.php b/tests/Math/Geometry/Shape/D3/PrismTest.php index 4549d948e..eeb7b1a6a 100644 --- a/tests/Math/Geometry/Shape/D3/PrismTest.php +++ b/tests/Math/Geometry/Shape/D3/PrismTest.php @@ -21,9 +21,13 @@ use phpOMS\Math\Geometry\Shape\D3\Prism; */ class PrismTest extends \PHPUnit\Framework\TestCase { - public function testVolume() : void + public function testVolumeByLength() : void { self::assertEqualsWithDelta(3 * 3 * 12, Prism::getVolumeRegularLength(3, 4, 12), 0.01); + } + + public function testVolumeByRadius() : void + { self::assertEqualsWithDelta(3 * 3 * 12, Prism::getVolumeRegularRadius(1.5, 4, 12), 0.01); } diff --git a/tests/Math/Geometry/Shape/D3/RectangularPyramidTest.php b/tests/Math/Geometry/Shape/D3/RectangularPyramidTest.php index e1b9cf197..bcf8aa94c 100644 --- a/tests/Math/Geometry/Shape/D3/RectangularPyramidTest.php +++ b/tests/Math/Geometry/Shape/D3/RectangularPyramidTest.php @@ -21,10 +21,18 @@ use phpOMS\Math\Geometry\Shape\D3\RectangularPyramid; */ class RectangularPyramidTest extends \PHPUnit\Framework\TestCase { - public function testCylinder() : void + public function testVolume() : void { self::assertEqualsWithDelta(8, RectangularPyramid::getVolume(2, 3, 4), 0.01); + } + + public function testSurface() : void + { self::assertEqualsWithDelta(26.91, RectangularPyramid::getSurface(2, 3, 4), 0.01); + } + + public function testLateralSurface() : void + { self::assertEqualsWithDelta(20.91, RectangularPyramid::getLateralSurface(2, 3, 4), 0.01); } } diff --git a/tests/Math/Geometry/Shape/D3/SphereTest.php b/tests/Math/Geometry/Shape/D3/SphereTest.php index 8e0dc2ec6..4759d598b 100644 --- a/tests/Math/Geometry/Shape/D3/SphereTest.php +++ b/tests/Math/Geometry/Shape/D3/SphereTest.php @@ -21,23 +21,37 @@ use phpOMS\Math\Geometry\Shape\D3\Sphere; */ class SphereTest extends \PHPUnit\Framework\TestCase { - public function testSphere() : void + public function testVolume() : void { $sphere = new Sphere(3); self::assertEqualsWithDelta(113.1, $sphere->getVolume(), 0.1); - self::assertEqualsWithDelta(113.1, $sphere->getSurface(), 0.1); + } + public function testSurface() : void + { + $sphere = new Sphere(3); + self::assertEqualsWithDelta(113.1, $sphere->getSurface(), 0.1); + } + + public function testDistanceOnSphere() : void + { self::assertEqualsWithDelta(422740, Sphere::distance2PointsOnSphere(32.9697, -96.80322, 29.46786, -98.53506), 50); } - public function testGetBy() : void + public function testGetSphereByRadius() : void { $sphere = Sphere::byRadius(3); self::assertEqualsWithDelta(3, $sphere->getRadius(), 0.1); + } + public function testGetSphereByVolume() : void + { $sphere = Sphere::byVolume(4); self::assertEqualsWithDelta(4, $sphere->getVolume(), 0.1); + } + public function testGetSphereBySurface() : void + { $sphere = Sphere::bySurface(5); self::assertEqualsWithDelta(5, $sphere->getSurface(), 0.1); } diff --git a/tests/Math/Geometry/Shape/D3/TetrahedronTest.php b/tests/Math/Geometry/Shape/D3/TetrahedronTest.php index f156bd082..584ddc7f6 100644 --- a/tests/Math/Geometry/Shape/D3/TetrahedronTest.php +++ b/tests/Math/Geometry/Shape/D3/TetrahedronTest.php @@ -21,10 +21,18 @@ use phpOMS\Math\Geometry\Shape\D3\Tetrahedron; */ class TetrahedronTest extends \PHPUnit\Framework\TestCase { - public function testTetrahedron() : void + public function testVolume() : void { self::assertEqualsWithDelta(3.18, Tetrahedron::getVolume(3), 0.01); + } + + public function testSurface() : void + { self::assertEqualsWithDelta(15.59, Tetrahedron::getSurface(3), 0.01); + } + + public function testFaceArea() : void + { self::assertEqualsWithDelta(3.9, Tetrahedron::getFaceArea(3), 0.01); } } diff --git a/tests/Math/Number/PrimeTest.php b/tests/Math/Number/PrimeTest.php index 4dd5f2966..be8add384 100644 --- a/tests/Math/Number/PrimeTest.php +++ b/tests/Math/Number/PrimeTest.php @@ -50,4 +50,11 @@ class PrimeTest extends \PHPUnit\Framework\TestCase self::assertTrue(Prime::isMersenne(Prime::mersenne(4))); self::assertFalse(Prime::isMersenne(2046)); } + + public function testIsMersenne() : void + { + self::assertTrue(Prime::isMersenne(Prime::mersenne(2))); + self::assertTrue(Prime::isMersenne(Prime::mersenne(4))); + self::assertFalse(Prime::isMersenne(2046)); + } } diff --git a/tests/Stdlib/Base/AddressTypeTest.php b/tests/Stdlib/Base/AddressTypeTest.php index 751009d8a..ec0241968 100644 --- a/tests/Stdlib/Base/AddressTypeTest.php +++ b/tests/Stdlib/Base/AddressTypeTest.php @@ -29,6 +29,14 @@ class AddressTypeTest extends \PHPUnit\Framework\TestCase self::assertCount(7, AddressType::getconstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(AddressType::getConstants(), \array_unique(AddressType::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/Stdlib/Base/PhoneTypeTest.php b/tests/Stdlib/Base/PhoneTypeTest.php index c5006e6ca..edcc86297 100644 --- a/tests/Stdlib/Base/PhoneTypeTest.php +++ b/tests/Stdlib/Base/PhoneTypeTest.php @@ -29,6 +29,14 @@ class PhoneTypeTest extends \PHPUnit\Framework\TestCase self::assertCount(4, PhoneType::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(PhoneType::getConstants(), \array_unique(PhoneType::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/Stdlib/Map/KeyTypeTest.php b/tests/Stdlib/Map/KeyTypeTest.php index de0ca9a0e..b35b19247 100644 --- a/tests/Stdlib/Map/KeyTypeTest.php +++ b/tests/Stdlib/Map/KeyTypeTest.php @@ -29,6 +29,14 @@ class KeyTypeTest extends \PHPUnit\Framework\TestCase self::assertCount(2, KeyType::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(KeyType::getConstants(), \array_unique(KeyType::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/Stdlib/Map/OrderTypeTest.php b/tests/Stdlib/Map/OrderTypeTest.php index 661c4c312..e27cdc57c 100644 --- a/tests/Stdlib/Map/OrderTypeTest.php +++ b/tests/Stdlib/Map/OrderTypeTest.php @@ -29,6 +29,14 @@ class OrderTypeTest extends \PHPUnit\Framework\TestCase self::assertCount(2, OrderType::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(OrderType::getConstants(), \array_unique(OrderType::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/Stdlib/Queue/PriorityModeTest.php b/tests/Stdlib/Queue/PriorityModeTest.php index 18daa8f52..bd97c4ff3 100644 --- a/tests/Stdlib/Queue/PriorityModeTest.php +++ b/tests/Stdlib/Queue/PriorityModeTest.php @@ -29,6 +29,14 @@ class PriorityModeTest extends \PHPUnit\Framework\TestCase self::assertCount(4, PriorityMode::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(PriorityMode::getConstants(), \array_unique(PriorityMode::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/System/SystemTypeTest.php b/tests/System/SystemTypeTest.php index f83bbd415..5dc7828cd 100644 --- a/tests/System/SystemTypeTest.php +++ b/tests/System/SystemTypeTest.php @@ -31,6 +31,14 @@ class SystemTypeTest extends \PHPUnit\Framework\TestCase self::assertCount(4, SystemType::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(SystemType::getConstants(), \array_unique(SystemType::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/Utils/ArrayUtilsTest.php b/tests/Utils/ArrayUtilsTest.php index 6e37f71d3..8e537da5b 100644 --- a/tests/Utils/ArrayUtilsTest.php +++ b/tests/Utils/ArrayUtilsTest.php @@ -19,11 +19,17 @@ use phpOMS\Utils\ArrayUtils; require_once __DIR__ . '/../Autoloader.php'; /** + * @testdox phpOMS\tests\Utils\ArrayUtilsTest: Array utilities + * * @internal */ class ArrayUtilsTest extends \PHPUnit\Framework\TestCase { - public function testArrayGetSet() : void + /** + * @testdox Array values can be set and returned with a path + * @covers phpOMS\Utils\ArrayUtils + */ + public function testArrayInputOutput() : void { $expected = [ 'a' => [ @@ -54,6 +60,10 @@ class ArrayUtilsTest extends \PHPUnit\Framework\TestCase self::assertEquals('ab0', ArrayUtils::getArray('a/ab/1', $expected)); } + /** + * @testdox Test recursively if a value is in an array + * @covers phpOMS\Utils\ArrayUtils + */ public function testArrayInRecursive() : void { $expected = [ @@ -71,10 +81,13 @@ class ArrayUtilsTest extends \PHPUnit\Framework\TestCase self::assertTrue(ArrayUtils::inArrayRecursive('2a', $expected)); self::assertTrue(ArrayUtils::inArrayRecursive('2a', $expected, 2)); self::assertFalse(ArrayUtils::inArrayRecursive('2a', $expected, 3)); - self::assertFalse(ArrayUtils::inArrayRecursive('aba', ArrayUtils::unsetArray('a/ab', $expected, '/'))); } - public function testArrayConversion() : void + /** + * @testdox An array element can be removed by its path + * @covers phpOMS\Utils\ArrayUtils + */ + public function testArrayDelete() : void { $expected = [ 'a' => [ @@ -85,24 +98,36 @@ class ArrayUtilsTest extends \PHPUnit\Framework\TestCase ], ], 2 => '2a', - 3 => false, - 'c' => null, ]; - $expected_str = "['a' => ['aa' => 1, 'ab' => [0 => 'aba', 1 => 'ab0', ], ], 2 => '2a', 3 => false, 'c' => null, ]"; - - self::assertEquals($expected_str, ArrayUtils::stringify($expected)); - self::assertEquals('2;3;1;"""Text;"' . "\n", ArrayUtils::arrayToCsv(['a' => 2, 3, 1, '"Text;'], ';', '"', '\\')); + self::assertFalse(ArrayUtils::inArrayRecursive('aba', ArrayUtils::unsetArray('a/ab', $expected, '/'))); } - public function testArrayRecursiveManipulation() : void + /** + * @testdox The recursive sum of all values in an array can be calculated + * @covers phpOMS\Utils\ArrayUtils + */ + public function testArrayRecursiveSum() : void + { + $numArrRec = [1, [2, [3, 4]]]; + self::assertEquals(10, ArrayUtils::arraySumRecursive($numArrRec)); + } + + /** + * @testdox A multi-dimensional array can be flatten to a one-dimensional array + * @covers phpOMS\Utils\ArrayUtils + */ + public function testArrayFlatten() : void { $numArr = [1, 2, 3, 4]; $numArrRec = [1, [2, [3, 4]]]; - self::assertEquals(10, ArrayUtils::arraySumRecursive($numArrRec)); self::assertEquals($numArr, ArrayUtils::arrayFlatten($numArrRec)); } + /** + * @testdox The sum of an array can be calculated + * @covers phpOMS\Utils\ArrayUtils + */ public function testArraySum() : void { $numArr = [1, 2, 3, 4]; @@ -111,6 +136,10 @@ class ArrayUtilsTest extends \PHPUnit\Framework\TestCase self::assertEquals(5, ArrayUtils::arraySum($numArr, 1, 2)); } + /** + * @testdox An array can be checked if it contains multiple defined elements + * @covers phpOMS\Utils\ArrayUtils + */ public function testArrayAllIn() : void { $numArr = [1, 2, 3, 4]; @@ -120,6 +149,10 @@ class ArrayUtilsTest extends \PHPUnit\Framework\TestCase self::assertFalse(ArrayUtils::allInArray([1, 5, 3], $numArr)); } + /** + * @testdox An array can be checked if it contains any of the defined elements + * @covers phpOMS\Utils\ArrayUtils + */ public function testArrayAnyIn() : void { $numArr = [1, 2, 3, 4]; @@ -127,38 +160,81 @@ class ArrayUtilsTest extends \PHPUnit\Framework\TestCase self::assertFalse(ArrayUtils::anyInArray($numArr, [10, 22])); } - public function testArg() : void + /** + * @testdox An array can be checked if it has an element and returns its index + * @covers phpOMS\Utils\ArrayUtils + */ + public function testArgHas() : void { - self::assertNull(ArrayUtils::hasArg('--testNull', $_SERVER['argv'])); - self::assertNull(ArrayUtils::getArg('--testNull', $_SERVER['argv'])); - if (ArrayUtils::getArg('--configuration', $_SERVER['argv']) !== null) { self::assertGreaterThan(0, ArrayUtils::hasArg('--configuration', $_SERVER['argv'])); + } + } + + /** + * @testdox A none-existing argument in an array returns a negative value + * @covers phpOMS\Utils\ArrayUtils + */ + public function testInvalidArgHas() : void + { + self::assertEquals(-1, ArrayUtils::hasArg('--testNull', $_SERVER['argv'])); + } + + /** + * @testdox The argument value in an array can be returned + * @covers phpOMS\Utils\ArrayUtils + */ + public function testArgGet() : void + { + if (ArrayUtils::getArg('--configuration', $_SERVER['argv']) !== null) { self::assertTrue(\stripos(ArrayUtils::getArg('--configuration', $_SERVER['argv']), '.xml') !== false); } } - public function testInvalidArrayStringify() : void + /** + * @testdox A none-existing argument in an array returns null + * @covers phpOMS\Utils\ArrayUtils + */ + public function testInvalidArgGet() : void { - self::expectException(\InvalidArgumentException::class); - - ArrayUtils::stringify([new class() {}]); + self::assertNull(ArrayUtils::getArg('--testNull', $_SERVER['argv'])); } - public function testPower() : void + /** + * @testdox All array values in an array can be exponentiated by an integer + * @covers phpOMS\Utils\ArrayUtils + */ + public function testPowerInt() : void { self::assertEquals([4, 9, 16], ArrayUtils::powerInt([2, 3, 4], 2)); self::assertEquals([8, 27, 64], ArrayUtils::powerInt([2, 3, 4], 3)); + } + /** + * @testdox All array values in an array can be exponentiated by a float + * @covers phpOMS\Utils\ArrayUtils + * + * @todo combine with int as soon as union types exist + */ + public function testPowerFloat() : void + { self::assertEqualsWithDelta([2.0, 3.0, 4.0], ArrayUtils::powerFloat([4, 9, 16], 1 / 2), 0.0); self::assertEqualsWithDelta([2.0, 3.0, 4.0], ArrayUtils::powerFloat([8, 27, 64], 1 / 3), 0.0); } + /** + * @testdox All array values in an array can be square rooted + * @covers phpOMS\Utils\ArrayUtils + */ public function testSqrt() : void { self::assertEqualsWithDelta([2, 3, 4], ArrayUtils::sqrt([4, 9, 16]), 0.01); } + /** + * @testdox All array values in an array can be turned into their absolute value + * @covers phpOMS\Utils\ArrayUtils + */ public function testAbs() : void { self::assertEquals([1, 3, 4], ArrayUtils::abs([-1, 3, -4])); diff --git a/tests/Utils/ColorUtilsTest.php b/tests/Utils/ColorUtilsTest.php index ffe427934..07db39a40 100644 --- a/tests/Utils/ColorUtilsTest.php +++ b/tests/Utils/ColorUtilsTest.php @@ -19,13 +19,27 @@ require_once __DIR__ . '/../Autoloader.php'; use phpOMS\Utils\ColorUtils; /** + * @testdox phpOMS\tests\Utils\ColorUtilsTest: Color utilities + * * @internal */ class ColorUtilsTest extends \PHPUnit\Framework\TestCase { - public function testColor() : void + /** + * @testdox A integer can be converted to rgb + * @covers phpOMS\Utils\ColorUtils + */ + public function testIntToRgb() : void { self::assertEquals(['r' => 0xbc, 'g' => 0x39, 'b' => 0x6c], ColorUtils::intToRgb(12335468)); + } + + /** + * @testdox Rgb can be converted to a integer + * @covers phpOMS\Utils\ColorUtils + */ + public function testRgbToInt() : void + { self::assertEquals(12335468, ColorUtils::rgbToInt(['r' => 0xbc, 'g' => 0x39, 'b' => 0x6c])); } } diff --git a/tests/Utils/Converter/FileSizeTypeTest.php b/tests/Utils/Converter/FileSizeTypeTest.php index e2b67c6bf..3a0fae661 100644 --- a/tests/Utils/Converter/FileSizeTypeTest.php +++ b/tests/Utils/Converter/FileSizeTypeTest.php @@ -29,6 +29,14 @@ class FileSizeTypeTest extends \PHPUnit\Framework\TestCase self::assertCount(10, FileSizeType::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(FileSizeType::getConstants(), \array_unique(FileSizeType::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/Utils/ImageUtilsTest.php b/tests/Utils/ImageUtilsTest.php index ca372da07..c37c1861a 100644 --- a/tests/Utils/ImageUtilsTest.php +++ b/tests/Utils/ImageUtilsTest.php @@ -19,10 +19,16 @@ require_once __DIR__ . '/../Autoloader.php'; use phpOMS\Utils\ImageUtils; /** + * @testdox phpOMS\tests\Utils\ImageUtilsTest: Image utilities + * * @internal */ class ImageUtilsTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox Base64 image data can be decoded to an image + * @covers phpOMS\Utils\ImageUtils + */ public function testImage() : void { self::assertEquals( diff --git a/tests/Utils/JsonBuilderTest.php b/tests/Utils/JsonBuilderTest.php deleted file mode 100644 index 26dd7ed41..000000000 --- a/tests/Utils/JsonBuilderTest.php +++ /dev/null @@ -1,51 +0,0 @@ -getJson()); - $builder->remove('test/path'); - self::assertEquals([], $builder->getJson()); - } - - public function testBuilder() : void - { - // main test is/should be done on ArrayUtils::setArray etc. - $builder = new JsonBuilder(); - $builder->add('a/test/path', 3); - self::assertEquals(['a' => ['test' => ['path' => 3]]], $builder->getJson()); - $builder->remove('a/test/path'); - self::assertEquals(['a' => ['test' => []]], $builder->getJson()); - - $arr = $builder->getJson(); - - self::assertEquals($arr, $builder->jsonSerialize()); - self::assertEquals(\json_encode($arr), $builder->serialize()); - - $builder->unserialize($builder->serialize()); - self::assertEquals($arr, $builder->getJson()); - } -} diff --git a/tests/Utils/NumericUtilsTest.php b/tests/Utils/NumericUtilsTest.php index 8c70268af..db0550cea 100644 --- a/tests/Utils/NumericUtilsTest.php +++ b/tests/Utils/NumericUtilsTest.php @@ -19,10 +19,16 @@ use phpOMS\Utils\NumericUtils; require_once __DIR__ . '/../Autoloader.php'; /** + * @testdox phpOMS\tests\Utils\NumericUtilsTest: Numeric utilities + * * @internal */ class NumericUtilsTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox Integers can be unsigned right shifted + * @covers phpOMS\Utils\NumericUtils + */ public function testShift() : void { self::assertEquals(10, NumericUtils::uRightShift(10, 0)); diff --git a/tests/Utils/Parser/Php/ArrayParserTest.php b/tests/Utils/Parser/Php/ArrayParserTest.php index 06e3245a9..b7bc360c1 100644 --- a/tests/Utils/Parser/Php/ArrayParserTest.php +++ b/tests/Utils/Parser/Php/ArrayParserTest.php @@ -17,10 +17,16 @@ namespace phpOMS\tests\Utils\Parser\Php; use phpOMS\Utils\Parser\Php\ArrayParser; /** + * @testdox phpOMS\tests\Utils\Parser\Php\ArrayParserTest: Array data serializer as code + * * @internal */ class ArrayParserTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox An array can be encoded and decoded as php code + * @covers phpOMS\Utils\Parser\Php\ArrayParser + */ public function testParser() : void { $serializable = new class() implements \Serializable { @@ -63,6 +69,10 @@ class ArrayParserTest extends \PHPUnit\Framework\TestCase self::assertEquals($expected, eval('return '. ArrayParser::serializeArray($array) . ';')); } + /** + * @testdox A value can be encoded and decoded into php code + * @covers phpOMS\Utils\Parser\Php\ArrayParser + */ public function testInvalidValueType() : void { self::expectException(\UnexpectedValueException::class); diff --git a/tests/Utils/PermutationTest.php b/tests/Utils/PermutationTest.php index 2e9b0b442..c131e5546 100644 --- a/tests/Utils/PermutationTest.php +++ b/tests/Utils/PermutationTest.php @@ -19,10 +19,16 @@ use phpOMS\Utils\Permutation; require_once __DIR__ . '/../Autoloader.php'; /** + * @testdox phpOMS\tests\Utils\PermutationTest: Permutation utilities + * * @internal */ class PermutationTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox An array can be permuted + * @covers phpOMS\Utils\Permutation + */ public function testPermute() : void { $arr = ['a', 'b', 'c']; @@ -33,12 +39,20 @@ class PermutationTest extends \PHPUnit\Framework\TestCase self::assertEquals($permutations2, Permutation::permut($arr, [], false)); } + /** + * @testdox Two string can be checked if they are a permutation of each other + * @covers phpOMS\Utils\Permutation + */ public function testIsPermutation() : void { self::assertTrue(Permutation::isPermutation('abc', 'bca')); self::assertFalse(Permutation::isPermutation('abc', 'bda')); } + /** + * @testdox A string can be checked if it is a palindrome + * @covers phpOMS\Utils\Permutation + */ public function testIsPalindrome() : void { self::assertTrue(Permutation::isPalindrome('abba')); @@ -46,11 +60,19 @@ class PermutationTest extends \PHPUnit\Framework\TestCase self::assertFalse(Permutation::isPalindrome('abb1a')); } + /** + * @testdox An array can be permutated with a permutation key + * @covers phpOMS\Utils\Permutation + */ public function testPermutate() : void { self::assertEquals(['c', 'b', 'a'], Permutation::permutate(['a', 'b', 'c'], [2, 1, 1])); } + /** + * @testdox A invalid permutation type throws a InvalidArgumentException + * @covers phpOMS\Utils\Permutation + */ public function testWrongPermuteParameterType() : void { self::expectException(\InvalidArgumentException::class); @@ -58,6 +80,10 @@ class PermutationTest extends \PHPUnit\Framework\TestCase Permutation::permutate(4, [2, 1, 1]); } + /** + * @testdox A none-existing permutation keye throws a OutOfBoundsException + * @covers phpOMS\Utils\Permutation + */ public function testWrongPermuteKeyLength() : void { self::expectException(\OutOfBoundsException::class); diff --git a/tests/Utils/RnG/ArrayRandomizeTest.php b/tests/Utils/RnG/ArrayRandomizeTest.php index eac1508e4..2943057c2 100644 --- a/tests/Utils/RnG/ArrayRandomizeTest.php +++ b/tests/Utils/RnG/ArrayRandomizeTest.php @@ -17,15 +17,45 @@ namespace phpOMS\tests\Utils\RnG; use phpOMS\Utils\RnG\ArrayRandomize; /** + * @testdox phpOMS\tests\Utils\RnG\ArrayRandomizeTest: Array randomizer + * * @internal */ class ArrayRandomizeTest extends \PHPUnit\Framework\TestCase { - public function testRandomize() : void + /** + * @testdox An array can be randomized using the yates algorithm + * @covers phpOMS\Utils\RnG\ArrayRandomize + */ + public function testYates() : void { $orig = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]; - self::assertNotEquals($orig, ArrayRandomize::yates($orig)); - self::assertNotEquals($orig, ArrayRandomize::knuth($orig)); + for ($i = 0; $i < 10; ++$i) { + if ($orig !== ArrayRandomize::yates($orig)) { + self::assertTrue(true); + return; + } + } + + self::assertTrue(false); + } + + /** + * @testdox An array can be randomized using the knuth algorithm + * @covers phpOMS\Utils\RnG\ArrayRandomize + */ + public function testKnuth() : void + { + $orig = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]; + + for ($i = 0; $i < 10; ++$i) { + if ($orig !== ArrayRandomize::knuth($orig)) { + self::assertTrue(true); + return; + } + } + + self::assertTrue(false); } } diff --git a/tests/Utils/RnG/DateTimeTest.php b/tests/Utils/RnG/DateTimeTest.php index 1b199e8e4..840ea9c2f 100644 --- a/tests/Utils/RnG/DateTimeTest.php +++ b/tests/Utils/RnG/DateTimeTest.php @@ -17,10 +17,16 @@ namespace phpOMS\tests\Utils\RnG; use phpOMS\Utils\RnG\DateTime; /** + * @testdox phpOMS\tests\Utils\RnG\DateTimeTest: Date time randomizer + * * @internal */ class DateTimeTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox A random date time can be generated + * @covers phpOMS\Utils\RnG\ArrayRandomize + */ public function testRnG() : void { for ($i = 0; $i < 100; ++$i) { diff --git a/tests/Utils/RnG/FileTest.php b/tests/Utils/RnG/FileTest.php index d7e793fed..59c477dfe 100644 --- a/tests/Utils/RnG/FileTest.php +++ b/tests/Utils/RnG/FileTest.php @@ -17,10 +17,16 @@ namespace phpOMS\tests\Utils\RnG; use phpOMS\Utils\RnG\File; /** + * @testdox phpOMS\tests\Utils\RnG\FileTest: File extension randomizer + * * @internal */ class FileTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox A random file extension can be generated + * @covers phpOMS\Utils\RnG\File + */ public function testRnGExtension() : void { self::assertRegExp('/^[a-z0-9]{1,5}$/', File::generateExtension()); diff --git a/tests/Utils/RnG/LinearCongruentialGeneratorTest.php b/tests/Utils/RnG/LinearCongruentialGeneratorTest.php index 2b859010e..d342fb8af 100644 --- a/tests/Utils/RnG/LinearCongruentialGeneratorTest.php +++ b/tests/Utils/RnG/LinearCongruentialGeneratorTest.php @@ -17,35 +17,64 @@ namespace phpOMS\tests\Utils\RnG; use phpOMS\Utils\RnG\LinearCongruentialGenerator; /** + * @testdox phpOMS\tests\Utils\RnG\LinearCongruentialGeneratorTest: Random number generator + * * @internal */ class LinearCongruentialGeneratorTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox The bsd random number generator starts with the correct sequence + * @covers phpOMS\Utils\RnG\LinearCongruentialGenerator + */ public function testBsdRng() : void { self::assertEquals(12345, LinearCongruentialGenerator::bsd()); + } - if (\PHP_INT_SIZE > 4) { - self::assertEquals(1406932606, LinearCongruentialGenerator::bsd()); - self::assertEquals(654583775, LinearCongruentialGenerator::bsd()); - self::assertEquals(1449466924, LinearCongruentialGenerator::bsd()); - } - + /** + * @testdox The same bsd seed generates the same random number + * @covers phpOMS\Utils\RnG\LinearCongruentialGenerator + */ + public function testBsdRngEqual() : void + { self::assertEquals(LinearCongruentialGenerator::bsd(1), LinearCongruentialGenerator::bsd(1)); + } + + /** + * @testdox Different bsd seeds generate different random numbers + * @covers phpOMS\Utils\RnG\LinearCongruentialGenerator + */ + public function testBsdRngNotEqual() : void + { self::assertNotEquals(LinearCongruentialGenerator::bsd(0), LinearCongruentialGenerator::bsd(1)); } + /** + * @testdox The msvcrt random number generator starts with the correct sequence + * @covers phpOMS\Utils\RnG\LinearCongruentialGenerator + */ public function testMsRng() : void { self::assertEquals(38, LinearCongruentialGenerator::msvcrt()); self::assertEquals(7719, LinearCongruentialGenerator::msvcrt()); + } - if (\PHP_INT_SIZE > 4) { - self::assertEquals(21238, LinearCongruentialGenerator::msvcrt()); - self::assertEquals(2437, LinearCongruentialGenerator::msvcrt()); - } - + /** + * @testdox The same msvcrt seed generates the same random number + * @covers phpOMS\Utils\RnG\LinearCongruentialGenerator + */ + public function testMsRngEqual() : void + { self::assertEquals(LinearCongruentialGenerator::msvcrt(1), LinearCongruentialGenerator::msvcrt(1)); + } + + /** + * @testdox Different msvcrt seeds generate different random numbers + * @covers phpOMS\Utils\RnG\LinearCongruentialGenerator + */ + public function testMsRngNotEqual() : void + { self::assertNotEquals(LinearCongruentialGenerator::msvcrt(0), LinearCongruentialGenerator::msvcrt(1)); } } diff --git a/tests/Utils/RnG/NameTest.php b/tests/Utils/RnG/NameTest.php index 062a3d448..681155684 100644 --- a/tests/Utils/RnG/NameTest.php +++ b/tests/Utils/RnG/NameTest.php @@ -17,10 +17,16 @@ namespace phpOMS\tests\Utils\RnG; use phpOMS\Utils\RnG\Name; /** + * @testdox phpOMS\tests\Utils\RnG\NameTest: Random name generator + * * @internal */ class NameTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox Random female and male names can be generated + * @covers phpOMS\Utils\RnG\Name + */ public function testRandom() : void { self::assertNotEquals(Name::generateName(['female']), Name::generateName(['male'])); diff --git a/tests/Utils/RnG/PhoneTest.php b/tests/Utils/RnG/PhoneTest.php index 9bdac1a33..84f9a5570 100644 --- a/tests/Utils/RnG/PhoneTest.php +++ b/tests/Utils/RnG/PhoneTest.php @@ -17,10 +17,16 @@ namespace phpOMS\tests\Utils\RnG; use phpOMS\Utils\RnG\Phone; /** + * @testdox phpOMS\tests\Utils\RnG\PhoneTest: Random phone number generator + * * @internal */ class PhoneTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox Random phone numbers can be generated + * @covers phpOMS\Utils\RnG\Phone + */ public function testRnG() : void { self::assertRegExp('/^\+\d{1,2} \(\d{3,4}\) \d{3,5}\-\d{3,8}$/', Phone::generatePhone()); diff --git a/tests/Utils/RnG/StringUtilsTest.php b/tests/Utils/RnG/StringUtilsTest.php index ac2fd0739..43d0ddf4a 100644 --- a/tests/Utils/RnG/StringUtilsTest.php +++ b/tests/Utils/RnG/StringUtilsTest.php @@ -17,11 +17,15 @@ namespace phpOMS\tests\Utils\RnG; use phpOMS\Utils\RnG\StringUtils; /** + * @testdox phpOMS\tests\Utils\RnG\StringUtilsTest: Random string generator + * * @internal */ class StringUtilsTest extends \PHPUnit\Framework\TestCase { /** + * @testdox Random strings can be generated + * @covers phpOMS\Utils\RnG\StringUtils * @slowThreshold 1500 */ public function testStrings() : void diff --git a/tests/Utils/RnG/TextTest.php b/tests/Utils/RnG/TextTest.php index ee0a52906..b2eae9025 100644 --- a/tests/Utils/RnG/TextTest.php +++ b/tests/Utils/RnG/TextTest.php @@ -17,10 +17,16 @@ namespace phpOMS\tests\Utils\RnG; use phpOMS\Utils\RnG\Text; /** + * @testdox phpOMS\tests\Utils\RnG\TextTest: Random text generator + * * @internal */ class TextTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox Random text can be generated + * @covers phpOMS\Utils\RnG\Text + */ public function testRnG() : void { $text = new Text(true, true); diff --git a/tests/Utils/StringCompareTest.php b/tests/Utils/StringCompareTest.php index 3d4af9dec..510b5117e 100644 --- a/tests/Utils/StringCompareTest.php +++ b/tests/Utils/StringCompareTest.php @@ -19,13 +19,17 @@ require_once __DIR__ . '/../Autoloader.php'; use phpOMS\Utils\StringCompare; /** + * @testdox phpOMS\tests\Utils\StringCompareTest: String comparison / dictionary + * * @internal */ class StringCompareTest extends \PHPUnit\Framework\TestCase { - public function testDictionary() : void + private StringCompare $dict; + + protected function setUp() : void { - $dict = new StringCompare( + $this->dict = new StringCompare( [ 'Table Airplane Snowflake', 'Football Pancake Doghouse Bathtub', @@ -43,14 +47,34 @@ class StringCompareTest extends \PHPUnit\Framework\TestCase 'Zebra Apple Magnet Sidewal', ] ); + } - self::assertEquals('Cartoon', $dict->matchDictionary('Cartoon')); - self::assertEquals('Bathtub Sidewalk Table', $dict->matchDictionary('Sidewalk Table')); + /** + * @testdox A string can be matched with a dictionary entry + * @covers phpOMS\Utils\StringCompare + */ + public function testDictionaryMatch() : void + { + self::assertEquals('Cartoon', $this->dict->matchDictionary('Carton')); + self::assertEquals('Bathtub Sidewalk Table', $this->dict->matchDictionary('Sidewalk Table')); + } - // too far apart - self::assertNotEquals('Snowflake Bathtub Snowflake Toothbrush Sidewalk', $dict->matchDictionary('Toothbrush')); + /** + * @testdox A string doesn't match a dictionary entry if it is very different + * @covers phpOMS\Utils\StringCompare + */ + public function testInvalidDictionary() : void + { + self::assertNotEquals('Snowflake Bathtub Snowflake Toothbrush Sidewalk', $this->dict->matchDictionary('Toothbrush')); + } - $dict->add('Carton'); - self::assertEquals('Carton', $dict->matchDictionary('carton')); + /** + * @testdox A new dictionary entry can be created and returned + * @covers phpOMS\Utils\StringCompare + */ + public function testDictionaryAdd() : void + { + $this->dict->add('Carton'); + self::assertEquals('Carton', $this->dict->matchDictionary('carton')); } } diff --git a/tests/Utils/StringUtilsTest.php b/tests/Utils/StringUtilsTest.php index c4c54b5e0..d29328b24 100644 --- a/tests/Utils/StringUtilsTest.php +++ b/tests/Utils/StringUtilsTest.php @@ -20,37 +20,89 @@ use phpOMS\Utils\StringUtils; require_once __DIR__ . '/../Autoloader.php'; /** + * @testdox phpOMS\tests\Utils\StringUtilsTest: String utilities + * * @internal */ class StringUtilsTest extends \PHPUnit\Framework\TestCase { - public function testEvaluation() : void + /** + * @testdox The entropy of a string can be calculated + * @covers phpOMS\Utils\StringUtils + */ + public function testEntropy() : void { self::assertTrue(\abs(2.5 - StringUtils::getEntropy('akj@!0aj')) < 0.1); } - public function testStartsEnds() : void + /** + * @testdox A string can be checked if it starts with a defined string + * @covers phpOMS\Utils\StringUtils + */ + public function testStarts() : void { $string = 'This is a test string.'; self::assertTrue(StringUtils::startsWith($string, 'This ')); self::assertFalse(StringUtils::startsWith($string, 'Thss ')); + } + + /** + * @testdox A string can be checked if it ends with a defined string + * @covers phpOMS\Utils\StringUtils + */ + public function testEnds() : void + { + $string = 'This is a test string.'; self::assertTrue(StringUtils::endsWith($string, 'string.')); self::assertFalse(StringUtils::endsWith($string, 'strng.')); + } + /** + * @testdox A multi-byte string can be checked if it starts with a defined string + * @covers phpOMS\Utils\StringUtils + */ + public function testStartsMb() : void + { + $string = 'This is a test string.'; self::assertTrue(StringUtils::mb_startsWith($string, 'This ')); self::assertFalse(StringUtils::mb_startsWith($string, 'Thss ')); + } + + /** + * @testdox A multi-byte string can be checked if it ends with a defined string + * @covers phpOMS\Utils\StringUtils + */ + public function testEndsMb() : void + { + $string = 'This is a test string.'; self::assertTrue(StringUtils::mb_endsWith($string, 'string.')); self::assertFalse(StringUtils::mb_endsWith($string, 'strng.')); } - public function testTransform() : void + /** + * @testdox The first character of a multi-byte string can be turned into upper case + * @covers phpOMS\Utils\StringUtils + */ + public function testTransformUpperCase() : void { self::assertEquals('This ', StringUtils::mb_ucfirst('this ')); self::assertNotEquals('this ', StringUtils::mb_ucfirst('this ')); + } + + /** + * @testdox The first character of a multi-byte string can be turned into lower case + * @covers phpOMS\Utils\StringUtils + */ + public function testTransformLowerCase() : void + { self::assertEquals('thss', StringUtils::mb_lcfirst('Thss')); self::assertNotEquals('Thss', StringUtils::mb_lcfirst('Thss')); } + /** + * @testdox A multi-byte string can be trimmed + * @covers phpOMS\Utils\StringUtils + */ public function testTrim() : void { $string = 'This is a test string.'; @@ -59,32 +111,75 @@ class StringUtilsTest extends \PHPUnit\Framework\TestCase self::assertEquals('This is a test string', StringUtils::mb_trim($string, '.')); self::assertEquals('asdf', StringUtils::mb_trim(' asdf ', ' ')); self::assertEquals('asdf', StringUtils::mb_trim('%asdf%', '%')); + } + /** + * @testdox A multi-byte string can be right-trimmed + * @covers phpOMS\Utils\StringUtils + */ + public function testRTrim() : void + { self::assertEquals(' asdf', StringUtils::mb_rtrim(' asdf ')); self::assertEquals('%asdf', StringUtils::mb_rtrim('%asdf%', '%')); + } + /** + * @testdox A multi-byte string can be left-trimmed + * @covers phpOMS\Utils\StringUtils + */ + public function testLTrim() : void + { self::assertEquals('asdf ', StringUtils::mb_ltrim(' asdf ')); self::assertEquals('asdf%', StringUtils::mb_ltrim('%asdf%', '%')); } + /** + * @testdox A string can be checked if it contains at least one defined string element + * @covers phpOMS\Utils\StringUtils + */ public function testContains() : void { $string = 'This is a test string.'; self::assertTrue(StringUtils::contains($string, ['is', 'nothing', 'string'])); self::assertFalse(StringUtils::contains($string, ['iss', 'nothing', 'false'])); + } + + /** + * @testdox A multi-byte string can be checked if it contains at least one defined string element + * @covers phpOMS\Utils\StringUtils + */ + public function testContainsMb() : void + { + $string = 'This is a test string.'; self::assertTrue(StringUtils::mb_contains($string, ['is', 'nothing', 'string'])); self::assertFalse(StringUtils::mb_contains($string, ['iss', 'nothing', 'false'])); } - public function testCount() : void + /** + * @testdox The characters of a multi-byte string can be counted + * @covers phpOMS\Utils\StringUtils + */ + public function testCountMb() : void { self::assertEquals(5, StringUtils::mb_count_chars('αααααΕεΙιΜμΨψ')['α']); + } + + /** + * @testdox The amount of a defined characters in the beginning of a string can be counted + * @covers phpOMS\Utils\StringUtils + */ + public function testCountBeginning() : void + { self::assertEquals(4, StringUtils::countCharacterFromStart(' Test string', ' ')); self::assertEquals(0, StringUtils::countCharacterFromStart(' Test string', 's')); } + /** + * @testdox Various data types can be stringified + * @covers phpOMS\Utils\StringUtils + */ public function testStringify() : void { self::assertEquals('"abc"', StringUtils::stringify(new class() implements \JsonSerializable { @@ -132,6 +227,10 @@ class StringUtilsTest extends \PHPUnit\Framework\TestCase })); } + /** + * @testdox The difference between two strings can be evaluated + * @covers phpOMS\Utils\StringUtils + */ public function testStringDiffHtml() : void { $original = 'This is a test string.'; diff --git a/tests/Utils/TaskSchedule/CronJobTest.php b/tests/Utils/TaskSchedule/CronJobTest.php index 52e094ca4..efa3000cd 100644 --- a/tests/Utils/TaskSchedule/CronJobTest.php +++ b/tests/Utils/TaskSchedule/CronJobTest.php @@ -17,12 +17,30 @@ namespace phpOMS\tests\Utils\TaskSchedule; use phpOMS\Utils\TaskSchedule\CronJob; /** + * @testdox phpOMS\tests\Utils\TaskSchedule\CronJobTest: Cron job + * * @internal */ class CronJobTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox The cron job has the expected default values after initialization + * @covers phpOMS\Utils\TaskSchedule\CronJob + */ public function testDefault() : void { - self::assertInstanceOf('\phpOMS\Utils\TaskSchedule\TaskAbstract', new CronJob('')); + $job = new CronJob(''); + self::assertEquals('', $job->__toString()); + self::assertInstanceOf('\phpOMS\Utils\TaskSchedule\TaskAbstract', $job); + } + + /** + * @testdox A cron job can be created from an array and rendered + * @covers phpOMS\Utils\TaskSchedule\CronJob + */ + public function testCreateJobWithData() : void + { + $job = CronJob::createWith(['testname', '*', '*', '*', '*', '*', 'testcmd']); + self::assertEquals('* * * * * testcmd # name="testname" ', $job->__toString()); } } diff --git a/tests/Utils/TaskSchedule/CronTest.php b/tests/Utils/TaskSchedule/CronTest.php index 385b47b7f..36099f497 100644 --- a/tests/Utils/TaskSchedule/CronTest.php +++ b/tests/Utils/TaskSchedule/CronTest.php @@ -18,31 +18,48 @@ use phpOMS\Utils\TaskSchedule\Cron; use phpOMS\Utils\TaskSchedule\CronJob; /** + * @testdox phpOMS\tests\Utils\TaskSchedule\CronTest: Cron handler + * * @internal */ class CronTest extends \PHPUnit\Framework\TestCase { - // * * * * * echo "test" > __DIR__ . '/cronjob.log' // evaluate dir - public function testDefault() : void - { - self::assertInstanceOf('\phpOMS\Utils\TaskSchedule\SchedulerAbstract', new Cron()); - } - - public function testCRUD() : void + protected function setUp() : void { if (\stripos(\PHP_OS, 'LINUX') === false) { $this->markTestSkipped( 'The OS is not linux.' ); } + } + // * * * * * echo "test" > __DIR__ . '/cronjob.log' // evaluate dir + /** + * @testdox The cron handler has the expected default values after initialization + * @covers phpOMS\Utils\TaskSchedule\Cron + */ + public function testDefault() : void + { + self::assertInstanceOf('\phpOMS\Utils\TaskSchedule\SchedulerAbstract', new Cron()); + } + /** + * @testdox The cron brinary location path can be guessed + * @covers phpOMS\Utils\TaskSchedule\Cron + */ + public function testGuessBinary() : void + { self::assertTrue(Cron::guessBin()); + } + + /** + * @testdox A cron job can be created and returned + * @covers phpOMS\Utils\TaskSchedule\Cron + */ + public function testCronJobInputOutput() : void + { $cron = new Cron(); - - self::assertEquals([], $cron->getAllByName('testCronJob', false)); - - $job = new CronJob('testCronJob', 'testFile', '0 0 1 1 *'); + $job = new CronJob('testCronJob', 'testFile', '0 0 1 1 *'); $cron->create($job); self::assertTrue(!empty($cron->getAllByName('testCronJob', false))); @@ -50,6 +67,29 @@ class CronTest extends \PHPUnit\Framework\TestCase self::assertEquals('testFile', $cron->getAllByName('testCronJob', false)[0]->getCommand()); } + $cron->delete($job); + } + + /** + * @testdox A none-existing cron name cannot be returned + * @covers phpOMS\Utils\TaskSchedule\Cron + */ + public function testInvalidCronJobName() : void + { + $cron = new Cron(); + self::assertEquals([], $cron->getAllByName('testCronJob', false)); + } + + /** + * @testdox A cron job can be updated + * @covers phpOMS\Utils\TaskSchedule\Cron + */ + public function testCronJobUpdate() : void + { + $cron = new Cron(); + $job = new CronJob('testCronJob', 'testFile', '0 0 1 1 *'); + $cron->create($job); + $job->setCommand('testFile2'); $cron->update($job); @@ -59,6 +99,20 @@ class CronTest extends \PHPUnit\Framework\TestCase } $cron->delete($job); + } + + /** + * @testdox A cron job can be deleted + * @covers phpOMS\Utils\TaskSchedule\Cron + */ + public function testDelete() : void + { + $cron = new Cron(); + $job = new CronJob('testCronJob', 'testFile', '0 0 1 1 *'); + $cron->create($job); + + self::assertTrue(!empty($cron->getAllByName('testCronJob', false))); + $cron->delete($job); self::assertEquals([], $cron->getAllByName('testCronJob', false)); } } diff --git a/tests/Utils/TaskSchedule/IntervalTest.php b/tests/Utils/TaskSchedule/IntervalTest.php index e23e415c8..770fab26e 100644 --- a/tests/Utils/TaskSchedule/IntervalTest.php +++ b/tests/Utils/TaskSchedule/IntervalTest.php @@ -17,10 +17,16 @@ namespace phpOMS\tests\Utils\TaskSchedule; use phpOMS\Utils\TaskSchedule\Interval; /** + * @testdox phpOMS\tests\Utils\TaskSchedule\IntervalTest: Cron interval + * * @internal */ class IntervalTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox The interval has the expected default values after initialization + * @covers phpOMS\Utils\TaskSchedule\Interval + */ public function testDefault() : void { $dt = new \DateTime('now'); @@ -48,20 +54,59 @@ class IntervalTest extends \PHPUnit\Framework\TestCase ); } - public function testSetGet() : void + /** + * @testdox The start date can be set during initialization and returned + * @covers phpOMS\Utils\TaskSchedule\Interval + */ + public function testConstructorInputOutput() : void + { + $interval = new Interval(new \DateTime('2001-11-25')); + self::assertEquals('2001-11-25', $interval->getStart()->format('Y-m-d')); + } + + /** + * @testdox The start date can set and returned + * @covers phpOMS\Utils\TaskSchedule\Interval + */ + public function testStartInputOutput() : void { $interval = new Interval(new \DateTime('2001-11-25')); - self::assertEquals('2001-11-25', $interval->getStart()->format('Y-m-d')); - $interval->setStart(new \DateTime('2015-08-14')); self::assertEquals('2015-08-14', $interval->getStart()->format('Y-m-d')); + } + + /** + * @testdox The end date can set and returned + * @covers phpOMS\Utils\TaskSchedule\Interval + */ + public function testEndInputOutput() : void + { + $interval = new Interval(new \DateTime('2001-11-25')); $interval->setEnd(new \DateTime('2018-10-30')); self::assertEquals('2018-10-30', $interval->getEnd()->format('Y-m-d')); + } + + /** + * @testdox The maximum execution duration can set and returned + * @covers phpOMS\Utils\TaskSchedule\Interval + */ + public function testMaxExecutionInputOutput() : void + { + $interval = new Interval(new \DateTime('2001-11-25')); $interval->setMaxDuration(30); self::assertEquals(30, $interval->getMaxDuration()); + } + + /** + * @testdox An execution minute can be added and returned + * @covers phpOMS\Utils\TaskSchedule\Interval + */ + public function testMinuteInputOutput() : void + { + $interval = new Interval(new \DateTime('2001-11-25')); $interval->addMinute(1, 3, 2); self::assertEquals([[ @@ -69,12 +114,32 @@ class IntervalTest extends \PHPUnit\Framework\TestCase 'end' => 3, 'step' => 2, ]], $interval->getMinute()); + } + + /** + * @testdox An execution minute can be overwritten + * @covers phpOMS\Utils\TaskSchedule\Interval + */ + public function testMinuteOverwriteInputOutput() : void + { + $interval = new Interval(new \DateTime('2001-11-25')); + + $interval->addMinute(1, 3, 2); $interval->setMinute(0, 4, 5, 6); self::assertEquals([[ 'start' => 4, 'end' => 5, 'step' => 6, ]], $interval->getMinute()); + } + + /** + * @testdox An execution hour can be added and returned + * @covers phpOMS\Utils\TaskSchedule\Interval + */ + public function testHourInputOutput() : void + { + $interval = new Interval(new \DateTime('2001-11-25')); $interval->addHour(1, 3, 2); self::assertEquals([[ @@ -82,12 +147,32 @@ class IntervalTest extends \PHPUnit\Framework\TestCase 'end' => 3, 'step' => 2, ]], $interval->getHour()); + } + + /** + * @testdox An execution hour can be overwritten + * @covers phpOMS\Utils\TaskSchedule\Interval + */ + public function testHourOverwriteInputOutput() : void + { + $interval = new Interval(new \DateTime('2001-11-25')); + + $interval->addHour(1, 3, 2); $interval->setHour(0, 4, 5, 6); self::assertEquals([[ 'start' => 4, 'end' => 5, 'step' => 6, ]], $interval->getHour()); + } + + /** + * @testdox An execution year can be added and returned + * @covers phpOMS\Utils\TaskSchedule\Interval + */ + public function testYearInputOutput() : void + { + $interval = new Interval(new \DateTime('2001-11-25')); $interval->addYear(1, 3, 2); self::assertEquals([[ @@ -95,12 +180,32 @@ class IntervalTest extends \PHPUnit\Framework\TestCase 'end' => 3, 'step' => 2, ]], $interval->getYear()); + } + + /** + * @testdox An execution year can be overwritten + * @covers phpOMS\Utils\TaskSchedule\Interval + */ + public function testYearOverwriteInputOutput() : void + { + $interval = new Interval(new \DateTime('2001-11-25')); + + $interval->addYear(1, 3, 2); $interval->setYear(0, 4, 5, 6); self::assertEquals([[ 'start' => 4, 'end' => 5, 'step' => 6, ]], $interval->getYear()); + } + + /** + * @testdox An execution day of month can be added and returned + * @covers phpOMS\Utils\TaskSchedule\Interval + */ + public function testDayOfMonthInputOutput() : void + { + $interval = new Interval(new \DateTime('2001-11-25')); $interval->addDayOfMonth(1, 3, 2); self::assertEquals([[ @@ -108,12 +213,32 @@ class IntervalTest extends \PHPUnit\Framework\TestCase 'end' => 3, 'step' => 2, ]], $interval->getDayOfMonth()); + } + + /** + * @testdox An execution day of month can be overwritten + * @covers phpOMS\Utils\TaskSchedule\Interval + */ + public function testDayOfMonthOverwriteInputOutput() : void + { + $interval = new Interval(new \DateTime('2001-11-25')); + + $interval->addDayOfMonth(1, 3, 2); $interval->setDayOfMonth(0, 4, 5, 6); self::assertEquals([[ 'start' => 4, 'end' => 5, 'step' => 6, ]], $interval->getDayOfMonth()); + } + + /** + * @testdox An execution day of week can be added and returned + * @covers phpOMS\Utils\TaskSchedule\Interval + */ + public function testDayOfWeekInputOutput() : void + { + $interval = new Interval(new \DateTime('2001-11-25')); $interval->addDayOfWeek(1, 3, 2); self::assertEquals([[ @@ -121,6 +246,17 @@ class IntervalTest extends \PHPUnit\Framework\TestCase 'end' => 3, 'step' => 2, ]], $interval->getDayOfWeek()); + } + + /** + * @testdox An execution day of week can be overwritten + * @covers phpOMS\Utils\TaskSchedule\Interval + */ + public function testDayOfWeekOverwriteInputOutput() : void + { + $interval = new Interval(new \DateTime('2001-11-25')); + + $interval->addDayOfWeek(1, 3, 2); $interval->setDayOfWeek(0, 4, 5, 6); self::assertEquals([[ 'start' => 4, @@ -129,6 +265,10 @@ class IntervalTest extends \PHPUnit\Framework\TestCase ]], $interval->getDayOfWeek()); } + /** + * @testdox A interval can be serialized + * @covers phpOMS\Utils\TaskSchedule\Interval + */ public function testSerialize() : void { $interval = new Interval(new \DateTime('2001-11-25')); @@ -154,6 +294,10 @@ class IntervalTest extends \PHPUnit\Framework\TestCase ]), $interval->serialize()); } + /** + * @testdox A serialized interval can be unserialized + * @covers phpOMS\Utils\TaskSchedule\Interval + */ public function testUnserialize() : void { $interval = new Interval(); diff --git a/tests/Utils/TaskSchedule/ScheduleTest.php b/tests/Utils/TaskSchedule/ScheduleTest.php index 9880ee6fb..d8e7a2791 100644 --- a/tests/Utils/TaskSchedule/ScheduleTest.php +++ b/tests/Utils/TaskSchedule/ScheduleTest.php @@ -17,12 +17,31 @@ namespace phpOMS\tests\Utils\TaskSchedule; use phpOMS\Utils\TaskSchedule\Schedule; /** + * @testdox phpOMS\tests\Utils\TaskSchedule\ScheduleTest: Schedule/task + * * @internal */ class ScheduleTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox The task has the expected default values after initialization + * @covers phpOMS\Utils\TaskSchedule\Schedule + */ public function testDefault() : void { - self::assertInstanceOf('\phpOMS\Utils\TaskSchedule\TaskAbstract', new Schedule('')); + $job = new Schedule(''); + self::assertEquals('', $job->__toString()); + self::assertInstanceOf('\phpOMS\Utils\TaskSchedule\TaskAbstract', $job); + } + + /** + * @testdox A task can be created from an array and rendered + * @covers phpOMS\Utils\TaskSchedule\Schedule + * @todo the interval has to be implemented! + */ + public function testCreateJobWithData() : void + { + $job = Schedule::createWith(['hostname', 'testname', '2018-06-02', 'Ready', 'Background', 'N/A', '1', '', 'testcmd', '/var/usr', 'comment']); + self::assertEquals('/tn testname asdf testcmd', $job->__toString()); } } diff --git a/tests/Utils/TaskSchedule/SchedulerAbstractTest.php b/tests/Utils/TaskSchedule/SchedulerAbstractTest.php index 68871130c..44f4a2aed 100644 --- a/tests/Utils/TaskSchedule/SchedulerAbstractTest.php +++ b/tests/Utils/TaskSchedule/SchedulerAbstractTest.php @@ -17,12 +17,27 @@ namespace phpOMS\tests\Utils\TaskSchedule; use phpOMS\Utils\TaskSchedule\SchedulerAbstract; /** + * @testdox phpOMS\tests\Utils\TaskSchedule\SchedulerAbstractTest: Scheduler abstraction + * * @internal */ class SchedulerAbstractTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox The scheduler has the expected default values after initialization + * @covers phpOMS\Utils\TaskSchedule\SchedulerAbstract + */ public function testDefault() : void { self::assertTrue(SchedulerAbstract::getBin() === '' || \file_exists(SchedulerAbstract::getBin())); } + + /** + * @testdox The scheduler brinary location path can be guessed + * @covers phpOMS\Utils\TaskSchedule\SchedulerAbstract + */ + public function testGuessBinary() : void + { + self::assertTrue(SchedulerAbstract::guessBin()); + } } diff --git a/tests/Utils/TaskSchedule/SchedulerFactoryTest.php b/tests/Utils/TaskSchedule/SchedulerFactoryTest.php index 0b3b29749..f4c93e0c2 100644 --- a/tests/Utils/TaskSchedule/SchedulerFactoryTest.php +++ b/tests/Utils/TaskSchedule/SchedulerFactoryTest.php @@ -19,13 +19,19 @@ use phpOMS\Utils\TaskSchedule\SchedulerFactory; use phpOMS\Utils\TaskSchedule\TaskScheduler; /** + * @testdox phpOMS\tests\Utils\TaskSchedule\SchedulerFactoryTest: Scheduler factory for creating cron/task handlers + * * @internal */ class SchedulerFactoryTest extends \PHPUnit\Framework\TestCase { - public function testFactory() : void + /** + * @testdox The correct schudeler is crated depending on the operating system + * @covers phpOMS\Utils\TaskSchedule\SchedulerAbstract + */ + public function testCreate() : void { - self::assertTrue((SchedulerFactory::create('') instanceof Cron) || (SchedulerFactory::create('') instanceof TaskScheduler)); + self::assertTrue((SchedulerFactory::create() instanceof Cron) || (SchedulerFactory::create() instanceof TaskScheduler)); // todo: make full test here by defining schtask or crontab path // todo: create task diff --git a/tests/Utils/TaskSchedule/TaskAbstractTest.php b/tests/Utils/TaskSchedule/TaskAbstractTest.php index 8e17d1179..00c57b5e8 100644 --- a/tests/Utils/TaskSchedule/TaskAbstractTest.php +++ b/tests/Utils/TaskSchedule/TaskAbstractTest.php @@ -17,6 +17,8 @@ namespace phpOMS\tests\Utils\TaskSchedule; use phpOMS\Utils\TaskSchedule\TaskAbstract; /** + * @testdox phpOMS\tests\Utils\TaskSchedule\TaskAbstractTest: Job/task abstraction + * * @internal */ class TaskAbstractTest extends \PHPUnit\Framework\TestCase @@ -38,6 +40,10 @@ class TaskAbstractTest extends \PHPUnit\Framework\TestCase }; } + /** + * @testdox The task abstraction has the expected default values after initialization + * @covers phpOMS\Utils\TaskSchedule\TaskAbstract + */ public function testDefault() : void { self::assertEquals('', $this->class->getId()); @@ -49,21 +55,54 @@ class TaskAbstractTest extends \PHPUnit\Framework\TestCase self::assertEquals('', $this->class->getInterval()); } - public function testGetSet() : void + /** + * @testdox The command can be set and returned + * @covers phpOMS\Utils\TaskSchedule\TaskAbstract + */ + public function testCommandInputOutput() : void { $this->class->setCommand('Command'); self::assertEquals('Command', $this->class->getCommand()); + } + /** + * @testdox The status can be set and returned + * @covers phpOMS\Utils\TaskSchedule\TaskAbstract + */ + public function testStatusInputOutput() : void + { $this->class->setStatus('Status'); self::assertEquals('Status', $this->class->getStatus()); + } + /** + * @testdox The comment can be set and returned + * @covers phpOMS\Utils\TaskSchedule\TaskAbstract + */ + public function testCommentInputOutput() : void + { $this->class->setComment('Comment'); self::assertEquals('Comment', $this->class->getComment()); + } + /** + * @testdox The last runtime can be set and returned + * @covers phpOMS\Utils\TaskSchedule\TaskAbstract + */ + public function testLastRuntimeInputOutput() : void + { $date = new \DateTime('now'); $this->class->setLastRuntime($date); self::assertEquals($date->format('Y-m-d'), $this->class->getLastRuntime()->format('Y-m-d')); + } + /** + * @testdox The next runtime can be set and returned + * @covers phpOMS\Utils\TaskSchedule\TaskAbstract + */ + public function testNextRuntimeInputOutput() : void + { + $date = new \DateTime('now'); $this->class->setNextRuntime($date); self::assertEquals($date->format('Y-m-d'), $this->class->getNextRuntime()->format('Y-m-d')); } diff --git a/tests/Utils/TaskSchedule/TaskFactoryTest.php b/tests/Utils/TaskSchedule/TaskFactoryTest.php index 71d514d1f..55f2acf3a 100644 --- a/tests/Utils/TaskSchedule/TaskFactoryTest.php +++ b/tests/Utils/TaskSchedule/TaskFactoryTest.php @@ -19,12 +19,18 @@ use phpOMS\Utils\TaskSchedule\Schedule; use phpOMS\Utils\TaskSchedule\TaskFactory; /** + * @testdox phpOMS\tests\Utils\TaskSchedule\TaskFactoryTest: Task factory for creating cron jobs/tasks + * * @internal */ class TaskFactoryTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox The correct task is crated depending on the operating system + * @covers phpOMS\Utils\TaskSchedule\TaskFactory + */ public function testFactory() : void { - self::assertTrue((TaskFactory::create('') instanceof CronJob) || (TaskFactory::create('') instanceof Schedule)); + self::assertTrue((TaskFactory::create() instanceof CronJob) || (TaskFactory::create() instanceof Schedule)); } } diff --git a/tests/Utils/TaskSchedule/TaskSchedulerTest.php b/tests/Utils/TaskSchedule/TaskSchedulerTest.php index ecd9003e5..360b66a4f 100644 --- a/tests/Utils/TaskSchedule/TaskSchedulerTest.php +++ b/tests/Utils/TaskSchedule/TaskSchedulerTest.php @@ -18,41 +18,100 @@ use phpOMS\Utils\TaskSchedule\Schedule; use phpOMS\Utils\TaskSchedule\TaskScheduler; /** + * @testdox phpOMS\tests\Utils\TaskSchedule\TaskSchedulerTest: Task schedule handler + * * @internal */ class TaskSchedulerTest extends \PHPUnit\Framework\TestCase { + protected function setUp() : void + { + if (\stripos(\PHP_OS, 'WIN') === false) { + $this->markTestSkipped( + 'The OS is not linux.' + ); + } + } + + /** + * @testdox The task handler has the expected default values after initialization + * @covers phpOMS\Utils\TaskSchedule\TaskScheduler + */ public function testDefault() : void { self::assertInstanceOf('\phpOMS\Utils\TaskSchedule\SchedulerAbstract', new TaskScheduler()); } - public function testCRUD() : void + /** + * @testdox The task brinary location path can be guessed + * @covers phpOMS\Utils\TaskSchedule\TaskScheduler + */ + public function testGuessBinary() : void { - if (\stristr(\PHP_OS, 'WIN')) { - self::assertTrue(TaskScheduler::guessBin()); - $cron = new TaskScheduler(); + self::assertTrue(TaskScheduler::guessBin()); + } - self::assertEquals([], $cron->getAllByName('testCronJob', false)); + /** + * @testdox A task can be created and returned + * @covers phpOMS\Utils\TaskSchedule\TaskScheduler + */ + public function testTaskScheduleInputOutput() : void + { + $task = new TaskScheduler(); + $job = new Schedule('testTaskSchedule', 'testFile', '0 0 1 1 *'); + $task->create($job); - $job = new Schedule('testCronJob', 'testFile', '0 0 1 1 *'); - $cron->create($job); - - self::assertTrue(!empty($cron->getAllByName('testCronJob', false))); - if (!empty($cron->getAllByName('testCronJob', false))) { - self::assertEquals('testFile', $cron->getAllByName('testCronJob', false)[0]->getCommand()); - } - - $job->setCommand('testFile2'); - $cron->update($job); - - self::assertTrue(!empty($cron->getAllByName('testCronJob', false))); - if (!empty($cron->getAllByName('testCronJob', false))) { - self::assertEquals('testFile2', $cron->getAllByName('testCronJob', false)[0]->getCommand()); - } - - $cron->delete($job); - self::assertEquals([], $cron->getAllByName('testCronJob', false)); + self::assertTrue(!empty($task->getAllByName('testTaskSchedule', false))); + if (!empty($task->getAllByName('testTaskSchedule', false))) { + self::assertEquals('testFile', $task->getAllByName('testTaskSchedule', false)[0]->getCommand()); } + + $task->delete($job); + } + + /** + * @testdox A none-existing task name cannot be returned + * @covers phpOMS\Utils\TaskSchedule\TaskScheduler + */ + public function testInvalidCronJobName() : void + { + $task = new TaskScheduler(); + self::assertEquals([], $task->getAllByName('testTaskSchedule', false)); + } + + /** + * @testdox A task can be updated + * @covers phpOMS\Utils\TaskSchedule\TaskScheduler + */ + public function testTaskScheduleUpdate() : void + { + $task = new TaskScheduler(); + $job = new Schedule('testTaskSchedule', 'testFile', '0 0 1 1 *'); + $task->create($job); + + $job->setCommand('testFile2'); + $task->update($job); + + self::assertTrue(!empty($task->getAllByName('testTaskSchedule', false))); + if (!empty($task->getAllByName('testTaskSchedule', false))) { + self::assertEquals('testFile2', $task->getAllByName('testTaskSchedule', false)[0]->getCommand()); + } + + $task->delete($job); + } + + /** + * @testdox A task can be deleted + * @covers phpOMS\Utils\TaskSchedule\TaskScheduler + */ + public function testDelete() : void + { + $task = new TaskScheduler(); + $job = new Schedule('testTaskSchedule', 'testFile', '0 0 1 1 *'); + $task->create($job); + + self::assertTrue(!empty($task->getAllByName('testTaskSchedule', false))); + $task->delete($job); + self::assertEquals([], $task->getAllByName('testTaskSchedule', false)); } } diff --git a/tests/Utils/TestUtilsTest.php b/tests/Utils/TestUtilsTest.php index 6d1ed2220..26a80b0f9 100644 --- a/tests/Utils/TestUtilsTest.php +++ b/tests/Utils/TestUtilsTest.php @@ -19,10 +19,16 @@ require_once __DIR__ . '/../Autoloader.php'; use phpOMS\Utils\TestUtils; /** + * @testdox phpOMS\tests\Utils\TestUtilsTest: Test utilities + * * @internal */ class TestUtilsTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox A member value can be returned + * @covers phpOMS\Utils\TestUtils + */ public function testGet() : void { $class = new TestUtilsClass(); @@ -31,11 +37,24 @@ class TestUtilsTest extends \PHPUnit\Framework\TestCase self::assertEquals(2, TestUtils::getMember($class, 'b')); self::assertEquals(3, TestUtils::getMember($class, 'c')); self::assertEquals('4', TestUtils::getMember($class, 'd')); + } + + /** + * @testdox Invalid member variable returns null + * @covers phpOMS\Utils\TestUtils + */ + public function testInvalidGet() : void + { + $class = new TestUtilsClass(); self::assertNull(TestUtils::getMember($class, 'e')); } - public function testSet() : void + /** + * @testdox A member value can be set and returned + * @covers phpOMS\Utils\TestUtils + */ + public function testInputOutput() : void { $class = new TestUtilsClass(); @@ -48,6 +67,15 @@ class TestUtilsTest extends \PHPUnit\Framework\TestCase self::assertEquals(5, TestUtils::getMember($class, 'b')); self::assertEquals(6, TestUtils::getMember($class, 'c')); self::assertEquals('7', TestUtils::getMember($class, 'd')); + } + + /** + * @testdox A none-existing member variable cannot be set + * @covers phpOMS\Utils\TestUtils + */ + public function testInputInputOutput() : void + { + $class = new TestUtilsClass(); self::assertFalse(TestUtils::setMember($class, 'e', 8)); } diff --git a/tests/Validation/Base/DateTimeTest.php b/tests/Validation/Base/DateTimeTest.php index 6ca01ad4a..0e73cd7a5 100644 --- a/tests/Validation/Base/DateTimeTest.php +++ b/tests/Validation/Base/DateTimeTest.php @@ -14,13 +14,21 @@ declare(strict_types=1); namespace phpOMS\tests\Validation\Base; +require_once __DIR__ . '/../../Autoloader.php'; + use phpOMS\Validation\Base\DateTime; /** + * @testdox phpOMS\tests\Validation\Base\DateTimeTest: Datetime validator + * * @internal */ class DateTimeTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox A date time string can be validated + * @covers phpOMS\Validation\Base\DateTime + */ public function testDateTime() : void { self::assertTrue(DateTime::isValid('now')); diff --git a/tests/Validation/Base/JsonTest.php b/tests/Validation/Base/JsonTest.php index fafdbba61..d09b10c7b 100644 --- a/tests/Validation/Base/JsonTest.php +++ b/tests/Validation/Base/JsonTest.php @@ -17,16 +17,26 @@ namespace phpOMS\tests\Validation\Base; use phpOMS\Validation\Base\Json; /** + * @testdox phpOMS\tests\Validation\Base\JsonTest: Json validator + * * @internal */ class JsonTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox A json string can be validated + * @covers phpOMS\Validation\Base\Json + */ public function testJson() : void { self::assertTrue(Json::isValid('{}')); self::assertFalse(Json::isValid('{')); } + /** + * @testdox A json string can be validated against a template definition + * @covers phpOMS\Validation\Base\Json + */ public function testJsonTemplate() : void { $template = \json_decode(\file_get_contents(__DIR__ . '/json/template.json'), true); @@ -34,13 +44,51 @@ class JsonTest extends \PHPUnit\Framework\TestCase $valid = \json_decode(\file_get_contents(__DIR__ . '/json/valid.json'), true); self::assertTrue(Json::validateTemplate($template, $valid)); self::assertTrue(Json::validateTemplate($template, $valid, true)); + } + + /** + * @testdox A json string can be validated against a template definition with additional data + * @covers phpOMS\Validation\Base\Json + */ + public function testJsonTemplateAdditional() : void + { + $template = \json_decode(\file_get_contents(__DIR__ . '/json/template.json'), true); $additional = \json_decode(\file_get_contents(__DIR__ . '/json/additional.json'), true); self::assertTrue(Json::validateTemplate($template, $additional)); + } + + /** + * @testdox A json string cannot be validated against a template definition with additional data if an exact match is enforced + * @covers phpOMS\Validation\Base\Json + */ + public function testJsonTemplateInvalidAdditional() : void + { + $template = \json_decode(\file_get_contents(__DIR__ . '/json/template.json'), true); + + $additional = \json_decode(\file_get_contents(__DIR__ . '/json/additional.json'), true); self::assertFalse(Json::validateTemplate($template, $additional, true)); + } + + /** + * @testdox A json string cannot be validated against a template definition with missing data if an exact match is enforced + * @covers phpOMS\Validation\Base\Json + */ + public function testJsonTemplateInvalidMissing() : void + { + $template = \json_decode(\file_get_contents(__DIR__ . '/json/template.json'), true); $incomplete = \json_decode(\file_get_contents(__DIR__ . '/json/incomplete.json'), true); self::assertFalse(Json::validateTemplate($template, $incomplete)); + } + + /** + * @testdox A json string cannot be validated against a template definition if it doesn't match the template + * @covers phpOMS\Validation\Base\Json + */ + public function testInvalidJsonTemplate() : void + { + $template = \json_decode(\file_get_contents(__DIR__ . '/json/template.json'), true); $invalid = \json_decode(\file_get_contents(__DIR__ . '/json/invalid.json'), true); self::assertFalse(Json::validateTemplate($template, $invalid)); diff --git a/tests/Validation/Finance/BICTest.php b/tests/Validation/Finance/BICTest.php index ff263f7ad..444d56989 100644 --- a/tests/Validation/Finance/BICTest.php +++ b/tests/Validation/Finance/BICTest.php @@ -17,10 +17,16 @@ namespace phpOMS\tests\Validation\Finance; use phpOMS\Validation\Finance\BIC; /** + * @testdox phpOMS\tests\Validation\Finance\BICTest: BIC validator + * * @internal */ class BICTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox A BIC can be validated + * @covers phpOMS\Validation\Finance\BIC + */ public function testBic() : void { self::assertTrue(BIC::isValid('ASPKAT2LXXX')); diff --git a/tests/Validation/Finance/CreditCardTest.php b/tests/Validation/Finance/CreditCardTest.php index 45e2b73ef..f59d9ef83 100644 --- a/tests/Validation/Finance/CreditCardTest.php +++ b/tests/Validation/Finance/CreditCardTest.php @@ -17,10 +17,16 @@ namespace phpOMS\tests\Validation\Finance; use phpOMS\Validation\Finance\CreditCard; /** + * @testdox phpOMS\tests\Validation\Finance\CreditCardTest: Credit card validator + * * @internal */ class CreditCardTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox A credit card can be validated + * @covers phpOMS\Validation\Finance\CreditCard + */ public function testCreditCard() : void { self::assertTrue(CreditCard::isValid('4242424242424242')); @@ -31,6 +37,10 @@ class CreditCardTest extends \PHPUnit\Framework\TestCase self::assertFalse(CreditCard::luhnTest('4242424242424241')); } + /** + * @testdox A invalid type cannot be validated + * @covers phpOMS\Validation\Finance\CreditCard + */ public function testInvalidCreditCardType() : void { self::assertFalse(CreditCard::isValid(12347)); diff --git a/tests/Validation/Finance/IbanErrorTypeTest.php b/tests/Validation/Finance/IbanErrorTypeTest.php index de8394e5e..c380a1eb4 100644 --- a/tests/Validation/Finance/IbanErrorTypeTest.php +++ b/tests/Validation/Finance/IbanErrorTypeTest.php @@ -29,6 +29,14 @@ class IbanErrorTypeTest extends \PHPUnit\Framework\TestCase self::assertCount(5, IbanErrorType::getConstants()); } + /** + * @coversNothing + */ + public function testUnique() : void + { + self::assertEquals(IbanErrorType::getConstants(), \array_unique(IbanErrorType::getConstants())); + } + /** * @coversNothing */ diff --git a/tests/Validation/Finance/IbanTest.php b/tests/Validation/Finance/IbanTest.php index 0e88d165b..18ae158b8 100644 --- a/tests/Validation/Finance/IbanTest.php +++ b/tests/Validation/Finance/IbanTest.php @@ -17,10 +17,16 @@ namespace phpOMS\tests\Validation\Finance; use phpOMS\Validation\Finance\Iban; /** + * @testdox phpOMS\tests\Validation\Finance\IbanTest: Iban validator + * * @internal */ class IbanTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox A iban can be validated + * @covers phpOMS\Validation\Finance\Iban + */ public function testValid() : void { self::assertTrue(Iban::isValid('DE22 6008 0000 0960 0280 00')); diff --git a/tests/Validation/Network/EmailTest.php b/tests/Validation/Network/EmailTest.php index 77fb568a8..cdfccb259 100644 --- a/tests/Validation/Network/EmailTest.php +++ b/tests/Validation/Network/EmailTest.php @@ -17,10 +17,16 @@ namespace phpOMS\tests\Validation\Network; use phpOMS\Validation\Network\Email; /** + * @testdox phpOMS\tests\Validation\Network\EmailTest: Email validator + * * @internal */ class EmailTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox A email can be validated + * @covers phpOMS\Validation\Network\Email + */ public function testValidation() : void { self::assertTrue(Email::isValid('test.string@email.com')); diff --git a/tests/Validation/Network/HostnameTest.php b/tests/Validation/Network/HostnameTest.php index 3c915e76b..acbe7ddec 100644 --- a/tests/Validation/Network/HostnameTest.php +++ b/tests/Validation/Network/HostnameTest.php @@ -17,10 +17,16 @@ namespace phpOMS\tests\Validation\Network; use phpOMS\Validation\Network\Hostname; /** + * @testdox phpOMS\tests\Validation\Network\HostnameTest: Hostname validator + * * @internal */ class HostnameTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox A hostname can be validated + * @covers phpOMS\Validation\Network\Hostname + */ public function testHostname() : void { self::assertTrue(Hostname::isValid('test.com')); diff --git a/tests/Validation/Network/IpTest.php b/tests/Validation/Network/IpTest.php index b563a8cd7..cf00d0f15 100644 --- a/tests/Validation/Network/IpTest.php +++ b/tests/Validation/Network/IpTest.php @@ -17,21 +17,41 @@ namespace phpOMS\tests\Validation\Network; use phpOMS\Validation\Network\Ip; /** + * @testdox phpOMS\tests\Validation\Network\IpTest: IP validator + * * @internal */ class IpTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox A ip can be validated + * @covers phpOMS\Validation\Network\Ip + */ public function testValid() : void { self::assertTrue(IP::isValid('192.168.178.1')); self::assertTrue(IP::isValid('2001:0db8:85a3:0000:0000:8a2e:0370:7334')); self::assertFalse(IP::isValid('192.168.178.257')); self::assertFalse(IP::isValid('localhost')); + } - self::assertFalse(IP::isValidIpv6('192.168.178.1')); - self::assertTrue(IP::isValidIpv6('2001:0db8:85a3:0000:0000:8a2e:0370:7334')); - + /** + * @testdox A ip4 can be validated + * @covers phpOMS\Validation\Network\Ip + */ + public function testValidIp4() : void + { self::assertTrue(IP::isValidIpv4('192.168.178.1')); self::assertFalse(IP::isValidIpv4('2001:0db8:85a3:0000:0000:8a2e:0370:7334')); } + + /** + * @testdox A ip6 can be validated + * @covers phpOMS\Validation\Network\Ip + */ + public function testValidIp6() : void + { + self::assertFalse(IP::isValidIpv6('192.168.178.1')); + self::assertTrue(IP::isValidIpv6('2001:0db8:85a3:0000:0000:8a2e:0370:7334')); + } } diff --git a/tests/Validation/ValidatorTest.php b/tests/Validation/ValidatorTest.php index 21f37520b..eb2068608 100644 --- a/tests/Validation/ValidatorTest.php +++ b/tests/Validation/ValidatorTest.php @@ -20,35 +20,83 @@ use phpOMS\Validation\Validator; require_once __DIR__ . '/../Autoloader.php'; /** + * @testdox phpOMS\tests\Validation\ValidatorTest: General validator + * * @internal */ class ValidatorTest extends \PHPUnit\Framework\TestCase { - public function testValidation() : void + /** + * @testdox A string can be checked if it contains a substring + * @covers phpOMS\Validation\Validator + */ + public function testValidationContains() : void { self::assertTrue(Validator::contains('Test string contains something.', 'contains')); self::assertFalse(Validator::contains('Test string contains something.', 'contains2')); + } + /** + * @testdox A string can be checked if it has a certain length + * @covers phpOMS\Validation\Validator + */ + public function testValidationLength() : void + { self::assertTrue(Validator::hasLength('Test string contains something.')); self::assertTrue(Validator::hasLength('Test string contains something.', 10, 100)); self::assertFalse(Validator::hasLength('Test string contains something.', 100, 1000)); + } + /** + * @testdox A value can be checked if it is in range + * @covers phpOMS\Validation\Validator + */ + public function testValidationLimit() : void + { self::assertTrue(Validator::hasLimit(1.23, 1.0, 2.0)); self::assertTrue(Validator::hasLimit(1, 0, 2)); self::assertFalse(Validator::hasLimit(3.0, 0, 2)); + } + /** + * @testdox A value can be checked to be of a defined type + * @covers phpOMS\Validation\Validator + */ + public function testValidationType() : void + { self::assertTrue(Validator::isType(new FileLogger(__DIR__), '\phpOMS\Log\FileLogger')); self::assertFalse(Validator::isType(new FileLogger(__DIR__), '\some\namespace')); + } + /** + * @testdox The error message and error code have the expected default values + * @covers phpOMS\Validation\Validator + */ + public function testValidationError() : void + { Validator::resetError(); self::assertEquals('', Validator::getMessage()); self::assertEquals(0, Validator::getErrorCode()); + } + /** + * @testdox Custom validators can be specified in order to validate a value + * @covers phpOMS\Validation\Validator + */ + public function testValidators() : void + { self::assertTrue(Validator::isValid('testVar')); self::assertTrue(Validator::isValid('value', ['\is_string' => []])); self::assertFalse(Validator::isValid('value', ['\is_stringNot' => []])); self::assertTrue(Validator::isValid('value', ['phpOMS\Validation\Validator::hasLength' => [4]])); + } + /** + * @testdox A value can be checked to match a regular expression + * @covers phpOMS\Validation\Validator + */ + public function testMatching() : void + { self::assertTrue(Validator::matches('ThisTestVar', '/.*/')); self::assertFalse(Validator::matches('ThisTestVar', '/.*\d+/')); self::assertTrue(Validator::matches('ThisTestVar', '/TestVar/')); diff --git a/tests/Version/VersionTest.php b/tests/Version/VersionTest.php index 2b13ab67c..1b203a092 100644 --- a/tests/Version/VersionTest.php +++ b/tests/Version/VersionTest.php @@ -19,10 +19,16 @@ use phpOMS\Version\Version; require_once __DIR__ . '/../Autoloader.php'; /** + * @testdox phpOMS\tests\Version\VersionTest: Version handler + * * @internal */ class VersionTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox Versions can be compared with each other + * @covers phpOMS\Version\Version + */ public function testVersionCompare() : void { $version1 = '1.23.456'; diff --git a/tests/Views/PaginationViewTest.php b/tests/Views/PaginationViewTest.php index 9c7d75305..5047ad43c 100644 --- a/tests/Views/PaginationViewTest.php +++ b/tests/Views/PaginationViewTest.php @@ -19,10 +19,16 @@ require_once __DIR__ . '/../Autoloader.php'; use phpOMS\Views\PaginationView; /** + * @testdox phpOMS\tests\Views\PaginationViewTest: View for pagination + * * @internal */ class PaginationViewTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox The pagination view has the expected default values after initialization + * @covers phpOMS\Views\PaginationView + */ public function testDefault() : void { $view = new PaginationView(); @@ -32,18 +38,49 @@ class PaginationViewTest extends \PHPUnit\Framework\TestCase self::assertEquals(0, $view->getResults()); } - public function testGetSet() : void + /** + * @testdox The max pages can be set and returned + * @covers phpOMS\Views\PaginationView + */ + public function testMaxPagesInputOutput() : void { $view = new PaginationView(); $view->setMaxPages(9); self::assertEquals(9, $view->getMaxPages()); + } + + /** + * @testdox The pages can be set and returned + * @covers phpOMS\Views\PaginationView + */ + public function testPagesInputOutput() : void + { + $view = new PaginationView(); $view->setPages(2); self::assertEquals(2, $view->getPages()); + } + + /** + * @testdox The page can be set and returned + * @covers phpOMS\Views\PaginationView + */ + public function testPageInputOutput() : void + { + $view = new PaginationView(); $view->setPage(3); self::assertEquals(3, $view->getPage()); + } + + /** + * @testdox The results can be set and returned + * @covers phpOMS\Views\PaginationView + */ + public function testResultsInputOutput() : void + { + $view = new PaginationView(); $view->setResults(12); self::assertEquals(12, $view->getResults()); diff --git a/tests/Views/ViewTest.php b/tests/Views/ViewTest.php index e0317e975..ecf1a4689 100644 --- a/tests/Views/ViewTest.php +++ b/tests/Views/ViewTest.php @@ -27,13 +27,15 @@ use phpOMS\Views\View; use phpOMS\Views\ViewAbstract; /** + * @testdox phpOMS\tests\Views\ViewTest: View for response rendering + * * @internal */ class ViewTest extends \PHPUnit\Framework\TestCase { - protected $dbPool = null; + protected DatabasePool $dbPool; - protected $app = null; + protected ApplicationAbstract $app; protected function setUp() : void { @@ -50,6 +52,10 @@ class ViewTest extends \PHPUnit\Framework\TestCase $this->app->dbPool = $this->dbPool; } + /** + * @testdox The view has the expected default values after initialization + * @covers phpOMS\Views\View + */ public function testDefault() : void { $view = new View($this->app, new Request(new Http('')), new Response(new Localization())); @@ -64,6 +70,10 @@ class ViewTest extends \PHPUnit\Framework\TestCase self::assertEmpty($view->toArray()); } + /** + * @testdox The view can output text from the localization manager + * @covers phpOMS\Views\View + */ public function testGetText() : void { $view = new View($this->app, $request = new Request(new Http('')), $response = new Response()); @@ -81,49 +91,205 @@ class ViewTest extends \PHPUnit\Framework\TestCase $this->app->l11nManager->loadLanguage('en', 'Admin', $expected['en']); self::assertEquals('Test', $view->getText('Test')); + } + + /** + * @testdox The view can output html escaped text from the localization manager + * @covers phpOMS\Views\View + */ + public function testGetHtml() : void + { + $view = new View($this->app, $request = new Request(new Http('')), $response = new Response()); + $view->setTemplate('/Modules/Admin/Theme/Backend/accounts-list'); + + $expected = [ + 'en' => [ + 'Admin' => [ + 'Test' => 'Test', + ], + ], + ]; + + $this->app->l11nManager = new L11nManager('Api'); + $this->app->l11nManager->loadLanguage('en', 'Admin', $expected['en']); + self::assertEquals('<a href="test">Test</a>', $view->getHtml('Test')); } - public function testGetSet() : void + /** + * @testdox View data can be set and returned + * @covers phpOMS\Views\View + */ + public function testDataInputOutput() : void { $view = new View($this->app, $request = new Request(new Http('')), $response = new Response()); $view->setData('key', 'value'); self::assertEquals('value', $view->getData('key')); + } + + /** + * @testdox View data can be added and returned + * @covers phpOMS\Views\View + */ + public function testDataAdd() : void + { + $view = new View($this->app, $request = new Request(new Http('')), $response = new Response()); self::assertTrue($view->addData('key2', 'valu2')); + self::assertEquals('valu2', $view->getData('key2')); + } + + /** + * @testdox View data cannot be added if it already exists + * @covers phpOMS\Views\View + */ + public function testInvalidDataOverwrite() : void + { + $view = new View($this->app, $request = new Request(new Http('')), $response = new Response()); + + $view->addData('key2', 'valu2'); self::assertFalse($view->addData('key2', 'valu3')); self::assertEquals('valu2', $view->getData('key2')); + } + /** + * @testdox View data can be removed + * @covers phpOMS\Views\View + */ + public function testRemove() : void + { + $view = new View($this->app, $request = new Request(new Http('')), $response = new Response()); + + $view->addData('key2', 'valu2'); self::assertTrue($view->removeData('key2')); + } + + /** + * @testdox None-existing view data cannot be removed + * @covers phpOMS\Views\View + */ + public function testInvalidDataRemove() : void + { + $view = new View($this->app, $request = new Request(new Http('')), $response = new Response()); + self::assertFalse($view->removeData('key3')); + } + + /** + * @testdox The request can be returned + * @covers phpOMS\Views\View + */ + public function testGetRequest() : void + { + $view = new View($this->app, $request = new Request(new Http('')), $response = new Response()); self::assertEquals($request, $view->getRequest()); self::assertEquals($response, $view->getResponse()); + } + + /** + * @testdox The response can be returned + * @covers phpOMS\Views\View + */ + public function testGetResponse() : void + { + $view = new View($this->app, $request = new Request(new Http('')), $response = new Response()); + + self::assertEquals($response, $view->getResponse()); + } + + /** + * @testdox Text can be html escaped + * @covers phpOMS\Views\View + */ + public function testPrintHtml() : void + { + $view = new View($this->app, $request = new Request(new Http('')), $response = new Response()); self::assertEquals('<a href="test">Test</a>', $view->printHtml('Test')); self::assertEquals('<a href="test">Test</a>', ViewAbstract::html('Test')); + } + + /** + * @testdox Views can be added and returned from a view + * @covers phpOMS\Views\View + */ + public function testViewInputOutput() : void + { + $view = new View($this->app, $request = new Request(new Http('')), $response = new Response()); $tView = new View($this->app, $request, $response); self::assertTrue($view->addView('test', $tView)); self::assertEquals($tView, $view->getView('test')); self::assertCount(1, $view->getViews()); - self::assertTrue($view->removeView('test')); - self::assertFalse($view->removeView('test')); - self::assertFalse($view->getView('test')); } + /** + * @testdox None-existing views cannot be returned + * @covers phpOMS\Views\View + */ + public function testInvalidViewGet() : void + { + $view = new View($this->app, $request = new Request(new Http('')), $response = new Response()); + + self::assertEquals(false, $view->getView('test')); + } + + /** + * @testdox Views can be removed + * @covers phpOMS\Views\View + */ + public function testViewRemove() : void + { + $view = new View($this->app, $request = new Request(new Http('')), $response = new Response()); + + $tView = new View($this->app, $request, $response); + $view->addView('test', $tView); + self::assertTrue($view->removeView('test')); + } + + /** + * @testdox None-existing views cannot be removed + * @covers phpOMS\Views\View + */ + public function testInvalidViewRemove() : void + { + $view = new View($this->app, $request = new Request(new Http('')), $response = new Response()); + + self::assertFalse($view->removeView('test')); + } + + /** + * @testdox A view can be forcefully overwritten + * @covers phpOMS\Views\View + */ public function testOverwritingView() : void { $view = new View(); $tView = new View(); - self::assertTrue($view->addView('test', $tView)); + $view->addView('test', $tView); self::assertTrue($view->addView('test', $tView, true)); - self::assertFalse($view->addView('test', $tView)); - self::assertFalse($view->addView('test', $tView, false)); } + /** + * @testdox By default a view is not overwritten + * @covers phpOMS\Views\View + */ + public function testInvalidOverwritingView() : void + { + $view = new View(); + $tView = new View(); + + $view->addView('test', $tView); + self::assertFalse($view->addView('test', $tView)); + } + + /** + * @testdox A view template can be rendered + * @covers phpOMS\Views\View + */ public function testRender() : void { $view = new View(); @@ -132,6 +298,10 @@ class ViewTest extends \PHPUnit\Framework\TestCase self::assertEquals('Test', $view->render()); } + /** + * @testdox A view template can be serialized + * @covers phpOMS\Views\View + */ public function testSerialize() : void { $view = new View(); @@ -141,6 +311,10 @@ class ViewTest extends \PHPUnit\Framework\TestCase self::assertEquals('Test', $view->serialize()); } + /** + * @testdox A view can be turned into an array containing the rendered templates + * @covers phpOMS\Views\View + */ public function testArray() : void { $view = new View(); @@ -160,6 +334,10 @@ class ViewTest extends \PHPUnit\Framework\TestCase ); } + /** + * @testdox Rendering a invalid template throws a PathException + * @covers phpOMS\Views\View + */ public function testRenderException() : void { self::expectException(\phpOMS\System\File\PathException::class); @@ -170,6 +348,10 @@ class ViewTest extends \PHPUnit\Framework\TestCase $view->render(); } + /** + * @testdox Serializing a invalid template throws a PathException + * @covers phpOMS\Views\View + */ public function testSerializeException() : void { self::expectException(\phpOMS\System\File\PathException::class);