diff --git a/Algorithm/PathFinding/Path.php b/Algorithm/PathFinding/Path.php index 983d74418..b72cae87d 100644 --- a/Algorithm/PathFinding/Path.php +++ b/Algorithm/PathFinding/Path.php @@ -83,7 +83,7 @@ class Path } /** - * Get the path length + * Get the path length (euclidean) * * @return float * @@ -183,12 +183,12 @@ class Path $line = []; while (true) { - $line[] = $node; - if ($node->getX() === $node2->getX() && $node->getY() === $node2->getY()) { break; } + $line[] = $node; + $e2 = 2 * $err; if ($e2 > -$dy) { diff --git a/Business/Finance/FinanceFormulas.php b/Business/Finance/FinanceFormulas.php index efa8f0c3b..88c21818f 100644 --- a/Business/Finance/FinanceFormulas.php +++ b/Business/Finance/FinanceFormulas.php @@ -1094,7 +1094,7 @@ final class FinanceFormulas $count = \count($C); if ($count === 0) { - throw new \UnexpectedValueException((string) $count); + return 0.0; } $npv = -$C[0]; diff --git a/DataStorage/Cache/Connection/FileCache.php b/DataStorage/Cache/Connection/FileCache.php index aa7e5f0b0..b7cc4ca64 100644 --- a/DataStorage/Cache/Connection/FileCache.php +++ b/DataStorage/Cache/Connection/FileCache.php @@ -313,7 +313,7 @@ class FileCache extends ConnectionAbstract $cacheExpire = \substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1)); $cacheExpire = ($cacheExpire === -1) ? $created : (int) $cacheExpire; - if ($cacheExpire >= 0 && $created + $cacheExpire < $now) { + if ($cacheExpire >= 0 && $created + $cacheExpire + ($expire > 0 ? $expire : 0) < $now) { $this->delete($key); return null; diff --git a/DataStorage/Cookie/CookieJar.php b/DataStorage/Cookie/CookieJar.php index 9d8bdd2cb..77938c66a 100644 --- a/DataStorage/Cookie/CookieJar.php +++ b/DataStorage/Cookie/CookieJar.php @@ -143,6 +143,7 @@ final class CookieJar throw new LockException('CookieJar'); } + // @codeCoverageIgnoreStart if (!\headers_sent()) { \setcookie($id, '', \time() - 3600); @@ -150,6 +151,7 @@ final class CookieJar } return false; + // @codeCoverageIgnoreEnd } return false; @@ -190,8 +192,10 @@ final class CookieJar throw new LockException('CookieJar'); } + // @codeCoverageIgnoreStart foreach ($this->cookies as $key => $cookie) { \setcookie($key, $cookie['value'], $cookie['expiry'], $cookie['path'], $cookie['domain'], $cookie['secure'], $cookie['httponly']); } + // @codeCoverageIgnoreEnd } } diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index b260237e0..a1c0b5893 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -492,6 +492,7 @@ class DataMapperAbstract implements DataMapperInterface // @todo: remove after debugging // @fix: really remove it // @critical: after we found the bug we MUST remove it! + var_dump($t->getMessage()); var_dump($query->toSql()); } @@ -941,7 +942,12 @@ class DataMapperAbstract implements DataMapperInterface $relQuery->values($src, $objId); } - self::$db->con->prepare($relQuery->toSql())->execute(); + try { + self::$db->con->prepare($relQuery->toSql())->execute(); + } catch (\Throwable $e) { + var_dump($e->getMessage()); + var_dump($relQuery->toSql()); + } } } diff --git a/DataStorage/Session/HttpSession.php b/DataStorage/Session/HttpSession.php index d111cdbb8..e0e78903a 100644 --- a/DataStorage/Session/HttpSession.php +++ b/DataStorage/Session/HttpSession.php @@ -77,7 +77,7 @@ class HttpSession implements SessionInterface public function __construct(int $liftetime = 3600, $sid = false, int $inactivityInterval = 0) { if (\session_id()) { - \session_write_close(); + \session_write_close(); // @codeCoverageIgnore } if (!\is_bool($sid)) { @@ -87,12 +87,12 @@ class HttpSession implements SessionInterface $this->inactivityInterval = $inactivityInterval; if (\session_status() !== \PHP_SESSION_ACTIVE && !\headers_sent()) { - \session_set_cookie_params($liftetime, '/', '', false, true); - \session_start(); + \session_set_cookie_params($liftetime, '/', '', false, true); // @codeCoverageIgnore + \session_start(); // @codeCoverageIgnore } if ($this->inactivityInterval > 0 && ($this->inactivityInterval + ($_SESSION['lastActivity'] ?? 0) < \time())) { - $this->destroy(); + $this->destroy(); // @codeCoverageIgnore } $this->sessionData = $_SESSION ?? []; @@ -211,6 +211,7 @@ class HttpSession implements SessionInterface * @return void * * @since 1.0.0 + * @codeCoverageIgnore */ private function destroy() : void { diff --git a/Module/PackageManager.php b/Module/PackageManager.php index 8c32655eb..9210544d4 100644 --- a/Module/PackageManager.php +++ b/Module/PackageManager.php @@ -102,7 +102,7 @@ final class PackageManager */ public function extract(string $path) : void { - $this->extractPath = $path; + $this->extractPath = \rtrim($path, '\\/'); Zip::unpack($this->path, $this->extractPath); } @@ -135,6 +135,10 @@ final class PackageManager */ public function isValid() : bool { + if (!\file_exists($this->extractPath . '/package.cert')) { + return false; + } + $contents = \file_get_contents($this->extractPath . '/package.cert'); return $this->authenticate($contents === false ? '' : $contents, $this->hashFiles()); } @@ -184,7 +188,7 @@ final class PackageManager foreach ($this->info['update'] as $steps) { foreach ($steps as $key => $components) { - if (\function_exists($this->{$key})) { + if (\method_exists($this, $key)) { $this->{$key}($components); } } @@ -206,8 +210,8 @@ final class PackageManager $fp = \fopen($this->basePath . '/' . $to, 'w+'); $ch = \curl_init(\str_replace(' ','%20', $from)); - if ($ch === false) { - continue; + if ($ch === false || $fp === false) { + continue; // @codeCoverageIgnore } \curl_setopt($ch, \CURLOPT_TIMEOUT, 50); @@ -233,10 +237,10 @@ final class PackageManager private function move(array $components) : void { foreach ($components as $from => $to) { - $fromPath = StringUtils::startsWith($from, '/Package/') ? $this->extractPath : $this->basePath; - $toPath = StringUtils::startsWith($to, '/Package/') ? $this->extractPath : $this->basePath; + $fromPath = StringUtils::startsWith($from, '/Package/') ? $this->extractPath . '/' . \substr($from, 9) : $this->basePath . '/' . $from; + $toPath = StringUtils::startsWith($to, '/Package/') ? $this->extractPath . '/' . \substr($to, 9) : $this->basePath . '/' . $to; - LocalStorage::move($fromPath . '/' . $from, $toPath . '/' . $to, true); + LocalStorage::move($fromPath, $toPath, true); } } @@ -252,12 +256,12 @@ final class PackageManager private function copy(array $components) : void { foreach ($components as $from => $tos) { - $fromPath = StringUtils::startsWith($from, '/Package/') ? $this->extractPath : $this->basePath; + $fromPath = StringUtils::startsWith($from, '/Package/') ? $this->extractPath . '/' . \substr($from, 9) : $this->basePath . '/' . $from; foreach ($tos as $to) { - $toPath = StringUtils::startsWith($to, '/Package/') ? $this->extractPath : $this->basePath; + $toPath = StringUtils::startsWith($to, '/Package/') ? $this->extractPath . '/' . \substr($to, 9) : $this->basePath . '/' . $to; - LocalStorage::copy($fromPath . '/' . $from, $toPath . '/' . $to, true); + LocalStorage::copy($fromPath, $toPath, true); } } } @@ -274,8 +278,8 @@ final class PackageManager private function delete(array $components) : void { foreach ($components as $component) { - $path = StringUtils::startsWith($component, '/Package/') ? $this->extractPath : $this->basePath; - LocalStorage::delete($path . '/' . $component); + $path = StringUtils::startsWith($component, '/Package/') ? $this->extractPath . '/' . \substr($component, 9) : $this->basePath . '/' . $component; + LocalStorage::delete($path); } } @@ -291,19 +295,27 @@ final class PackageManager private function cmd(array $components) : void { foreach ($components as $component) { - $pipes = []; $cmd = ''; - $path = StringUtils::startsWith($component, '/Package/') ? $this->extractPath : $this->basePath; + $path = StringUtils::startsWith($component, '/Package/') ? $this->extractPath . '/' . \substr($component, 9) : $this->basePath . '/' . $component; + if (StringUtils::endsWith($component, '.php')) { - $cmd = 'php ' . $path . '/' . $component; - } elseif (StringUtils::endsWith($component, '.sh') && OperatingSystem::getSystem() === SystemType::LINUX) { - $cmd = '.' . $path . '/' . $component; - } elseif (StringUtils::endsWith($component, '.batch') && OperatingSystem::getSystem() === SystemType::WIN) { - $cmd = '.' . $path . '/' . $component; + // todo: maybe add a guessing method to find php path if it isn't available in the environment see Repository.php for git api + $cmd = 'php ' . $path; + } elseif (StringUtils::endsWith($component, '.sh') && OperatingSystem::getSystem() === SystemType::LINUX && \is_executable($path)) { + $cmd = $path; + } elseif (StringUtils::endsWith($component, '.batch') && OperatingSystem::getSystem() === SystemType::WIN && \is_executable($path)) { + $cmd = $path; } if ($cmd !== '') { - \proc_open($cmd, [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes, __DIR__); + $pipes = []; + $resource = \proc_open($cmd, [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes, $this->extractPath); + + foreach ($pipes as $pipe) { + \fclose($pipe); + } + + \proc_close($resource); } } } diff --git a/Security/PhpCode.php b/Security/PhpCode.php index 117b399db..1391b8e06 100644 --- a/Security/PhpCode.php +++ b/Security/PhpCode.php @@ -110,7 +110,7 @@ final class PhpCode $disabled = \ini_get('disable_functions'); if ($disabled === false) { - return true; + return true; // @codeCoverageIgnore } $disabled = \str_replace(' ', '', $disabled); @@ -122,7 +122,7 @@ final class PhpCode } } - return true; + return true; // @codeCoverageIgnore } /** diff --git a/Views/ViewAbstract.php b/Views/ViewAbstract.php index 1c6dcb7f7..ed1189213 100644 --- a/Views/ViewAbstract.php +++ b/Views/ViewAbstract.php @@ -44,25 +44,6 @@ abstract class ViewAbstract implements RenderableInterface */ protected array $views = []; - /** - * Sort views by order. - * - * @param array $a Array 1 - * @param array $b Array 2 - * - * @return int - * - * @since 1.0.0 - */ - private static function viewSort(array $a, array $b) : int - { - if ($a['order'] === $b['order']) { - return 0; - } - - return ($a['order'] < $b['order']) ? -1 : 1; - } - /** * Get the template. * @@ -172,22 +153,17 @@ abstract class ViewAbstract implements RenderableInterface * * @param string $id View ID * @param View $view View to add - * @param int $order Order of view * @param bool $overwrite Overwrite existing view * * @return bool * * @since 1.0.0 */ - public function addView(string $id, View $view, int $order = 0, bool $overwrite = false) : bool + public function addView(string $id, View $view, bool $overwrite = false) : bool { if ($overwrite || !isset($this->views[$id])) { $this->views[$id] = $view; - if ($order !== 0) { - \uasort($this->views, ['\phpOMS\Views\View', 'viewSort']); - } - return true; } diff --git a/tests/Account/AccountManagerTest.php b/tests/Account/AccountManagerTest.php index 178602238..3ce78955b 100644 --- a/tests/Account/AccountManagerTest.php +++ b/tests/Account/AccountManagerTest.php @@ -39,6 +39,7 @@ class AccountManagerTest extends \PHPUnit\Framework\TestCase /** * @testdox The manager has the expected member variables + * @covers phpOMS\Account\AccountManager */ public function testAttributes() : void { @@ -50,6 +51,7 @@ class AccountManagerTest extends \PHPUnit\Framework\TestCase /** * @testdox The manager has the expected default values after initialization + * @covers phpOMS\Account\AccountManager */ public function testDefault() : void { @@ -60,6 +62,7 @@ class AccountManagerTest extends \PHPUnit\Framework\TestCase /** * @testdox An account can be added to the manager + * @covers phpOMS\Account\AccountManager */ public function testAddAccount() : void { @@ -70,6 +73,7 @@ class AccountManagerTest extends \PHPUnit\Framework\TestCase /** * @testdox An account can be retrieved from the manager + * @covers phpOMS\Account\AccountManager */ public function testRetrieveAccount() : void { @@ -79,6 +83,7 @@ class AccountManagerTest extends \PHPUnit\Framework\TestCase /** * @testdox An account can only be added once to the account manager (no duplication) + * @covers phpOMS\Account\AccountManager */ public function testNoAccountDuplication() : void { @@ -93,6 +98,7 @@ class AccountManagerTest extends \PHPUnit\Framework\TestCase /** * @testdox An account can be removed from the account manager + * @covers phpOMS\Account\AccountManager */ public function testRemoveAccount() : void { @@ -104,6 +110,7 @@ class AccountManagerTest extends \PHPUnit\Framework\TestCase /** * @testdox Only a valid account can be removed from the manager + * @covers phpOMS\Account\AccountManager */ public function testRemoveOnlyValidAccount() : void { diff --git a/tests/Account/AccountStatusTest.php b/tests/Account/AccountStatusTest.php index 638783d5c..9f5eaffad 100644 --- a/tests/Account/AccountStatusTest.php +++ b/tests/Account/AccountStatusTest.php @@ -23,6 +23,9 @@ use phpOMS\Account\AccountStatus; */ class AccountStatusTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(4, AccountStatus::getConstants()); diff --git a/tests/Account/AccountTest.php b/tests/Account/AccountTest.php index c6ba0ff4b..4338bea46 100644 --- a/tests/Account/AccountTest.php +++ b/tests/Account/AccountTest.php @@ -41,6 +41,7 @@ class AccountTest extends \PHPUnit\Framework\TestCase /** * @testdox The account has the expected member variables + * @covers phpOMS\Account\Account */ public function testAttributes() : void { @@ -66,6 +67,7 @@ class AccountTest extends \PHPUnit\Framework\TestCase /** * @testdox The account has the expected default values after initialization + * @covers phpOMS\Account\Account */ public function testDefault() : void { @@ -113,6 +115,7 @@ class AccountTest extends \PHPUnit\Framework\TestCase /** * @testdox The account names can be set and retrieved correctly + * @covers phpOMS\Account\Account */ public function testSetAndGetAccountNames() : void { @@ -137,6 +140,7 @@ class AccountTest extends \PHPUnit\Framework\TestCase /** * @testdox Groups can be added to an account + * @covers phpOMS\Account\Account */ public function testAddAndGetGroup() : void { @@ -149,6 +153,7 @@ class AccountTest extends \PHPUnit\Framework\TestCase /** * @testdox An account can have a valid email address + * @covers phpOMS\Account\Account */ public function testSetAndGetAccountEmail() : void { @@ -161,6 +166,7 @@ class AccountTest extends \PHPUnit\Framework\TestCase /** * @testdox The default status of the account can be changed to a different valid status + * @covers phpOMS\Account\Account */ public function testChangeStatus() : void { @@ -173,6 +179,7 @@ class AccountTest extends \PHPUnit\Framework\TestCase /** * @testdox The default type of the account can be changed to a different valid type + * @covers phpOMS\Account\Account */ public function testChangeType() : void { @@ -185,6 +192,7 @@ class AccountTest extends \PHPUnit\Framework\TestCase /** * @testdox Account permissions can be added and checked for existence + * @covers phpOMS\Account\Account */ public function testPermissionHandling() : void { @@ -218,6 +226,7 @@ class AccountTest extends \PHPUnit\Framework\TestCase /** * @testdox An account can have it's own localization + * @covers phpOMS\Account\Account */ public function testLocalization() : void { diff --git a/tests/Account/AccountTypeTest.php b/tests/Account/AccountTypeTest.php index 74c083b18..2229f16a4 100644 --- a/tests/Account/AccountTypeTest.php +++ b/tests/Account/AccountTypeTest.php @@ -23,6 +23,9 @@ use phpOMS\Account\AccountType; */ class AccountTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(2, AccountType::getConstants()); diff --git a/tests/Account/GroupStatusTest.php b/tests/Account/GroupStatusTest.php index 3982923b5..1034fa656 100644 --- a/tests/Account/GroupStatusTest.php +++ b/tests/Account/GroupStatusTest.php @@ -23,6 +23,9 @@ use phpOMS\Account\GroupStatus; */ class GroupStatusTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(3, GroupStatus::getConstants()); diff --git a/tests/Account/GroupTest.php b/tests/Account/GroupTest.php index 4686220c7..023c02893 100644 --- a/tests/Account/GroupTest.php +++ b/tests/Account/GroupTest.php @@ -30,6 +30,7 @@ class GroupTest extends \PHPUnit\Framework\TestCase { /** * @testdox The group has the expected member variables + * @covers phpOMS\Account\Group */ public function testAttributes() : void { @@ -48,6 +49,7 @@ class GroupTest extends \PHPUnit\Framework\TestCase /** * @testdox The group has the expected default values after initialization + * @covers phpOMS\Account\Group */ public function testDefault() : void { @@ -75,6 +77,7 @@ class GroupTest extends \PHPUnit\Framework\TestCase /** * @testdox The group name and description can be set and retrieved correctly + * @covers phpOMS\Account\Group */ public function testSetAndGetGroupNameDescription() : void { @@ -89,6 +92,7 @@ class GroupTest extends \PHPUnit\Framework\TestCase /** * @testdox Group permissions can be added and checked for existence + * @covers phpOMS\Account\Group */ public function testPermissionHandling() : void { @@ -120,6 +124,7 @@ class GroupTest extends \PHPUnit\Framework\TestCase /** * @testdox The default status of the group can be changed to a different valid status + * @covers phpOMS\Account\Group */ public function testChangeStatus() : void { @@ -131,6 +136,7 @@ class GroupTest extends \PHPUnit\Framework\TestCase /** * @testdox A group can only have valid group status + * @covers phpOMS\Account\Group */ public function testStatusException() : void { diff --git a/tests/Account/PermissionAbstractTest.php b/tests/Account/PermissionAbstractTest.php index f678bd7e0..9e2d16359 100644 --- a/tests/Account/PermissionAbstractTest.php +++ b/tests/Account/PermissionAbstractTest.php @@ -20,10 +20,16 @@ use phpOMS\Account\PermissionAbstract; use phpOMS\Account\PermissionType; /** + * @testdox phpOMS\tests\Account\PermissionAbstract: Base permission representation + * * @internal */ class PermissionAbstractTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox The permission has the expected default values after initialization + * @covers phpOMS\Account\PermissionAbstract + */ public function testAbstractDefault() : void { $perm = new class() extends PermissionAbstract {}; @@ -58,41 +64,153 @@ class PermissionAbstractTest extends \PHPUnit\Framework\TestCase ); } - public function testAbstractGetSet() : void + /** + * @testdox The unit can be set and returned correctly + * @covers phpOMS\Account\PermissionAbstract + */ + public function testUnitInputOutput() : void { $perm = new class() extends PermissionAbstract {}; $perm->setUnit(1); self::assertEquals(1, $perm->getUnit()); + } + + /** + * @testdox The app can be set and returned correctly + * @covers phpOMS\Account\PermissionAbstract + */ + public function testAppInputOutput() : void + { + $perm = new class() extends PermissionAbstract {}; $perm->setApp('Test'); self::assertEquals('Test', $perm->getApp()); + } + + /** + * @testdox The module can be set and returned correctly + * @covers phpOMS\Account\PermissionAbstract + */ + public function testModuleInputOutput() : void + { + $perm = new class() extends PermissionAbstract {}; $perm->setModule('2'); self::assertEquals('2', $perm->getModule()); + } + + /** + * @testdox The from can be set and returned correctly + * @covers phpOMS\Account\PermissionAbstract + */ + public function testFromInputOutput() : void + { + $perm = new class() extends PermissionAbstract {}; $perm->setFrom(3); self::assertEquals(3, $perm->getFrom()); + } + + /** + * @testdox The type can be set and returned correctly + * @covers phpOMS\Account\PermissionAbstract + */ + public function testTypeInputOutput() : void + { + $perm = new class() extends PermissionAbstract {}; $perm->setType(4); self::assertEquals(4, $perm->getType()); + } + + /** + * @testdox The element can be set and returned correctly + * @covers phpOMS\Account\PermissionAbstract + */ + public function testElementInputOutput() : void + { + $perm = new class() extends PermissionAbstract {}; $perm->setElement(5); self::assertEquals(5, $perm->getElement()); + } + + /** + * @testdox The component can be set and returned correctly + * @covers phpOMS\Account\PermissionAbstract + */ + public function testComponentInputOutput() : void + { + $perm = new class() extends PermissionAbstract {}; $perm->setComponent(6); self::assertEquals(6, $perm->getComponent()); + } + + /** + * @testdox The permission can be set and returned correctly + * @covers phpOMS\Account\PermissionAbstract + */ + public function testPermissionInputOutput() : void + { + $perm = new class() extends PermissionAbstract {}; $perm->setPermission(PermissionType::READ); self::assertEquals(PermissionType::READ, $perm->getPermission()); + } + /** + * @testdox Correct permissions are validated + * @covers phpOMS\Account\PermissionAbstract + */ + public function testValidPermission() : void + { + $perm = new class() extends PermissionAbstract {}; + + $perm->setPermission(PermissionType::READ); $perm->addPermission(PermissionType::CREATE); self::assertTrue($perm->hasPermission(PermissionType::CREATE)); self::assertTrue($perm->hasPermission(PermissionType::READ)); - self::assertFalse($perm->hasPermission(PermissionType::MODIFY)); + } + /** + * @testdox Invalid permissions are not validted + * @covers phpOMS\Account\PermissionAbstract + */ + public function testInvalidPermission() : void + { + $perm = new class() extends PermissionAbstract {}; + + $perm->setPermission(PermissionType::READ); + $perm->addPermission(PermissionType::CREATE); + self::assertFalse($perm->hasPermission(PermissionType::MODIFY)); + } + + /** + * @testdox Correct permission flags are validated + * @covers phpOMS\Account\PermissionAbstract + */ + public function testValidPermissionFlag() : void + { + $perm = new class() extends PermissionAbstract {}; + + $perm->setPermission(PermissionType::READ); + $perm->addPermission(PermissionType::CREATE); self::assertTrue($perm->hasPermissionFlags(PermissionType::READ)); self::assertTrue($perm->hasPermissionFlags(PermissionType::READ & PermissionType::CREATE)); + } + + /** + * @testdox Invalid permission flags are not validated + * @covers phpOMS\Account\PermissionAbstract + */ + public function testInvalidPermissionFlag() : void + { + $perm = new class() extends PermissionAbstract {}; + + $perm->setPermission(PermissionType::READ); + $perm->addPermission(PermissionType::CREATE); self::assertFalse($perm->hasPermissionFlags(PermissionType::MODIFY)); } } diff --git a/tests/Account/PermissionTypeTest.php b/tests/Account/PermissionTypeTest.php index 9e855dc8e..658f0b58e 100644 --- a/tests/Account/PermissionTypeTest.php +++ b/tests/Account/PermissionTypeTest.php @@ -23,6 +23,9 @@ use phpOMS\Account\PermissionType; */ class PermissionTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(6, PermissionType::getConstants()); diff --git a/tests/Algorithm/Clustering/KmeansTest.php b/tests/Algorithm/Clustering/KmeansTest.php index d78b67080..83912aa33 100644 --- a/tests/Algorithm/Clustering/KmeansTest.php +++ b/tests/Algorithm/Clustering/KmeansTest.php @@ -26,6 +26,7 @@ class KmeansTest extends \PHPUnit\Framework\TestCase { /** * @testdox The clustering of points and dynamic check of new points works as expected + * @covers phpOMS\Algorithm\Clustering\Kmeans */ public function testKmeans() : void { diff --git a/tests/Algorithm/Clustering/PointTest.php b/tests/Algorithm/Clustering/PointTest.php index f8e8fc6e7..45bba24b7 100644 --- a/tests/Algorithm/Clustering/PointTest.php +++ b/tests/Algorithm/Clustering/PointTest.php @@ -25,6 +25,7 @@ class PointTest extends \PHPUnit\Framework\TestCase { /** * @testdox The point has the expected default values after initialization + * @covers phpOMS\Algorithm\Clustering\Point */ public function testDefault() : void { @@ -38,9 +39,10 @@ class PointTest extends \PHPUnit\Framework\TestCase } /** - * @testdox Coordinates of a point can be changed + * @testdox Coordinates of a point can be set and returned + * @covers phpOMS\Algorithm\Clustering\Point */ - public function testChangeCoordinates() : void + public function testCoordinateInputOutput() : void { $point = new Point([3.0, 2.0], 'abc'); @@ -53,13 +55,26 @@ class PointTest extends \PHPUnit\Framework\TestCase } /** - * @testdox The group/cluster of a point can be changed + * @testdox The group/cluster of a point can be set and returned + * @covers phpOMS\Algorithm\Clustering\Point */ - public function testChangeGroup() : void + public function testGroupInputOutput() : void { $point = new Point([3.0, 2.0], 'abc'); $point->setGroup(2); self::assertEquals(2, $point->getGroup()); } + + /** + * @testdox The name of a point can be set and returned + * @covers phpOMS\Algorithm\Clustering\Point + */ + public function testNameInputOutput() : void + { + $point = new Point([3.0, 2.0], 'abc'); + + $point->setName('xyz'); + self::assertEquals('xyz', $point->getName()); + } } diff --git a/tests/Algorithm/CoinMatching/MinimumCoinProblemTest.php b/tests/Algorithm/CoinMatching/MinimumCoinProblemTest.php index 9a1b892a2..f68c1d0be 100644 --- a/tests/Algorithm/CoinMatching/MinimumCoinProblemTest.php +++ b/tests/Algorithm/CoinMatching/MinimumCoinProblemTest.php @@ -27,6 +27,7 @@ class MinimumCoinProblemTest extends \PHPUnit\Framework\TestCase { /** * @testdox A value is matched with the minimum quantity of avialable coins. + * @covers phpOMS\Algorithm\CoinMatching\MinimumCoinProblem */ public function testMinimumCoins() : void { diff --git a/tests/Algorithm/JobScheduling/JobTest.php b/tests/Algorithm/JobScheduling/JobTest.php index 2ee0d506d..2757f1f48 100644 --- a/tests/Algorithm/JobScheduling/JobTest.php +++ b/tests/Algorithm/JobScheduling/JobTest.php @@ -25,6 +25,7 @@ class JobTest extends \PHPUnit\Framework\TestCase { /** * @testdox The job has the expected values after initialization + * @covers phpOMS\Algorithm\JobScheduling\Job */ public function testDefault() : void { diff --git a/tests/Algorithm/JobScheduling/WeightedTest.php b/tests/Algorithm/JobScheduling/WeightedTest.php index af33db637..316721c6d 100644 --- a/tests/Algorithm/JobScheduling/WeightedTest.php +++ b/tests/Algorithm/JobScheduling/WeightedTest.php @@ -26,6 +26,7 @@ class WeightedTest extends \PHPUnit\Framework\TestCase { /** * @testdox The optimal job combination is selected to maximize the value/profit without overlapping jobs + * @covers phpOMS\Algorithm\JobScheduling\Weighted */ public function testNoOverlappingScheduling() : void { @@ -56,6 +57,7 @@ class WeightedTest extends \PHPUnit\Framework\TestCase /** * @testdox A job list with only one job simply returns one job + * @covers phpOMS\Algorithm\JobScheduling\Weighted */ public function testSmallList() : void { diff --git a/tests/Algorithm/Knapsack/BackpackTest.php b/tests/Algorithm/Knapsack/BackpackTest.php index 3e5e30dc5..d9691cd35 100644 --- a/tests/Algorithm/Knapsack/BackpackTest.php +++ b/tests/Algorithm/Knapsack/BackpackTest.php @@ -26,6 +26,7 @@ class BackpackTest extends \PHPUnit\Framework\TestCase { /** * @testdox The backpack has the expected values after initialization + * @covers phpOMS\Algorithm\Knapsack\Backpack */ public function testDefault() : void { @@ -39,6 +40,7 @@ class BackpackTest extends \PHPUnit\Framework\TestCase /** * @testdox Items can be added to the backpack and automatically change the value and cost the backpack contains + * @covers phpOMS\Algorithm\Knapsack\Backpack */ public function testAddItems() : void { diff --git a/tests/Algorithm/Knapsack/BoundedTest.php b/tests/Algorithm/Knapsack/BoundedTest.php index 35b83b7aa..b6b7800e1 100644 --- a/tests/Algorithm/Knapsack/BoundedTest.php +++ b/tests/Algorithm/Knapsack/BoundedTest.php @@ -27,6 +27,7 @@ class BoundedTest extends \PHPUnit\Framework\TestCase { /** * @testdox The optimal item selection in a backpack is calculated in order to optimize the value/profit while considering the available capacity/cost limit + * @covers phpOMS\Algorithm\Knapsack\Bounded */ public function testBackpacking() : void { diff --git a/tests/Algorithm/Knapsack/ContinuousTest.php b/tests/Algorithm/Knapsack/ContinuousTest.php index 9e0cc2248..b504e564e 100644 --- a/tests/Algorithm/Knapsack/ContinuousTest.php +++ b/tests/Algorithm/Knapsack/ContinuousTest.php @@ -27,6 +27,7 @@ class ContinuousTest extends \PHPUnit\Framework\TestCase { /** * @testdox The optimal item selection in a backpack is calculated in order to optimize the value/profit while considering the available capacity/cost limit [discrete quantities] + * @covers phpOMS\Algorithm\Knapsack\Continuous */ public function testBackpacking() : void { @@ -67,6 +68,7 @@ class ContinuousTest extends \PHPUnit\Framework\TestCase /** * @testdox The optimal item selection in a backpack is calculated in order to optimize the value/profit while considering the available capacity/cost limit [continuous quantities] + * @covers phpOMS\Algorithm\Knapsack\Continuous */ public function testBackpackingAlternative() : void { diff --git a/tests/Algorithm/Knapsack/ItemTest.php b/tests/Algorithm/Knapsack/ItemTest.php index d19ef8228..7c3f0aa0b 100644 --- a/tests/Algorithm/Knapsack/ItemTest.php +++ b/tests/Algorithm/Knapsack/ItemTest.php @@ -25,6 +25,7 @@ class ItemTest extends \PHPUnit\Framework\TestCase { /** * @testdox The item has the expected values after initialization + * @covers phpOMS\Algorithm\Knapsack\Item */ public function testDefault() : void { diff --git a/tests/Algorithm/PathFinding/AStarNodeTest.php b/tests/Algorithm/PathFinding/AStarNodeTest.php new file mode 100644 index 000000000..0fe6c8edb --- /dev/null +++ b/tests/Algorithm/PathFinding/AStarNodeTest.php @@ -0,0 +1,108 @@ +node = new AStarNode(1, 2, 3.0, false); + } + + /** + * @testdox The node has the expected values after initialization + * @covers phpOMS\Algorithm\PathFinding\AStarNode + */ + public function testDefault() : void + { + self::assertFalse($this->node->isClosed()); + self::assertFalse($this->node->isOpened()); + self::assertFalse($this->node->isTested()); + self::assertEquals(0.0, $this->node->getG()); + self::assertEquals(null, $this->node->getH()); + self::assertEquals(0.0, $this->node->getF()); + } + + /** + * @testdox The node can be set closed and checked + * @covers phpOMS\Algorithm\PathFinding\AStarNode + */ + public function testClosedInputOutput() : void + { + $this->node->setClosed(true); + self::assertTrue($this->node->isClosed()); + } + + /** + * @testdox The node can be set opened and checked + * @covers phpOMS\Algorithm\PathFinding\AStarNode + */ + public function testOpenedInputOutput() : void + { + $this->node->setOpened(true); + self::assertTrue($this->node->isOpened()); + } + + /** + * @testdox The node can be set tested and checked + * @covers phpOMS\Algorithm\PathFinding\AStarNode + */ + public function testTestedInputOutput() : void + { + $this->node->setTested(true); + self::assertTrue($this->node->isTested()); + } + + /** + * @testdox The g value cen be set and returned + * @covers phpOMS\Algorithm\PathFinding\AStarNode + */ + public function testGInputOutput() : void + { + $this->node->setG(2.0); + self::assertEquals(2.0, $this->node->getG()); + } + + /** + * @testdox The h value cen be set and returned + * @covers phpOMS\Algorithm\PathFinding\AStarNode + */ + public function testHInputOutput() : void + { + $this->node->setH(2.0); + self::assertEquals(2.0, $this->node->getH()); + } + + /** + * @testdox The f value cen be set and returned + * @covers phpOMS\Algorithm\PathFinding\AStarNode + */ + public function testFInputOutput() : void + { + $this->node->setF(2.0); + self::assertEquals(2.0, $this->node->getF()); + } +} diff --git a/tests/Algorithm/PathFinding/AStarTest.php b/tests/Algorithm/PathFinding/AStarTest.php index 77d3dccfe..65146cb11 100644 --- a/tests/Algorithm/PathFinding/AStarTest.php +++ b/tests/Algorithm/PathFinding/AStarTest.php @@ -69,6 +69,7 @@ class AStarTest extends \PHPUnit\Framework\TestCase /** * @testdox The correct path is found for diagonal movement + * @covers phpOMS\Algorithm\PathFinding\AStar */ public function testPathFindingDiagonal() : void { @@ -111,6 +112,7 @@ class AStarTest extends \PHPUnit\Framework\TestCase /** * @testdox The correct path is found for straight movement + * @covers phpOMS\Algorithm\PathFinding\AStar */ public function testPathFindingStraight() : void { @@ -153,6 +155,7 @@ class AStarTest extends \PHPUnit\Framework\TestCase /** * @testdox The correct path is found for diagonal movement [one obstacle] + * @covers phpOMS\Algorithm\PathFinding\AStar */ public function testPathFindingDiagonalOneObstacle() : void { @@ -195,6 +198,7 @@ class AStarTest extends \PHPUnit\Framework\TestCase /** * @testdox The correct path is found for diagonal movement [no obstacle] + * @covers phpOMS\Algorithm\PathFinding\AStar */ public function testPathFindingDiagonalNoObstacle() : void { diff --git a/tests/Algorithm/PathFinding/GridTest.php b/tests/Algorithm/PathFinding/GridTest.php new file mode 100644 index 000000000..271fb75c6 --- /dev/null +++ b/tests/Algorithm/PathFinding/GridTest.php @@ -0,0 +1,417 @@ +getNode(0, 0)); + } + + /** + * @testdox A grid can be created from an array + * @covers phpOMS\Algorithm\PathFinding\Grid + */ + public function testGridFromArray() : void + { + $grid = Grid::createGridFromArray([ + [0, 9, 0], + [0, 9, 0], + [0, 9, 0], + ], Node::class); + + self::assertTrue($grid->isWalkable(0, 0)); + self::assertFalse($grid->isWalkable(1, 0)); + self::assertTrue($grid->isWalkable(2, 0)); + + self::assertTrue($grid->isWalkable(0, 1)); + self::assertFalse($grid->isWalkable(1, 1)); + self::assertTrue($grid->isWalkable(2, 1)); + + self::assertTrue($grid->isWalkable(0, 2)); + self::assertFalse($grid->isWalkable(1, 2)); + self::assertTrue($grid->isWalkable(2, 2)); + } + + /** + * @testdox A node can be set and returned from the grid + * @covers phpOMS\Algorithm\PathFinding\Grid + */ + public function testNodeInputOutput() : void + { + $grid = Grid::createGridFromArray([ + [0, 9, 0], + [0, 9, 0], + [0, 9, 0], + ], Node::class); + + $grid->setNode(0, 0, new Node(0, 0, 1.0, false)); + self::assertFalse($grid->getNode(0, 0)->isWalkable()); + self::assertFalse($grid->isWalkable(0, 0)); + } + + /** + * @testdox Out of bounds nodes cannot be returned + * @covers phpOMS\Algorithm\PathFinding\Grid::getNode + */ + public function testOutOfBoundsNode() : void + { + $grid = Grid::createGridFromArray([ + [0, 9, 0], + [0, 9, 0], + [0, 9, 0], + ], Node::class); + + self::assertEquals(null, $grid->getNode(-1, 0)); + self::assertEquals(null, $grid->getNode(0, -1)); + self::assertEquals(null, $grid->getNode(3, 0)); + self::assertEquals(null, $grid->getNode(0, 3)); + } + + /** + * @testdox All hoirzontal neighbors can be found correctly + * @covers phpOMS\Algorithm\PathFinding\Grid::getNeighbors + */ + public function testStraightHorizontalNeighbors() : void + { + $grid = Grid::createGridFromArray([ + [0, 9, 0], + [0, 0, 0], + [0, 9, 0], + ], Node::class); + + $node = $grid->getNode(1, 1); + $neighbors = $grid->getNeighbors($node, MovementType::STRAIGHT); + + self::assertEquals(2, \count($neighbors)); + self::assertTrue($grid->getNode(0, 1)->isEqual($neighbors[1])); + self::assertTrue($grid->getNode(2, 1)->isEqual($neighbors[0])); + } + + /** + * @testdox All vertical neighbors can be found correctly + * @covers phpOMS\Algorithm\PathFinding\Grid::getNeighbors + */ + public function testStraightVerticalNeighbors() : void + { + $grid = Grid::createGridFromArray([ + [0, 0, 0], + [9, 0, 9], + [0, 0, 0], + ], Node::class); + + $node = $grid->getNode(1, 1); + $neighbors = $grid->getNeighbors($node, MovementType::STRAIGHT); + + self::assertEquals(2, \count($neighbors)); + self::assertTrue($grid->getNode(1, 0)->isEqual($neighbors[0])); + self::assertTrue($grid->getNode(1, 2)->isEqual($neighbors[1])); + } + + /** + * @testdox No straight neighbors are found if no straight neighbors exist + * @covers phpOMS\Algorithm\PathFinding\Grid::getNeighbors + */ + public function testStraightNoneNeighbors() : void + { + $grid = Grid::createGridFromArray([ + [0, 9, 0], + [9, 0, 9], + [0, 9, 0], + ], Node::class); + + $node = $grid->getNode(1, 1); + $neighbors = $grid->getNeighbors($node, MovementType::STRAIGHT); + + self::assertEquals(0, \count($neighbors)); + } + + /** + * @testdox All straight neighbors can be found correctly + * @covers phpOMS\Algorithm\PathFinding\Grid::getNeighbors + */ + public function testStraightAllNeighbors() : void + { + $grid = Grid::createGridFromArray([ + [9, 0, 9], + [0, 0, 0], + [9, 0, 9], + ], Node::class); + + $node = $grid->getNode(1, 1); + $neighbors = $grid->getNeighbors($node, MovementType::STRAIGHT); + + self::assertEquals(4, \count($neighbors)); + self::assertTrue($grid->getNode(0, 1)->isEqual($neighbors[3])); + self::assertTrue($grid->getNode(2, 1)->isEqual($neighbors[1])); + self::assertTrue($grid->getNode(1, 0)->isEqual($neighbors[0])); + self::assertTrue($grid->getNode(1, 2)->isEqual($neighbors[2])); + } + + /** + * @testdox All neighbors except blocked diagonal neighbors can be found correctly + * @covers phpOMS\Algorithm\PathFinding\Grid::getNeighbors + */ + public function testDiagonalLRNeighbors() : void + { + $grid = Grid::createGridFromArray([ + [0, 0, 9], + [0, 0, 0], + [9, 0, 0], + ], Node::class); + + $node = $grid->getNode(1, 1); + $neighbors = $grid->getNeighbors($node, MovementType::DIAGONAL); + + self::assertEquals(6, \count($neighbors)); + self::assertTrue($grid->getNode(0, 0)->isEqual($neighbors[4])); + self::assertTrue($grid->getNode(1, 0)->isEqual($neighbors[0])); + self::assertTrue($grid->getNode(0, 1)->isEqual($neighbors[3])); + self::assertTrue($grid->getNode(2, 1)->isEqual($neighbors[1])); + self::assertTrue($grid->getNode(1, 2)->isEqual($neighbors[2])); + self::assertTrue($grid->getNode(2, 2)->isEqual($neighbors[5])); + } + + /** + * @testdox All neighbors except blocked diagonal neighbors can be found correctly + * @covers phpOMS\Algorithm\PathFinding\Grid::getNeighbors + */ + public function testDiagonalURNeighbors() : void + { + $grid = Grid::createGridFromArray([ + [9, 0, 0], + [0, 0, 0], + [0, 0, 9], + ], Node::class); + + $node = $grid->getNode(1, 1); + $neighbors = $grid->getNeighbors($node, MovementType::DIAGONAL); + + self::assertEquals(6, \count($neighbors)); + self::assertTrue($grid->getNode(1, 0)->isEqual($neighbors[0])); + self::assertTrue($grid->getNode(2, 0)->isEqual($neighbors[4])); + self::assertTrue($grid->getNode(0, 1)->isEqual($neighbors[3])); + self::assertTrue($grid->getNode(2, 1)->isEqual($neighbors[1])); + self::assertTrue($grid->getNode(1, 2)->isEqual($neighbors[2])); + self::assertTrue($grid->getNode(0, 2)->isEqual($neighbors[5])); + } + + /** + * @testdox No diagonal neighbors are found if no neighbors exist + * @covers phpOMS\Algorithm\PathFinding\Grid::getNeighbors + */ + public function testDiagonalNoneNeighbors() : void + { + $grid = Grid::createGridFromArray([ + [9, 9, 9], + [9, 0, 9], + [9, 9, 9], + ], Node::class); + + $node = $grid->getNode(1, 1); + $neighbors = $grid->getNeighbors($node, MovementType::DIAGONAL); + + self::assertEquals(0, \count($neighbors)); + } + + /** + * @testdox All diagonal neighbors can be found correctly + * @covers phpOMS\Algorithm\PathFinding\Grid::getNeighbors + */ + public function testDiagonalOnlyNeighbors() : void + { + $grid = Grid::createGridFromArray([ + [0, 9, 0], + [9, 0, 9], + [0, 9, 0], + ], Node::class); + + $node = $grid->getNode(1, 1); + $neighbors = $grid->getNeighbors($node, MovementType::DIAGONAL); + + self::assertEquals(4, \count($neighbors)); + self::assertTrue($grid->getNode(0, 0)->isEqual($neighbors[0])); + self::assertTrue($grid->getNode(2, 0)->isEqual($neighbors[1])); + self::assertTrue($grid->getNode(0, 2)->isEqual($neighbors[3])); + self::assertTrue($grid->getNode(2, 2)->isEqual($neighbors[2])); + } + + /** + * @testdox All neighbors can be found correctly + * @covers phpOMS\Algorithm\PathFinding\Grid::getNeighbors + */ + public function testDiagonalAllNeighbors() : void + { + $grid = Grid::createGridFromArray([ + [0, 0, 0], + [0, 0, 0], + [0, 0, 0], + ], Node::class); + + $node = $grid->getNode(1, 1); + $neighbors = $grid->getNeighbors($node, MovementType::DIAGONAL); + + self::assertEquals(8, \count($neighbors)); + self::assertTrue($grid->getNode(0, 0)->isEqual($neighbors[4])); + self::assertTrue($grid->getNode(1, 0)->isEqual($neighbors[0])); + self::assertTrue($grid->getNode(2, 0)->isEqual($neighbors[5])); + self::assertTrue($grid->getNode(0, 1)->isEqual($neighbors[3])); + self::assertTrue($grid->getNode(2, 1)->isEqual($neighbors[1])); + self::assertTrue($grid->getNode(0, 2)->isEqual($neighbors[7])); + self::assertTrue($grid->getNode(1, 2)->isEqual($neighbors[2])); + self::assertTrue($grid->getNode(2, 2)->isEqual($neighbors[6])); + } + + /** + * @testdox All neighbors can be found correctly even if one obstacle exists + * @covers phpOMS\Algorithm\PathFinding\Grid::getNeighbors + */ + public function testDiagonalOneObstacleNoBlockNeighbors() : void + { + $grid = Grid::createGridFromArray([ + [0, 9, 0], + [0, 0, 0], + [0, 0, 0], + ], Node::class); + + $node = $grid->getNode(1, 1); + $neighbors = $grid->getNeighbors($node, MovementType::DIAGONAL_ONE_OBSTACLE); + + self::assertEquals(7, \count($neighbors)); + self::assertTrue($grid->getNode(0, 0)->isEqual($neighbors[3])); + self::assertTrue($grid->getNode(2, 0)->isEqual($neighbors[4])); + self::assertTrue($grid->getNode(0, 1)->isEqual($neighbors[2])); + self::assertTrue($grid->getNode(2, 1)->isEqual($neighbors[0])); + self::assertTrue($grid->getNode(0, 2)->isEqual($neighbors[6])); + self::assertTrue($grid->getNode(1, 2)->isEqual($neighbors[1])); + self::assertTrue($grid->getNode(2, 2)->isEqual($neighbors[5])); + } + + /** + * @testdox No diagonal neighbors are found if they are blocked on two sides + * @covers phpOMS\Algorithm\PathFinding\Grid::getNeighbors + */ + public function testDiagonalOneObstacleBlockNeighbors() : void + { + $grid = Grid::createGridFromArray([ + [0, 9, 0], + [0, 0, 9], + [0, 0, 0], + ], Node::class); + + $node = $grid->getNode(1, 1); + $neighbors = $grid->getNeighbors($node, MovementType::DIAGONAL_ONE_OBSTACLE); + + self::assertEquals(5, \count($neighbors)); + self::assertTrue($grid->getNode(0, 0)->isEqual($neighbors[2])); + self::assertTrue($grid->getNode(0, 1)->isEqual($neighbors[1])); + self::assertTrue($grid->getNode(0, 2)->isEqual($neighbors[4])); + self::assertTrue($grid->getNode(1, 2)->isEqual($neighbors[0])); + self::assertTrue($grid->getNode(2, 2)->isEqual($neighbors[3])); + } + + /** + * @testdox All neighbors can be found correctly if no obstacles exists + * @covers phpOMS\Algorithm\PathFinding\Grid::getNeighbors + */ + public function testDiagonalOneObstacleAllNeighbors() : void + { + $grid = Grid::createGridFromArray([ + [0, 0, 0], + [0, 0, 0], + [0, 0, 0], + ], Node::class); + + $node = $grid->getNode(1, 1); + $neighbors = $grid->getNeighbors($node, MovementType::DIAGONAL_ONE_OBSTACLE); + + self::assertEquals(8, \count($neighbors)); + self::assertTrue($grid->getNode(0, 0)->isEqual($neighbors[4])); + self::assertTrue($grid->getNode(1, 0)->isEqual($neighbors[0])); + self::assertTrue($grid->getNode(2, 0)->isEqual($neighbors[5])); + self::assertTrue($grid->getNode(0, 1)->isEqual($neighbors[3])); + self::assertTrue($grid->getNode(2, 1)->isEqual($neighbors[1])); + self::assertTrue($grid->getNode(0, 2)->isEqual($neighbors[7])); + self::assertTrue($grid->getNode(1, 2)->isEqual($neighbors[2])); + self::assertTrue($grid->getNode(2, 2)->isEqual($neighbors[6])); + } + + /** + * @testdox No diagonal neighbors are found if one obstacle exists + * @covers phpOMS\Algorithm\PathFinding\Grid::getNeighbors + */ + public function testDiagonalNoObstacleBlockNeighbors() : void + { + $grid = Grid::createGridFromArray([ + [0, 9, 0], + [0, 0, 0], + [0, 0, 0], + ], Node::class); + + $node = $grid->getNode(1, 1); + $neighbors = $grid->getNeighbors($node, MovementType::DIAGONAL_NO_OBSTACLE); + + self::assertEquals(5, \count($neighbors)); + self::assertTrue($grid->getNode(0, 1)->isEqual($neighbors[2])); + self::assertTrue($grid->getNode(2, 1)->isEqual($neighbors[0])); + self::assertTrue($grid->getNode(0, 2)->isEqual($neighbors[4])); + self::assertTrue($grid->getNode(1, 2)->isEqual($neighbors[1])); + self::assertTrue($grid->getNode(2, 2)->isEqual($neighbors[3])); + } + + /** + * @testdox All neighbors can be found correctly if no obstacles exist + * @covers phpOMS\Algorithm\PathFinding\Grid::getNeighbors + */ + public function testDiagonalNoObstacleAllNeighbors() : void + { + $grid = Grid::createGridFromArray([ + [0, 0, 0], + [0, 0, 0], + [0, 0, 0], + ], Node::class); + + $node = $grid->getNode(1, 1); + $neighbors = $grid->getNeighbors($node, MovementType::DIAGONAL_NO_OBSTACLE); + + self::assertEquals(8, \count($neighbors)); + self::assertTrue($grid->getNode(0, 0)->isEqual($neighbors[4])); + self::assertTrue($grid->getNode(1, 0)->isEqual($neighbors[0])); + self::assertTrue($grid->getNode(2, 0)->isEqual($neighbors[5])); + self::assertTrue($grid->getNode(0, 1)->isEqual($neighbors[3])); + self::assertTrue($grid->getNode(2, 1)->isEqual($neighbors[1])); + self::assertTrue($grid->getNode(0, 2)->isEqual($neighbors[7])); + self::assertTrue($grid->getNode(1, 2)->isEqual($neighbors[2])); + self::assertTrue($grid->getNode(2, 2)->isEqual($neighbors[6])); + } +} diff --git a/tests/Algorithm/PathFinding/JumpPointNodeTest.php b/tests/Algorithm/PathFinding/JumpPointNodeTest.php new file mode 100644 index 000000000..8b2347dd6 --- /dev/null +++ b/tests/Algorithm/PathFinding/JumpPointNodeTest.php @@ -0,0 +1,108 @@ +node = new JumpPointNode(1, 2, 3.0, false); + } + + /** + * @testdox The node has the expected values after initialization + * @covers phpOMS\Algorithm\PathFinding\JumpPointNode + */ + public function testDefault() : void + { + self::assertFalse($this->node->isClosed()); + self::assertFalse($this->node->isOpened()); + self::assertFalse($this->node->isTested()); + self::assertEquals(0.0, $this->node->getG()); + self::assertEquals(null, $this->node->getH()); + self::assertEquals(0.0, $this->node->getF()); + } + + /** + * @testdox The node can be set closed and checked + * @covers phpOMS\Algorithm\PathFinding\JumpPointNode + */ + public function testClosedInputOutput() : void + { + $this->node->setClosed(true); + self::assertTrue($this->node->isClosed()); + } + + /** + * @testdox The node can be set opened and checked + * @covers phpOMS\Algorithm\PathFinding\JumpPointNode + */ + public function testOpenedInputOutput() : void + { + $this->node->setOpened(true); + self::assertTrue($this->node->isOpened()); + } + + /** + * @testdox The node can be set tested and checked + * @covers phpOMS\Algorithm\PathFinding\JumpPointNode + */ + public function testTestedInputOutput() : void + { + $this->node->setTested(true); + self::assertTrue($this->node->isTested()); + } + + /** + * @testdox The g value cen be set and returned + * @covers phpOMS\Algorithm\PathFinding\JumpPointNode + */ + public function testGInputOutput() : void + { + $this->node->setG(2.0); + self::assertEquals(2.0, $this->node->getG()); + } + + /** + * @testdox The h value cen be set and returned + * @covers phpOMS\Algorithm\PathFinding\JumpPointNode + */ + public function testHInputOutput() : void + { + $this->node->setH(2.0); + self::assertEquals(2.0, $this->node->getH()); + } + + /** + * @testdox The f value cen be set and returned + * @covers phpOMS\Algorithm\PathFinding\JumpPointNode + */ + public function testFInputOutput() : void + { + $this->node->setF(2.0); + self::assertEquals(2.0, $this->node->getF()); + } +} diff --git a/tests/Algorithm/PathFinding/JumpPointSearchTest.php b/tests/Algorithm/PathFinding/JumpPointSearchTest.php index 1acca0cf4..40b8b5477 100644 --- a/tests/Algorithm/PathFinding/JumpPointSearchTest.php +++ b/tests/Algorithm/PathFinding/JumpPointSearchTest.php @@ -69,6 +69,7 @@ class JumpPointSearchTest extends \PHPUnit\Framework\TestCase /** * @testdox The correct path is found for diagonal movement + * @covers phpOMS\Algorithm\PathFinding\JumpPointSearch */ public function testPathFindingDiagonal() : void { @@ -111,6 +112,7 @@ class JumpPointSearchTest extends \PHPUnit\Framework\TestCase /** * @testdox The correct path is found for straight movement + * @covers phpOMS\Algorithm\PathFinding\JumpPointSearch */ public function testPathFindingStraight() : void { @@ -153,6 +155,7 @@ class JumpPointSearchTest extends \PHPUnit\Framework\TestCase /** * @testdox The correct path is found for diagonal movement [one obstacle] + * @covers phpOMS\Algorithm\PathFinding\JumpPointSearch */ public function testPathFindingDiagonalOneObstacle() : void { @@ -195,6 +198,7 @@ class JumpPointSearchTest extends \PHPUnit\Framework\TestCase /** * @testdox The correct path is found for diagonal movement [no obstacle] + * @covers phpOMS\Algorithm\PathFinding\JumpPointSearch */ public function testPathFindingDiagonalNoObstacle() : void { diff --git a/tests/Algorithm/PathFinding/NodeTest.php b/tests/Algorithm/PathFinding/NodeTest.php new file mode 100644 index 000000000..c401a0dd6 --- /dev/null +++ b/tests/Algorithm/PathFinding/NodeTest.php @@ -0,0 +1,81 @@ +getX()); + self::assertEquals(2, $node->getY()); + self::assertEquals(['x' => 1, 'y' => 2], $node->getCoordinates()); + self::assertEquals(3.0, $node->getWeight()); + self::assertEquals(null, $node->getParent()); + self::assertFalse($node->isWalkable()); + } + + /** + * @testdox Nodes with equal coordinates are equal + * @covers phpOMS\Algorithm\PathFinding\Node + */ + public function testNodesWithEqualCoordinatesAreEqual() : void + { + $node = new Node(1, 2, 3.0, false); + $node2 = new Node(1, 2, 2.0, true); + + self::assertTrue($node->isEqual($node2)); + } + + /** + * @testdox Nodes with different coordinates are not equal + * @covers phpOMS\Algorithm\PathFinding\Node + */ + public function testNodesWithDifferentCoordinatesAreNotEqual() : void + { + $node = new Node(1, 2, 3.0, false); + $node2 = new Node(2, 2, 3.0, false); + + self::assertFalse($node->isEqual($node2)); + } + + /** + * @testdox A parent node can be set and returned + * @covers phpOMS\Algorithm\PathFinding\Node + */ + public function testParentInputOutput() : void + { + $node = new Node(1, 2, 3.0, false); + $node2 = new Node(2, 2, 3.0, false); + + $node->setParent($node2); + self::assertTrue($node2->isEqual($node->getParent())); + } +} diff --git a/tests/Algorithm/PathFinding/PathTest.php b/tests/Algorithm/PathFinding/PathTest.php new file mode 100644 index 000000000..2feb3627e --- /dev/null +++ b/tests/Algorithm/PathFinding/PathTest.php @@ -0,0 +1,112 @@ +getLength()); + self::assertEquals([], $path->getPath()); + self::assertEquals([], $path->expandPath()); + } + + /** + * @testdox The diagonal euclidean path length is calculated correctly + * @covers phpOMS\Algorithm\PathFinding\Path + */ + public function testDiagonalPathLength() : void + { + $grid = Grid::createGridFromArray([ + [0, 0, 0, 0, 0], + [0, 0, 0, 0, 0], + [0, 0, 0, 0, 0], + [0, 0, 0, 0, 0], + [0, 0, 0, 0, 0], + ], Node::class); + + $path = new Path($grid); + + $path->addNode(new Node(1, 3)); + $path->addNode(new Node(3, 1)); + $path->addNode(new Node(4, 0)); + + self::assertEqualsWithDelta(4.2426, $path->getLength(), 0.001); + } + + /** + * @testdox The straight euclidean path length is calculated correctly + * @covers phpOMS\Algorithm\PathFinding\Path + */ + public function testStraightPathLength() : void + { + $grid = Grid::createGridFromArray([ + [0, 0, 0, 0, 0], + [0, 0, 0, 0, 0], + [0, 0, 0, 0, 0], + [0, 0, 0, 0, 0], + [0, 0, 0, 0, 0], + ], Node::class); + + $path = new Path($grid); + + $path->addNode(new Node(1, 3)); + $path->addNode(new Node(1, 1)); + $path->addNode(new Node(3, 1)); + + self::assertEqualsWithDelta(4.0, $path->getLength(), 0.001); + } + + /** + * @testdox The path is correctly expanded in case only jump points are defined + * @covers phpOMS\Algorithm\PathFinding\Path + */ + public function testPathExpansion() : void + { + $grid = Grid::createGridFromArray([ + [0, 0, 0, 0, 0], + [0, 0, 0, 0, 0], + [0, 0, 0, 0, 0], + [0, 0, 0, 0, 0], + [0, 0, 0, 0, 0], + ], Node::class); + + $path = new Path($grid); + + $path->addNode(new Node(1, 3)); + $path->addNode(new Node(3, 1)); + $path->addNode(new Node(4, 0)); + + self::assertEquals(3, \count($path->getPath())); + self::assertEquals(4, \count($path->expandPath())); + } +} diff --git a/tests/Asset/AssetTypeTest.php b/tests/Asset/AssetTypeTest.php index 519159ca7..5a22a6845 100644 --- a/tests/Asset/AssetTypeTest.php +++ b/tests/Asset/AssetTypeTest.php @@ -23,6 +23,9 @@ use phpOMS\Asset\AssetType; */ class AssetTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(3, AssetType::getConstants()); diff --git a/tests/Auth/LoginReturnTypeTest.php b/tests/Auth/LoginReturnTypeTest.php index d0a3d8709..2b67ef579 100644 --- a/tests/Auth/LoginReturnTypeTest.php +++ b/tests/Auth/LoginReturnTypeTest.php @@ -23,6 +23,9 @@ use phpOMS\Auth\LoginReturnType; */ class LoginReturnTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(11, LoginReturnType::getConstants()); diff --git a/tests/Business/Finance/FinanceFormulasTest.php b/tests/Business/Finance/FinanceFormulasTest.php index 127511e50..bbcb038a7 100644 --- a/tests/Business/Finance/FinanceFormulasTest.php +++ b/tests/Business/Finance/FinanceFormulasTest.php @@ -437,6 +437,9 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(0.04123, FinanceFormulas::getGeometricMeanReturn($r), 0.01); } + /** + * @testdox The calculation of the future value of the growing annuity is correct + */ public function testGrowingAnnuityFV() : void { $p = 1000; @@ -447,6 +450,9 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(14226.06, FinanceFormulas::getGrowingAnnuityFV($p, $r, $g, $n), 0.01); } + /** + * @testdox The calculation of the payment based on the present value of the growing annuity is correct + */ public function testGrowingAnnuityPaymentPV() : void { $p = 1000; @@ -457,6 +463,9 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(186.98, FinanceFormulas::getGrowingAnnuityPaymentPV($p, $r, $g, $n), 0.01); } + /** + * @testdox The calculation of the payment based on the future value of the growing annuity is correct + */ public function testGrowingAnnuityPaymentFV() : void { $fv = 1000; @@ -467,6 +476,9 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(70.29, FinanceFormulas::getGrowingAnnuityPaymentFV($fv, $r, $g, $n), 0.01); } + /** + * @testdox The calculation of the present value of the growing annuity is correct + */ public function testGrowingAnnuityPV() : void { $p = 1000; @@ -477,6 +489,9 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(5348.1, FinanceFormulas::getGrowingAnnuityPV($p, $r, $g, $n), 0.01); } + /** + * @testdox The calculation of the present value of the growing perpetuity is correct + */ public function testGrowingPerpetuityPV() : void { $d = 1000; @@ -486,6 +501,9 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(20000, FinanceFormulas::getGrowingPerpetuityPV($d, $r, $g), 0.01); } + /** + * @testdox The calculation of the net present value is correct + */ public function testNetPresentValue() : void { $c = [1000, 100, 200, 300, 400, 500, 600]; @@ -494,13 +512,17 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(172.13, FinanceFormulas::getNetPresentValue($c, $r), 0.01); } - public function testInvalidNetPresentValue() : void + /** + * @testdox No cash flows in the net prsent value calculation result in 0 + */ + public function testEmptyNetPresentValue() : void { - self::expectException(\UnexpectedValueException::class); - - FinanceFormulas::getNetPresentValue([], 0.1); + self::assertEquals(0.0, FinanceFormulas::getNetPresentValue([], 0.1)); } + /** + * @testdox The calculation of the real rate of return is correct + */ public function testRealRateOfReturn() : void { $nominal = 0.15; @@ -509,11 +531,17 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(0.09524, FinanceFormulas::getRealRateOfReturn($nominal, $inflation), 0.01); } + /** + * @testdox The calculation of the net working capital is correct + */ public function testNetWorkingCapital() : void { self::assertEqualsWithDelta(1000 - 600, FinanceFormulas::getNetWorkingCapital(1000, 600), 0.01); } + /** + * @testdox The periods to reach a future value based on the present value is calculated correctly + */ public function testNumberOfPeriodsPVFV() : void { $fv = 1200; @@ -523,6 +551,9 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(6.1681, FinanceFormulas::getNumberOfPeriodsPVFV($fv, $pv, $r), 0.01); } + /** + * @testdox The calculation of the present value is correct + */ public function testPresentValue() : void { $c = 1000; @@ -532,6 +563,9 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(375.94, FinanceFormulas::getPresentValue($c, $r, $n), 0.01); } + /** + * @testdox The calculation of the present value using continuous compounding is correct + */ public function testPresentValueContinuousCompounding() : void { $c = 1000; diff --git a/tests/Business/Finance/StockBondsTest.php b/tests/Business/Finance/StockBondsTest.php index d7caf9dd6..29372ce1b 100644 --- a/tests/Business/Finance/StockBondsTest.php +++ b/tests/Business/Finance/StockBondsTest.php @@ -17,10 +17,15 @@ namespace phpOMS\tests\Business\Finance; use phpOMS\Business\Finance\StockBonds; /** + * @testdox phpOMS\tests\Business\Finance\FinanceFormulasTest: Stock & bond related formulas + * * @internal */ class StockBondsTest extends \PHPUnit\Framework\TestCase { + /** + * @testdox The calculation of various stock/bond related ratios/yields is correct + */ public function testRatios() : void { self::assertEquals(100 / 50, StockBonds::getBookValuePerShare(100, 50)); @@ -35,26 +40,41 @@ class StockBondsTest extends \PHPUnit\Framework\TestCase self::assertEquals(100 / 50, StockBonds::getPriceToSalesRatio(100, 50)); } + /** + * @testdox The calculation of the bond yield based on face value and price is correct + */ public function testBondEquivalentYield() : void { self::assertEqualsWithDelta(0.40556, StockBonds::getBondEquivalentYield(100, 90, 100), 0.01); } + /** + * @testdox The calculation of the return of the capital asset pricing model is correct + */ public function testExpectedReturnCAPM() : void { self::assertEqualsWithDelta(7, StockBonds::getExpectedReturnCAPM(3, 2, 5), 0.01); } + /** + * @testdox The capital gains yield calculation is correct + */ public function testCapitalGainsYield() : void { self::assertEqualsWithDelta(0.1, StockBonds::getCapitalGainsYield(100, 110), 0.01); } + /** + * @testdox The diluted earnings per share calculation is correct + */ public function testDilutedEarningsPerShare() : void { self::assertEqualsWithDelta(9.09, StockBonds::getDilutedEarningsPerShare(1000, 100, 10), 0.1); } + /** + * @testdox The calculation of the absolute return for multiple holding periods is correct + */ public function testHoldingPeriodReturn() : void { $r = [0.01, 0.02, 0.03, 0.04]; @@ -62,6 +82,9 @@ class StockBondsTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(0.10355, StockBonds::getHoldingPeriodReturn($r), 0.01); } + /** + * @testdox The tax equivalent yield is calculated correctly + */ public function testTaxEquivalentYield() : void { $free = 0.15; @@ -70,6 +93,9 @@ class StockBondsTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(0.15789, StockBonds::getTaxEquivalentYield($free, $rate), 0.01); } + /** + * @testdox The net asset value is calculated correctly + */ public function testNetAssetValue() : void { $assets = 1000; @@ -79,6 +105,9 @@ class StockBondsTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(1.75, StockBonds::getNetAssetValue($assets, $liabilities, $shares), 0.01); } + /** + * @testdox The calculation of the present value of a stock with constant growth rate is correct + */ public function testPresentValueOfStockConstantGrowth() : void { $div = 500; @@ -88,6 +117,9 @@ class StockBondsTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(5000, StockBonds::getPresentValueOfStockConstantGrowth($div, $r, $g), 0.01); } + /** + * @testdox The total stock return including dividends and sales price is correct + */ public function testTotalStockReturn() : void { $p0 = 1000; @@ -97,6 +129,9 @@ class StockBondsTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(0.3, StockBonds::getTotalStockReturn($p0, $p1, $d), 0.01); } + /** + * @testdox The calculation of the yield of a bond is correct + */ public function testYieldToMaturity() : void { $c = 100; @@ -107,6 +142,9 @@ class StockBondsTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(0.1138, StockBonds::getYieldToMaturity($c, $f, $p, $n), 0.01); } + /** + * @testdox The calculation of value of the zero coupon bond is correct + */ public function testZeroCouponBondValue() : void { $f = 100; @@ -116,6 +154,9 @@ class StockBondsTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta(74.73, StockBonds::getZeroCouponBondValue($f, $r, $t), 0.01); } + /** + * @testdox The calculation of the yield of a zero coupon bond is correct + */ public function testZeroCouponBondEffectiveYield() : void { $f = 100; diff --git a/tests/DataStorage/Cache/CacheStatusTest.php b/tests/DataStorage/Cache/CacheStatusTest.php index 10544e276..d94cad7bd 100644 --- a/tests/DataStorage/Cache/CacheStatusTest.php +++ b/tests/DataStorage/Cache/CacheStatusTest.php @@ -21,6 +21,9 @@ use phpOMS\DataStorage\Cache\CacheStatus; */ class CacheStatusTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(4, CacheStatus::getConstants()); diff --git a/tests/DataStorage/Cache/CacheTypeTest.php b/tests/DataStorage/Cache/CacheTypeTest.php index af9ef190a..162e99719 100644 --- a/tests/DataStorage/Cache/CacheTypeTest.php +++ b/tests/DataStorage/Cache/CacheTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\DataStorage\Cache\CacheType; */ class CacheTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(4, CacheType::getConstants()); diff --git a/tests/DataStorage/Cache/Connection/CacheValueTypeTest.php b/tests/DataStorage/Cache/Connection/CacheValueTypeTest.php index 031592480..c4e9b89b5 100644 --- a/tests/DataStorage/Cache/Connection/CacheValueTypeTest.php +++ b/tests/DataStorage/Cache/Connection/CacheValueTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\DataStorage\Cache\Connection\CacheValueType; */ class CacheValueTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(8, CacheValueType::getConstants()); diff --git a/tests/DataStorage/Cache/Connection/FileCacheTest.php b/tests/DataStorage/Cache/Connection/FileCacheTest.php index ab8b20800..57a31eab5 100644 --- a/tests/DataStorage/Cache/Connection/FileCacheTest.php +++ b/tests/DataStorage/Cache/Connection/FileCacheTest.php @@ -26,104 +26,170 @@ use phpOMS\Utils\TestUtils; */ class FileCacheTest extends \PHPUnit\Framework\TestCase { - /** - * @testdox The file cache connection has the expected default values after initialization - */ - public function testDefault() : void + protected FileCache $cache; + + protected function setUp() : void { if (\file_exists(__DIR__ . '/Cache')) { \rmdir(__DIR__ . '/Cache'); } - $cache = new FileCache(__DIR__ . '/Cache'); + $this->cache = new FileCache(__DIR__ . '/Cache'); + } - self::assertEquals('', $cache->getPrefix()); - self::assertEquals(CacheType::FILE, $cache->getType()); - self::assertTrue(\is_dir(__DIR__ . '/Cache')); - self::assertTrue($cache->flushAll()); - self::assertEquals(50, $cache->getThreshold()); - self::assertNull($cache->get('test')); + protected function tearDown() : void + { + $this->cache->flushAll(); if (\file_exists(__DIR__ . '/Cache')) { \rmdir(__DIR__ . '/Cache'); } } + /** + * @testdox The file cache connection has the expected default values after initialization + */ + public function testDefault() : void + { + self::assertEquals('', $this->cache->getPrefix()); + self::assertEquals(CacheType::FILE, $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 dedicated cache directory can be established (none-exising directories get created) */ public function testConnect() : void { - if (\file_exists(__DIR__ . '/Cache')) { - \rmdir(__DIR__ . '/Cache'); - } - - $cache = new FileCache(__DIR__ . '/Cache'); - - self::assertEquals(CacheStatus::OK, $cache->getStatus()); - - if (\file_exists(__DIR__ . '/Cache')) { - \rmdir(__DIR__ . '/Cache'); - } + self::assertEquals(CacheStatus::OK, $this->cache->getStatus()); } - public function testGetSet() : void + /** + * @testdox Different cache data (types) can be set and returned + */ + public function testSetInputOutput() : void { - if (\file_exists(__DIR__ . '/Cache')) { - \rmdir(__DIR__ . '/Cache'); - } + $this->cache->set('key1', 'testVal'); + self::assertEquals('testVal', $this->cache->get('key1')); - $cache = new FileCache(__DIR__ . '/Cache'); + $this->cache->set('key2', false); + self::assertFalse($this->cache->get('key2')); - $cache->flushAll(); + $this->cache->set('key3', null); + self::assertNull($this->cache->get('key3')); - $cache->set('key1', 'testVal'); // 1 - self::assertEquals('testVal', $cache->get('key1')); + $this->cache->set('key4', 4); + self::assertEquals(4, $this->cache->get('key4')); - self::assertTrue($cache->add('addKey', 'testValAdd')); // 2 - self::assertFalse($cache->add('addKey', 'testValAdd2')); - self::assertEquals('testValAdd', $cache->get('addKey')); + $this->cache->set('key5', 5.12); + self::assertEquals(5.12, $this->cache->get('key5')); - $cache->set('key2', false); // 3 - self::assertFalse($cache->get('key2')); + $this->cache->set('key6', ['asdf', 1, true, 2.3]); + self::assertEquals(['asdf', 1, true, 2.3], $this->cache->get('key6')); - $cache->set('key3', null); // 4 - self::assertNull($cache->get('key3')); + $this->cache->set('key7', new FileCacheSerializable()); + self::assertEquals('abc', $this->cache->get('key7')->val); - $cache->set('key4', 4); // 5 - self::assertEquals(4, $cache->get('key4')); + $this->cache->set('key8', new FileCacheJsonSerializable()); + self::assertEquals('abc', $this->cache->get('key8')->val); + } - $cache->set('key5', 5.12); // 6 - self::assertEquals(5.12, $cache->get('key5')); + /** + * @testdox Cache data can bet added and returned + */ + public function testAddInputOutput() : void + { + self::assertTrue($this->cache->add('addKey', 'testValAdd')); + self::assertEquals('testValAdd', $this->cache->get('addKey')); + } - $cache->set('key6', ['asdf', 1, true, 2.3]); // 7 - self::assertEquals(['asdf', 1, true, 2.3], $cache->get('key6')); + /** + * @testdox Cache data cannot be added if it already exists + */ + 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')); + } - $cache->set('key7', new FileCacheSerializable()); // 8 - self::assertEquals('abc', $cache->get('key7')->val); + /** + * @testdox Existing cache data can be replaced + */ + public function testReplace() : void + { + $this->cache->set('key4', 4); + self::assertEquals(4, $this->cache->get('key4')); - $cache->set('key8', new FileCacheJsonSerializable()); // 9 - self::assertEquals('abc', $cache->get('key8')->val); + self::assertTrue($this->cache->replace('key4', 5)); + self::assertEquals(5, $this->cache->get('key4')); + } - self::assertTrue($cache->replace('key4', 5)); - self::assertFalse($cache->replace('keyInvalid', 5)); - self::assertEquals(5, $cache->get('key4')); + /** + * @testdox None-existing cache data cannot be replaced + */ + public function testInvalidReplace() : void + { + self::assertFalse($this->cache->replace('keyInvalid', 5)); + } - self::assertTrue($cache->delete('key4')); // 8 - self::assertTrue($cache->delete('keyInvalid')); - self::assertNull($cache->get('key4')); + /** + * @testdox Existing cache data can be deleted + */ + 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 + */ + 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' => 8, - 'size' => 220, + 'count' => 2, + 'size' => 17, ], - $cache->stats() + $this->cache->stats() ); + } - self::assertTrue($cache->flushAll()); - self::assertNull($cache->get('key5')); + /** + * @testdox The cache can be flushed + */ + 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( [ @@ -131,82 +197,103 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase 'count' => 0, 'size' => 0, ], - $cache->stats() + $this->cache->stats() ); - - if (\file_exists(__DIR__ . '/Cache')) { - \rmdir(__DIR__ . '/Cache'); - } } - public function testExpire() : void + /** + * @testdox Cache data can be set and returned with expiration limits + */ + public function testUnexpiredInputOutput() : void { - if (\file_exists(__DIR__ . '/Cache')) { - \rmdir(__DIR__ . '/Cache'); - } + $this->cache->set('key1', 'testVal', 1); + self::assertEquals('testVal', $this->cache->get('key1')); + } - $cache = new FileCache(__DIR__ . '/Cache'); + /** + * @testdox Expired cache data cannot be returned + */ + 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!!! + } - $cache->flushAll(); + /** + * @testdox Expired cache data can be forced to return + */ + public function testForceExpiredInputOutput() : void + { + $this->cache->set('key2', 'testVal2', 1); + \sleep(2); + self::assertEquals('testVal2', $this->cache->get('key2', 10)); + } - $cache->set('key1', 'testVal', 1); - self::assertEquals('testVal', $cache->get('key1')); + /** + * @testdox Unexpired cache data connot be delete if lower expiration is defined + */ + public function testInvalidDeleteUnexpired() : void + { + $this->cache->set('key4', 'testVal4', 1); + self::assertFalse($this->cache->delete('key4', 0)); + } - $cache->set('key2', 'testVal2', 1); - self::assertEquals('testVal2', $cache->get('key2', 1)); - \sleep(3); - self::assertNull($cache->get('key2', 1)); + /** + * @testdox Expired cache data can be deleted if equal expiration is defined + */ + public function testDeleteExpired() : void + { + $this->cache->set('key4', 'testVal4', 1); + \sleep(2); + self::assertTrue($this->cache->delete('key4', 1)); + } - $cache->set('key3', 'testVal3', 1); - self::assertEquals('testVal3', $cache->get('key3', 1)); - \sleep(3); - self::assertNull($cache->get('key3', 1)); + /** + * @testdox Unexpired data can be force deleted with lower expiration date + */ + 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)); + } - $cache->set('key4', 'testVal4', 1); - self::assertFalse($cache->delete('key4', 0)); - \sleep(3); - self::assertTrue($cache->delete('key4', 1)); - - $cache->set('key5', 'testVal5', 10000); - \sleep(3); - self::assertFalse($cache->delete('key5', 1000000)); - self::assertTrue($cache->delete('key5', 1)); - - $cache->set('key6', 'testVal6', 1); + /** + * @testdox Cach data can be flushed by expiration date + */ + public function testFlushExpired() : void + { + $this->cache->set('key6', 'testVal6', 1); \sleep(2); - $cache->flush(0); - - if (\file_exists(__DIR__ . '/Cache')) { - \rmdir(__DIR__ . '/Cache'); - } + $this->cache->flush(0); + self::assertNull($this->cache->get('key6', 0)); } + /** + * @testdox A bad cache status will prevent all cache actions + */ public function testBadCacheStatus() : void { - if (\file_exists(__DIR__ . '/Cache')) { - \rmdir(__DIR__ . '/Cache'); - } + TestUtils::setMember($this->cache, 'status', CacheStatus::FAILURE); - $cache = new FileCache(__DIR__ . '/Cache'); - $cache->flushAll(); - - 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()); - - if (\file_exists(__DIR__ . '/Cache')) { - \rmdir(__DIR__ . '/Cache'); - } + $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 cache connection will throw an InvalidConnectionConfigException + */ public function testInvalidCachePath() : void { self::expectException(\phpOMS\DataStorage\Cache\Exception\InvalidConnectionConfigException::class); @@ -214,11 +301,14 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase $cache = new FileCache('/etc/invalidPathOrPermission^$:?><'); } + /** + * @testdox A invalid data type will throw an InvalidArgumentException + */ public function testInvalidDataType() : void { self::expectException(\InvalidArgumentException::class); - $cache = new FileCache(__DIR__ . '/Cache'); - $cache->add('invalid', $cache); + $this->cache->add('invalid', $this->cache); + } } diff --git a/tests/DataStorage/Database/DataMapperAbstractTest.php b/tests/DataStorage/Database/DataMapperAbstractTest.php index b7c6b1ea1..d895a9434 100644 --- a/tests/DataStorage/Database/DataMapperAbstractTest.php +++ b/tests/DataStorage/Database/DataMapperAbstractTest.php @@ -147,6 +147,9 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase $GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_has_many_rel_relations')->execute(); } + /** + * @covers phpOMS\DataStorage\Database\DataMapperAbstract + */ public function testDefault() : void { self::assertEquals('test_base_id', BaseModelMapper::getPrimaryField()); @@ -154,18 +157,27 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase self::assertEquals('test_base_datetime', BaseModelMapper::getCreatedAt()); } + /** + * @covers phpOMS\DataStorage\Database\DataMapperAbstract + */ public function testCreate() : void { self::assertGreaterThan(0, BaseModelMapper::create($this->model)); self::assertGreaterThan(0, $this->model->id); } + /** + * @covers phpOMS\DataStorage\Database\DataMapperAbstract + */ public function testCreateArray() : void { self::assertGreaterThan(0, BaseModelMapper::createArray($this->modelArray)); self::assertGreaterThan(0, $this->modelArray['id']); } + /** + * @covers phpOMS\DataStorage\Database\DataMapperAbstract + */ public function testRead() : void { $id = BaseModelMapper::create($this->model); @@ -198,6 +210,9 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase self::assertCount(1, BaseModelMapper::getAll()); } + /** + * @covers phpOMS\DataStorage\Database\DataMapperAbstract + */ public function testReadArray() : void { $id = BaseModelMapper::createArray($this->modelArray); @@ -225,6 +240,9 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase self::assertCount(1, BaseModelMapper::getAllArray()); } + /** + * @covers phpOMS\DataStorage\Database\DataMapperAbstract + */ public function testUpdate() : void { $id = BaseModelMapper::create($this->model); @@ -252,6 +270,9 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase // todo test update relations } + /** + * @covers phpOMS\DataStorage\Database\DataMapperAbstract + */ public function testUpdateArray() : void { $id = BaseModelMapper::createArray($this->modelArray); @@ -279,6 +300,9 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase // todo test update relations } + /** + * @covers phpOMS\DataStorage\Database\DataMapperAbstract + */ public function testDelete() : void { $id = BaseModelMapper::create($this->model); diff --git a/tests/DataStorage/Database/DatabaseStatusTest.php b/tests/DataStorage/Database/DatabaseStatusTest.php index 187572016..216d25221 100644 --- a/tests/DataStorage/Database/DatabaseStatusTest.php +++ b/tests/DataStorage/Database/DatabaseStatusTest.php @@ -21,6 +21,9 @@ use phpOMS\DataStorage\Database\DatabaseStatus; */ class DatabaseStatusTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(6, DatabaseStatus::getConstants()); diff --git a/tests/DataStorage/Database/DatabaseTypeTest.php b/tests/DataStorage/Database/DatabaseTypeTest.php index be8dd3a5f..2ed64ee74 100644 --- a/tests/DataStorage/Database/DatabaseTypeTest.php +++ b/tests/DataStorage/Database/DatabaseTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\DataStorage\Database\DatabaseType; */ class DatabaseTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(5, DatabaseType::getConstants()); diff --git a/tests/DataStorage/Database/Query/JoinTypeTest.php b/tests/DataStorage/Database/Query/JoinTypeTest.php index 11abc9c8d..0ad24f301 100644 --- a/tests/DataStorage/Database/Query/JoinTypeTest.php +++ b/tests/DataStorage/Database/Query/JoinTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\DataStorage\Database\Query\JoinType; */ class JoinTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(12, JoinType::getConstants()); diff --git a/tests/DataStorage/Database/Query/QueryTypeTest.php b/tests/DataStorage/Database/Query/QueryTypeTest.php index ea6f375de..9781dd522 100644 --- a/tests/DataStorage/Database/Query/QueryTypeTest.php +++ b/tests/DataStorage/Database/Query/QueryTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\DataStorage\Database\Query\QueryType; */ class QueryTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(7, QueryType::getConstants()); diff --git a/tests/DataStorage/Database/RelationTypeTest.php b/tests/DataStorage/Database/RelationTypeTest.php index e968a3ba8..d2d3bd820 100644 --- a/tests/DataStorage/Database/RelationTypeTest.php +++ b/tests/DataStorage/Database/RelationTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\DataStorage\Database\RelationType; */ class RelationTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(7, RelationType::getConstants()); diff --git a/tests/DataStorage/Database/Schema/QueryTypeTest.php b/tests/DataStorage/Database/Schema/QueryTypeTest.php index c95f727c4..fa147db22 100644 --- a/tests/DataStorage/Database/Schema/QueryTypeTest.php +++ b/tests/DataStorage/Database/Schema/QueryTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\DataStorage\Database\Schema\QueryType; */ class QueryTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(13, QueryType::getConstants()); diff --git a/tests/Localization/ISO3166CharEnumTest.php b/tests/Localization/ISO3166CharEnumTest.php index b5d8b4df8..09b5ee898 100644 --- a/tests/Localization/ISO3166CharEnumTest.php +++ b/tests/Localization/ISO3166CharEnumTest.php @@ -23,6 +23,9 @@ use phpOMS\Localization\ISO3166CharEnum; */ class ISO3166CharEnumTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { $ok = true; diff --git a/tests/Localization/ISO3166NameEnumTest.php b/tests/Localization/ISO3166NameEnumTest.php index 96de71612..5ab8a29f8 100644 --- a/tests/Localization/ISO3166NameEnumTest.php +++ b/tests/Localization/ISO3166NameEnumTest.php @@ -23,6 +23,9 @@ use phpOMS\Localization\ISO3166NameEnum; */ class ISO3166NameEnumTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { $enum = ISO3166NameEnum::getConstants(); diff --git a/tests/Localization/ISO3166NumEnumTest.php b/tests/Localization/ISO3166NumEnumTest.php index 178bf2995..9ccb30221 100644 --- a/tests/Localization/ISO3166NumEnumTest.php +++ b/tests/Localization/ISO3166NumEnumTest.php @@ -23,6 +23,9 @@ use phpOMS\Localization\ISO3166NumEnum; */ class ISO3166NumEnumTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { $ok = true; diff --git a/tests/Localization/ISO3166TwoEnumTest.php b/tests/Localization/ISO3166TwoEnumTest.php index b15448e57..b5eabd8fc 100644 --- a/tests/Localization/ISO3166TwoEnumTest.php +++ b/tests/Localization/ISO3166TwoEnumTest.php @@ -23,6 +23,9 @@ use phpOMS\Localization\ISO3166TwoEnum; */ class ISO3166TwoEnumTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { $ok = true; diff --git a/tests/Localization/ISO4217CharEnumTest.php b/tests/Localization/ISO4217CharEnumTest.php index 04af32660..e0188ca99 100644 --- a/tests/Localization/ISO4217CharEnumTest.php +++ b/tests/Localization/ISO4217CharEnumTest.php @@ -23,6 +23,9 @@ use phpOMS\Localization\ISO4217CharEnum; */ class ISO4217CharEnumTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { $ok = true; diff --git a/tests/Localization/ISO4217DecimalEnumTest.php b/tests/Localization/ISO4217DecimalEnumTest.php index 462b0fe2c..02f08609c 100644 --- a/tests/Localization/ISO4217DecimalEnumTest.php +++ b/tests/Localization/ISO4217DecimalEnumTest.php @@ -23,6 +23,9 @@ use phpOMS\Localization\ISO4217DecimalEnum; */ class ISO4217DecimalEnumTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { $ok = true; diff --git a/tests/Localization/ISO4217EnumTest.php b/tests/Localization/ISO4217EnumTest.php index 5180af842..608819a15 100644 --- a/tests/Localization/ISO4217EnumTest.php +++ b/tests/Localization/ISO4217EnumTest.php @@ -23,6 +23,9 @@ use phpOMS\Localization\ISO4217Enum; */ class ISO4217EnumTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { $enum = ISO4217Enum::getConstants(); diff --git a/tests/Localization/ISO4217NumEnumTest.php b/tests/Localization/ISO4217NumEnumTest.php index 9b2a1f09b..f86dd6af2 100644 --- a/tests/Localization/ISO4217NumEnumTest.php +++ b/tests/Localization/ISO4217NumEnumTest.php @@ -23,6 +23,9 @@ use phpOMS\Localization\ISO4217NumEnum; */ class ISO4217NumEnumTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { $ok = true; diff --git a/tests/Localization/ISO4217SubUnitEnumTest.php b/tests/Localization/ISO4217SubUnitEnumTest.php index 2662c0665..8af9b5ddb 100644 --- a/tests/Localization/ISO4217SubUnitEnumTest.php +++ b/tests/Localization/ISO4217SubUnitEnumTest.php @@ -23,6 +23,9 @@ use phpOMS\Localization\ISO4217SubUnitEnum; */ class ISO4217SubUnitEnumTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { $ok = true; diff --git a/tests/Localization/ISO639EnumTest.php b/tests/Localization/ISO639EnumTest.php index 28a0ec83e..bda79ee6e 100644 --- a/tests/Localization/ISO639EnumTest.php +++ b/tests/Localization/ISO639EnumTest.php @@ -23,6 +23,9 @@ use phpOMS\Localization\ISO639Enum; */ class ISO639EnumTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { $enum = ISO639Enum::getConstants(); diff --git a/tests/Localization/ISO639x1EnumTest.php b/tests/Localization/ISO639x1EnumTest.php index 670a28dc4..ea6214264 100644 --- a/tests/Localization/ISO639x1EnumTest.php +++ b/tests/Localization/ISO639x1EnumTest.php @@ -23,6 +23,9 @@ use phpOMS\Localization\ISO639x1Enum; */ class ISO639x1EnumTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { $ok = true; diff --git a/tests/Localization/ISO639x2EnumTest.php b/tests/Localization/ISO639x2EnumTest.php index efe9043d9..83e4a19db 100644 --- a/tests/Localization/ISO639x2EnumTest.php +++ b/tests/Localization/ISO639x2EnumTest.php @@ -23,6 +23,9 @@ use phpOMS\Localization\ISO639x2Enum; */ class ISO639x2EnumTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { $ok = true; diff --git a/tests/Localization/ISO8601EnumArrayTest.php b/tests/Localization/ISO8601EnumArrayTest.php index 6cb1618fa..7529de7be 100644 --- a/tests/Localization/ISO8601EnumArrayTest.php +++ b/tests/Localization/ISO8601EnumArrayTest.php @@ -23,6 +23,9 @@ use phpOMS\Localization\ISO8601EnumArray; */ class ISO8601EnumArrayTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(4, ISO8601EnumArray::getConstants()); diff --git a/tests/Localization/PhoneEnumTest.php b/tests/Localization/PhoneEnumTest.php index 079ab0759..4526a86fd 100644 --- a/tests/Localization/PhoneEnumTest.php +++ b/tests/Localization/PhoneEnumTest.php @@ -23,6 +23,9 @@ use phpOMS\Localization\PhoneEnum; */ class PhoneEnumTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { $ok = true; diff --git a/tests/Localization/TimeZoneEnumArrayTest.php b/tests/Localization/TimeZoneEnumArrayTest.php index 183ea61f4..cc9d42236 100644 --- a/tests/Localization/TimeZoneEnumArrayTest.php +++ b/tests/Localization/TimeZoneEnumArrayTest.php @@ -23,6 +23,9 @@ use phpOMS\Localization\TimeZoneEnumArray; */ class TimeZoneEnumArrayTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertEquals(\count(TimeZoneEnumArray::getConstants()), \count(\array_unique(TimeZoneEnumArray::getConstants()))); diff --git a/tests/Log/LogLevelTest.php b/tests/Log/LogLevelTest.php index 1548d424e..cecff06ed 100644 --- a/tests/Log/LogLevelTest.php +++ b/tests/Log/LogLevelTest.php @@ -23,6 +23,9 @@ use phpOMS\Log\LogLevel; */ class LogLevelTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(8, LogLevel::getConstants()); diff --git a/tests/Math/Number/NumberTypeTest.php b/tests/Math/Number/NumberTypeTest.php index 0d5ff2cec..a082f221b 100644 --- a/tests/Math/Number/NumberTypeTest.php +++ b/tests/Math/Number/NumberTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Math\Number\NumberType; */ class NumberTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(9, NumberType::getConstants()); diff --git a/tests/Message/Http/BrowserTypeTest.php b/tests/Message/Http/BrowserTypeTest.php index a43e81064..9ff043a19 100644 --- a/tests/Message/Http/BrowserTypeTest.php +++ b/tests/Message/Http/BrowserTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Message\Http\BrowserType; */ class BrowserTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertEquals(12, BrowserType::count()); diff --git a/tests/Message/Http/OSTypeTest.php b/tests/Message/Http/OSTypeTest.php index 013ea750e..9112fdf53 100644 --- a/tests/Message/Http/OSTypeTest.php +++ b/tests/Message/Http/OSTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Message\Http\OSType; */ class OSTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(24, OSType::getConstants()); diff --git a/tests/Message/Http/RequestMethodTest.php b/tests/Message/Http/RequestMethodTest.php index 4b53cf20b..757a333ca 100644 --- a/tests/Message/Http/RequestMethodTest.php +++ b/tests/Message/Http/RequestMethodTest.php @@ -21,6 +21,9 @@ use phpOMS\Message\Http\RequestMethod; */ class RequestMethodTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(6, RequestMethod::getConstants()); diff --git a/tests/Message/Http/RequestStatusCodeTest.php b/tests/Message/Http/RequestStatusCodeTest.php index d24b3eaca..9168adc2a 100644 --- a/tests/Message/Http/RequestStatusCodeTest.php +++ b/tests/Message/Http/RequestStatusCodeTest.php @@ -21,6 +21,9 @@ use phpOMS\Message\Http\RequestStatusCode; */ class RequestStatusCodeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(55, RequestStatusCode::getConstants()); diff --git a/tests/Message/Http/RequestStatusTest.php b/tests/Message/Http/RequestStatusTest.php index 017658131..36efca869 100644 --- a/tests/Message/Http/RequestStatusTest.php +++ b/tests/Message/Http/RequestStatusTest.php @@ -21,6 +21,9 @@ use phpOMS\Message\Http\RequestStatus; */ class RequestStatusTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(55, RequestStatus::getConstants()); diff --git a/tests/Message/Socket/PacketTypeTest.php b/tests/Message/Socket/PacketTypeTest.php index 07461d47f..56bbf64aa 100644 --- a/tests/Message/Socket/PacketTypeTest.php +++ b/tests/Message/Socket/PacketTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Message\Socket\PacketType; */ class PacketTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(11, PacketType::getConstants()); diff --git a/tests/Model/Message/DomActionTest.php b/tests/Model/Message/DomActionTest.php index 6470591c2..f5ac19b46 100644 --- a/tests/Model/Message/DomActionTest.php +++ b/tests/Model/Message/DomActionTest.php @@ -21,6 +21,9 @@ use phpOMS\Model\Message\DomAction; */ class DomActionTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(9, DomAction::getConstants()); diff --git a/tests/Model/Message/NotifyTypeTest.php b/tests/Model/Message/NotifyTypeTest.php index 06a522b5c..7b8f62646 100644 --- a/tests/Model/Message/NotifyTypeTest.php +++ b/tests/Model/Message/NotifyTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Model\Message\NotifyType; */ class NotifyTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(5, NotifyType::getConstants()); diff --git a/tests/Module/PackageManagerTest.php b/tests/Module/PackageManagerTest.php index bb5fbf12c..1d7c35b85 100644 --- a/tests/Module/PackageManagerTest.php +++ b/tests/Module/PackageManagerTest.php @@ -90,7 +90,7 @@ class PackageManagerTest extends \PHPUnit\Framework\TestCase $package = new PackageManager( __DIR__ . '/testPackage.zip', - __DIR__ . 'dummyModule/', + __DIR__ . '/dummyModule/', \file_get_contents(__DIR__ . '/public.key') ); @@ -101,6 +101,33 @@ class PackageManagerTest extends \PHPUnit\Framework\TestCase $package->load(); $package->install(); + self::assertGreaterThan(100, \filesize(__DIR__ . '/dummyModule/README.md')); + self::assertEquals('To copy!', \file_get_contents(__DIR__ . '/dummyModule/Replace.md')); + + self::assertFalse(\file_exists(__DIR__ . '/dummyModule/toMove')); + self::assertTrue(\file_exists(__DIR__ . '/dummyModule/moveHere')); + self::assertTrue(\file_exists(__DIR__ . '/dummyModule/moveHere/a.md')); + self::assertTrue(\file_exists(__DIR__ . '/dummyModule/moveHere/sub/b.txt')); + + self::assertTrue(\file_exists(__DIR__ . '/dummyModule/externalCopy.md')); + + self::assertTrue(\file_exists(__DIR__ . '/dummyModule/toCopy')); + self::assertTrue(\file_exists(__DIR__ . '/dummyModule/copyHere')); + self::assertTrue(\file_exists(__DIR__ . '/dummyModule/copyHere/a.md')); + self::assertTrue(\file_exists(__DIR__ . '/dummyModule/copyHere/sub/b.txt')); + + self::assertFalse(\file_exists(__DIR__ . '/dummyModule/Remove')); + + \sleep(1); + + self::assertEquals('php script', \file_get_contents(__DIR__ . '/dummyModule/phpscript.md')); + + if (\is_executable(__DIR__ . '/testPackageExtracted/testSubPackage/run.sh') + && \is_executable(__DIR__ . '/testPackageExtracted/testSubPackage/run.batch') + ) { + self::assertEquals('cmd script', \file_get_contents(__DIR__ . '/dummyModule/cmdscript.md')); + } + if (\file_exists(__DIR__ . '/dummyModule')) { Directory::delete(__DIR__ . '/dummyModule'); } @@ -119,6 +146,19 @@ class PackageManagerTest extends \PHPUnit\Framework\TestCase $package->load(); } + public function testInvalidInstall() : void + { + self::expectException(\Exception::class); + + $package = new PackageManager( + __DIR__ . '/testPackage.zip', + '/invalid', + \file_get_contents(__DIR__ . '/public.key') . ' ' + ); + + $package->install(); + } + public function testPackageInvalidKey() : void { $package = new PackageManager( diff --git a/tests/Module/testPackage/info.json b/tests/Module/testPackage/info.json index be72f6d10..fd504380f 100644 --- a/tests/Module/testPackage/info.json +++ b/tests/Module/testPackage/info.json @@ -13,15 +13,19 @@ "copy": { "toCopy": [ "copyHere" + ], + "/Package/testSubPackage/externalCopy.md": [ + "externalCopy.md", + "Replace.md" ] }, "delete": [ "Remove" ], "cmd": [ - "/Package/run.php", - "/Package/run.sh", - "/Package/run.batch" + "/Package/testSubPackage/run.php", + "/Package/testSubPackage/run.sh", + "/Package/testSubPackage/run.batch" ] } ] diff --git a/tests/Module/testPackage/testSubPackage/externalCopy.md b/tests/Module/testPackage/testSubPackage/externalCopy.md new file mode 100644 index 000000000..85d44f7ea --- /dev/null +++ b/tests/Module/testPackage/testSubPackage/externalCopy.md @@ -0,0 +1 @@ +To copy! \ No newline at end of file diff --git a/tests/Module/testPackage/testSubPackage/run.php b/tests/Module/testPackage/testSubPackage/run.php index e69de29bb..0cce77f25 100644 --- a/tests/Module/testPackage/testSubPackage/run.php +++ b/tests/Module/testPackage/testSubPackage/run.php @@ -0,0 +1 @@ + $BASEDIR/../../dummyModule/cmdscript.md \ No newline at end of file diff --git a/tests/Socket/Client/ClientTest.php b/tests/Socket/Client/ClientTest.php index 2098d4a3f..9a5ea6b54 100644 --- a/tests/Socket/Client/ClientTest.php +++ b/tests/Socket/Client/ClientTest.php @@ -103,5 +103,11 @@ class ClientTest extends \PHPUnit\Framework\TestCase . 'Is shutdown...' . "\n", \file_get_contents(__DIR__ . '/server.log') ); + + foreach ($pipes as $pipe) { + \fclose($pipe); + } + + \proc_close($process); } } diff --git a/tests/Socket/Server/ServerTest.php b/tests/Socket/Server/ServerTest.php index e8a55a201..0ee5238fe 100644 --- a/tests/Socket/Server/ServerTest.php +++ b/tests/Socket/Server/ServerTest.php @@ -103,5 +103,11 @@ class ServerTest extends \PHPUnit\Framework\TestCase self::assertStringContainsString('Sending: handshake', $client); self::assertStringContainsString('Sending: help', $client); self::assertStringContainsString('Sending: shutdown', $client); + + foreach ($pipes as $pipe) { + \fclose($pipe); + } + + \proc_close($process); } } diff --git a/tests/Stdlib/Base/AddressTypeTest.php b/tests/Stdlib/Base/AddressTypeTest.php index ddacf6bf6..ed3b2679d 100644 --- a/tests/Stdlib/Base/AddressTypeTest.php +++ b/tests/Stdlib/Base/AddressTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Stdlib\Base\AddressType; */ class AddressTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(7, AddressType::getconstants()); diff --git a/tests/Stdlib/Base/PhoneTypeTest.php b/tests/Stdlib/Base/PhoneTypeTest.php index efa745b35..af6a5ae07 100644 --- a/tests/Stdlib/Base/PhoneTypeTest.php +++ b/tests/Stdlib/Base/PhoneTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Stdlib\Base\PhoneType; */ class PhoneTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(4, PhoneType::getConstants()); diff --git a/tests/Stdlib/Map/KeyTypeTest.php b/tests/Stdlib/Map/KeyTypeTest.php index cd0264890..2c89435aa 100644 --- a/tests/Stdlib/Map/KeyTypeTest.php +++ b/tests/Stdlib/Map/KeyTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Stdlib\Map\KeyType; */ class KeyTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(2, KeyType::getConstants()); diff --git a/tests/Stdlib/Map/OrderTypeTest.php b/tests/Stdlib/Map/OrderTypeTest.php index 7f85769fa..4a98525a1 100644 --- a/tests/Stdlib/Map/OrderTypeTest.php +++ b/tests/Stdlib/Map/OrderTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Stdlib\Map\OrderType; */ class OrderTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(2, OrderType::getConstants()); diff --git a/tests/Stdlib/Queue/PriorityModeTest.php b/tests/Stdlib/Queue/PriorityModeTest.php index d852b13b9..2acb0ba05 100644 --- a/tests/Stdlib/Queue/PriorityModeTest.php +++ b/tests/Stdlib/Queue/PriorityModeTest.php @@ -21,6 +21,9 @@ use phpOMS\Stdlib\Queue\PriorityMode; */ class PriorityModeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(4, PriorityMode::getConstants()); diff --git a/tests/System/File/ContentPutModeTest.php b/tests/System/File/ContentPutModeTest.php index 2270a08b4..870399f77 100644 --- a/tests/System/File/ContentPutModeTest.php +++ b/tests/System/File/ContentPutModeTest.php @@ -21,6 +21,9 @@ use phpOMS\System\File\ContentPutMode; */ class ContentPutModeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(4, ContentPutMode::getConstants()); diff --git a/tests/System/File/ExtensionTypeTest.php b/tests/System/File/ExtensionTypeTest.php index 88473531c..91913fad9 100644 --- a/tests/System/File/ExtensionTypeTest.php +++ b/tests/System/File/ExtensionTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\System\File\ExtensionType; */ class ExtensionTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(13, ExtensionType::getConstants()); diff --git a/tests/System/SystemTypeTest.php b/tests/System/SystemTypeTest.php index 778883f80..6a435136a 100644 --- a/tests/System/SystemTypeTest.php +++ b/tests/System/SystemTypeTest.php @@ -23,6 +23,9 @@ use phpOMS\System\SystemType; */ class SystemTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(4, SystemType::getConstants()); diff --git a/tests/Utils/Barcode/OrientationTypeTest.php b/tests/Utils/Barcode/OrientationTypeTest.php index 0d465de53..46590c04b 100644 --- a/tests/Utils/Barcode/OrientationTypeTest.php +++ b/tests/Utils/Barcode/OrientationTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Utils\Barcode\OrientationType; */ class OrientationTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(2, OrientationType::getConstants()); diff --git a/tests/Utils/Converter/AngleTypeTest.php b/tests/Utils/Converter/AngleTypeTest.php index 4f8c7d0e4..78e98a8b0 100644 --- a/tests/Utils/Converter/AngleTypeTest.php +++ b/tests/Utils/Converter/AngleTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Utils\Converter\AngleType; */ class AngleTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(10, AngleType::getConstants()); diff --git a/tests/Utils/Converter/AreaTypeTest.php b/tests/Utils/Converter/AreaTypeTest.php index 482ec7d8d..adf1418d0 100644 --- a/tests/Utils/Converter/AreaTypeTest.php +++ b/tests/Utils/Converter/AreaTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Utils\Converter\AreaType; */ class AreaTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(13, AreaType::getConstants()); diff --git a/tests/Utils/Converter/EnergyPowerTypeTest.php b/tests/Utils/Converter/EnergyPowerTypeTest.php index 052c3810c..87def4265 100644 --- a/tests/Utils/Converter/EnergyPowerTypeTest.php +++ b/tests/Utils/Converter/EnergyPowerTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Utils\Converter\EnergyPowerType; */ class EnergyPowerTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(9, EnergyPowerType::getConstants()); diff --git a/tests/Utils/Converter/FileSizeTypeTest.php b/tests/Utils/Converter/FileSizeTypeTest.php index 6052fc90d..d47e5428d 100644 --- a/tests/Utils/Converter/FileSizeTypeTest.php +++ b/tests/Utils/Converter/FileSizeTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Utils\Converter\FileSizeType; */ class FileSizeTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(10, FileSizeType::getConstants()); diff --git a/tests/Utils/Converter/LengthTypeTest.php b/tests/Utils/Converter/LengthTypeTest.php index 0bdde56ff..15d21700d 100644 --- a/tests/Utils/Converter/LengthTypeTest.php +++ b/tests/Utils/Converter/LengthTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Utils\Converter\LengthType; */ class LengthTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(21, LengthType::getConstants()); diff --git a/tests/Utils/Converter/PressureTypeTest.php b/tests/Utils/Converter/PressureTypeTest.php index e65e1e956..5115b35ee 100644 --- a/tests/Utils/Converter/PressureTypeTest.php +++ b/tests/Utils/Converter/PressureTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Utils\Converter\PressureType; */ class PressureTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(13, PressureType::getConstants()); diff --git a/tests/Utils/Converter/SpeedTypeTest.php b/tests/Utils/Converter/SpeedTypeTest.php index f56cf3bad..1fc439387 100644 --- a/tests/Utils/Converter/SpeedTypeTest.php +++ b/tests/Utils/Converter/SpeedTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Utils\Converter\SpeedType; */ class SpeedTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(34, SpeedType::getConstants()); diff --git a/tests/Utils/Converter/TemperatureTypeTest.php b/tests/Utils/Converter/TemperatureTypeTest.php index 820d4e0bf..26422b64b 100644 --- a/tests/Utils/Converter/TemperatureTypeTest.php +++ b/tests/Utils/Converter/TemperatureTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Utils\Converter\TemperatureType; */ class TemperatureTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(8, TemperatureType::getConstants()); diff --git a/tests/Utils/Converter/TimeTypeTest.php b/tests/Utils/Converter/TimeTypeTest.php index 4512fa37e..bfe8a98d8 100644 --- a/tests/Utils/Converter/TimeTypeTest.php +++ b/tests/Utils/Converter/TimeTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Utils\Converter\TimeType; */ class TimeTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(9, TimeType::getConstants()); diff --git a/tests/Utils/Converter/VolumeTypeTest.php b/tests/Utils/Converter/VolumeTypeTest.php index 9330777ef..445f36b41 100644 --- a/tests/Utils/Converter/VolumeTypeTest.php +++ b/tests/Utils/Converter/VolumeTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Utils\Converter\VolumeType; */ class VolumeTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(38, VolumeType::getConstants()); diff --git a/tests/Utils/Converter/WeightTypeTest.php b/tests/Utils/Converter/WeightTypeTest.php index e803b7178..9b895d6d5 100644 --- a/tests/Utils/Converter/WeightTypeTest.php +++ b/tests/Utils/Converter/WeightTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Utils\Converter\WeightType; */ class WeightTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(14, WeightType::getConstants()); diff --git a/tests/Utils/Encoding/CaesarTest.php b/tests/Utils/Encoding/CaesarTest.php index 050e446b9..db556bbcf 100644 --- a/tests/Utils/Encoding/CaesarTest.php +++ b/tests/Utils/Encoding/CaesarTest.php @@ -22,6 +22,9 @@ use phpOMS\Utils\RnG\StringUtils; */ class CaesarTest extends \PHPUnit\Framework\TestCase { + /** + * @covers phpOMS\Utils\Encoding\Caesar + */ public function testVolume() : void { for ($i = 0; $i < 100; ++$i) { diff --git a/tests/Utils/Encoding/GrayTest.php b/tests/Utils/Encoding/GrayTest.php index 1956f82c9..680df04d8 100644 --- a/tests/Utils/Encoding/GrayTest.php +++ b/tests/Utils/Encoding/GrayTest.php @@ -21,12 +21,18 @@ use phpOMS\Utils\Encoding\Gray; */ class GrayTest extends \PHPUnit\Framework\TestCase { + /** + * @covers phpOMS\Utils\Encoding\Gray + */ public function testEncoding() : void { self::assertEquals(55, Gray::encode(37)); self::assertEquals(37, Gray::decode(55)); } + /** + * @covers phpOMS\Utils\Encoding\Gray + */ public function testVolume() : void { for ($i = 0; $i < 100; ++$i) { diff --git a/tests/Utils/IO/Excel/ExcelDatabaseMapperTest.php b/tests/Utils/IO/Excel/ExcelDatabaseMapperTest.php index 0626eb1ab..6a335e3ad 100644 --- a/tests/Utils/IO/Excel/ExcelDatabaseMapperTest.php +++ b/tests/Utils/IO/Excel/ExcelDatabaseMapperTest.php @@ -53,6 +53,9 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase } } + /** + * @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper + */ public function testInsertOds() : void { Autoloader::addPath(__DIR__ . '/../../../../../Resources/'); @@ -84,6 +87,9 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase ); } + /** + * @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper::insert + */ public function testInsertXls() : void { $mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/insert.xls'); @@ -114,6 +120,9 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase ); } + /** + * @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper::insert + */ public function testInsertXlsx() : void { $mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/insert.xlsx'); @@ -144,6 +153,9 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase ); } + /** + * @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper::update + */ public function testUpdateOds() : void { $mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/insert.ods'); @@ -201,6 +213,9 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase ); } + /** + * @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper::update + */ public function testUpdateXls() : void { $mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/insert.xls'); @@ -258,6 +273,9 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase ); } + /** + * @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper::update + */ public function testUpdateXlsx() : void { $mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/insert.xlsx'); @@ -315,6 +333,9 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase ); } + /** + * @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper::select + */ public function testSelectOds() : void { if (\file_exists(__DIR__ . '/select.ods')) { @@ -362,6 +383,9 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase } } + /** + * @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper::select + */ public function testSelectXls() : void { if (\file_exists(__DIR__ . '/select.xls')) { @@ -409,6 +433,9 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase } } + /** + * @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper::select + */ public function testSelectXlsx() : void { if (\file_exists(__DIR__ . '/select.xlsx')) { @@ -456,6 +483,9 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase } } + /** + * @coversNothing + */ private function compareSelectInsertSheet(string $pathSelect, string $pathInsert) : bool { $reader1 = null; diff --git a/tests/Utils/RnG/DistributionTypeTest.php b/tests/Utils/RnG/DistributionTypeTest.php index 03031eec9..a8df8306f 100644 --- a/tests/Utils/RnG/DistributionTypeTest.php +++ b/tests/Utils/RnG/DistributionTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Utils\RnG\DistributionType; */ class DistributionTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(2, DistributionType::getConstants()); diff --git a/tests/Utils/RnG/StringUtilsTest.php b/tests/Utils/RnG/StringUtilsTest.php index 2db6e8c78..ac2fd0739 100644 --- a/tests/Utils/RnG/StringUtilsTest.php +++ b/tests/Utils/RnG/StringUtilsTest.php @@ -30,7 +30,7 @@ class StringUtilsTest extends \PHPUnit\Framework\TestCase $outOfBounds = false; $randomness = 0; - for ($i = 0; $i < 10000; ++$i) { + for ($i = 0; $i < 1000; ++$i) { $random = StringUtils::generateString(5, 12, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_?><|;"'); if (\strlen($random) > 12 || \strlen($random) < 5) { diff --git a/tests/Validation/Finance/IbanEnumTest.php b/tests/Validation/Finance/IbanEnumTest.php index 14803db03..13fdf993a 100644 --- a/tests/Validation/Finance/IbanEnumTest.php +++ b/tests/Validation/Finance/IbanEnumTest.php @@ -21,6 +21,9 @@ use phpOMS\Validation\Finance\IbanEnum; */ class IbanEnumTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { $enums = IbanEnum::getConstants(); diff --git a/tests/Validation/Finance/IbanErrorTypeTest.php b/tests/Validation/Finance/IbanErrorTypeTest.php index 4c17ede72..758bfb8c1 100644 --- a/tests/Validation/Finance/IbanErrorTypeTest.php +++ b/tests/Validation/Finance/IbanErrorTypeTest.php @@ -21,6 +21,9 @@ use phpOMS\Validation\Finance\IbanErrorType; */ class IbanErrorTypeTest extends \PHPUnit\Framework\TestCase { + /** + * @coversNothing + */ public function testEnums() : void { self::assertCount(5, IbanErrorType::getConstants()); diff --git a/tests/Views/ViewTest.php b/tests/Views/ViewTest.php index 75826648e..e0317e975 100644 --- a/tests/Views/ViewTest.php +++ b/tests/Views/ViewTest.php @@ -119,9 +119,9 @@ class ViewTest extends \PHPUnit\Framework\TestCase $tView = new View(); self::assertTrue($view->addView('test', $tView)); - self::assertTrue($view->addView('test', $tView, 0, true)); + self::assertTrue($view->addView('test', $tView, true)); self::assertFalse($view->addView('test', $tView)); - self::assertFalse($view->addView('test', $tView, 0, false)); + self::assertFalse($view->addView('test', $tView, false)); } public function testRender() : void @@ -151,7 +151,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase $view2 = new View(); $view2->setTemplate('/phpOMS/tests/Views/testTemplate'); - $view->addView('sub', $view2, 1); + $view->addView('sub', $view2); self::assertEquals([ 0 => 'Test', 'sub' => ['Test'],