improve tests

This commit is contained in:
Dennis Eichhorn 2019-11-24 10:52:03 +01:00
parent 86f77e0a5e
commit 1a74834831
60 changed files with 1575 additions and 396 deletions

View File

@ -231,7 +231,7 @@ class SmartDateTime extends \DateTime
*
* @since 1.0.0
*/
public static function getDayOfWeek(int $y, int $m, int $d) : int
public static function dayOfWeek(int $y, int $m, int $d) : int
{
$time = \strtotime($d . '-' . $m . '-' . $y);
@ -249,9 +249,9 @@ class SmartDateTime extends \DateTime
*
* @since 1.0.0
*/
public function getFirstDayOfWeek() : int
public function getDayOfWeek() : int
{
return self::getDayOfWeek((int) $this->format('Y'), (int) $this->format('m'), (int) $this->format('d'));
return self::dayOfWeek((int) $this->format('Y'), (int) $this->format('m'), (int) $this->format('d'));
}
/**

View File

@ -84,16 +84,36 @@ class MultiMap implements \Countable
*
* @since 1.0.0
*/
public function add(array $keys, $value, bool $overwrite = true) : bool
public function add(array $keys, $value, bool $overwrite = false) : bool
{
$id = \count($this->values);
$inserted = false;
$id = \count($this->values);
$inserted = false;
$keysBuild = $keys;
if ($this->keyType !== KeyType::SINGLE) {
$keys = [\implode(':', $keys)];
$keysBuild = [\implode(':', $keysBuild)];
// prevent adding elements if keys are just ordered differently
if ($this->orderType === OrderType::LOOSE) {
/** @var array<array<string>> $keysToTest */
$keysToTest = Permutation::permut($keys, [], false);
foreach ($keysToTest as $test) {
$key = \implode(':', $test);
if (isset($this->keys[$key])) {
if (!$overwrite) {
return false;
}
$keysBuild = [$key];
break;
}
}
}
}
foreach ($keys as $key) {
foreach ($keysBuild as $key) {
if ($overwrite || !isset($this->keys[$key])) {
$id = $this->keys[$key] ?? $id;
$this->keys[$key] = $id;

View File

@ -26,9 +26,16 @@ class AccountStatusTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(4, AccountStatus::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(1, AccountStatus::ACTIVE);
self::assertEquals(2, AccountStatus::INACTIVE);
self::assertEquals(3, AccountStatus::TIMEOUT);

View File

@ -26,9 +26,16 @@ class AccountTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(2, AccountType::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(0, AccountType::USER);
self::assertEquals(1, AccountType::GROUP);
}

View File

@ -26,9 +26,16 @@ class GroupStatusTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(3, GroupStatus::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(1, GroupStatus::ACTIVE);
self::assertEquals(2, GroupStatus::INACTIVE);
self::assertEquals(4, GroupStatus::HIDDEN);

View File

@ -26,11 +26,24 @@ class PermissionTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(6, PermissionType::getConstants());
self::assertEquals(PermissionType::getConstants(), \array_unique(PermissionType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(PermissionType::getConstants(), \array_unique(PermissionType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(1, PermissionType::NONE);
self::assertEquals(2, PermissionType::READ);
self::assertEquals(4, PermissionType::CREATE);

View File

@ -26,9 +26,16 @@ class AssetTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(3, AssetType::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(0, AssetType::CSS);
self::assertEquals(1, AssetType::JS);
self::assertEquals(2, AssetType::JSLATE);

View File

@ -26,9 +26,16 @@ class LoginReturnTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(11, LoginReturnType::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(0, LoginReturnType::OK);
self::assertEquals(-1, LoginReturnType::FAILURE);
self::assertEquals(-2, LoginReturnType::WRONG_PASSWORD);

View File

@ -24,9 +24,16 @@ class CacheStatusTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(4, CacheStatus::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(0, CacheStatus::OK);
self::assertEquals(1, CacheStatus::FAILURE);
self::assertEquals(2, CacheStatus::READONLY);

View File

@ -24,9 +24,16 @@ class CacheTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(4, CacheType::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('file', CacheType::FILE);
self::assertEquals('mem', CacheType::MEMCACHED);
self::assertEquals('redis', CacheType::REDIS);

View File

@ -24,9 +24,16 @@ class CacheValueTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(8, CacheValueType::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(0, CacheValueType::_INT);
self::assertEquals(1, CacheValueType::_STRING);
self::assertEquals(2, CacheValueType::_ARRAY);

View File

@ -24,9 +24,16 @@ class DatabaseStatusTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(6, DatabaseStatus::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(0, DatabaseStatus::OK);
self::assertEquals(1, DatabaseStatus::MISSING_DATABASE);
self::assertEquals(2, DatabaseStatus::MISSING_TABLE);

View File

@ -24,9 +24,16 @@ class DatabaseTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(5, DatabaseType::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('mysql', DatabaseType::MYSQL);
self::assertEquals('pgsql', DatabaseType::PGSQL);
self::assertEquals('sqlite', DatabaseType::SQLITE);

View File

@ -24,11 +24,24 @@ class JoinTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(12, JoinType::getConstants());
self::assertEquals(JoinType::getConstants(), \array_unique(JoinType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(JoinType::getConstants(), \array_unique(JoinType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('JOIN', JoinType::JOIN);
self::assertEquals('LEFT JOIN', JoinType::LEFT_JOIN);
self::assertEquals('LEFT OUTER JOIN', JoinType::LEFT_OUTER_JOIN);

View File

@ -24,11 +24,24 @@ class QueryTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(7, QueryType::getConstants());
self::assertEquals(QueryType::getConstants(), \array_unique(QueryType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(QueryType::getConstants(), \array_unique(QueryType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(0, QueryType::SELECT);
self::assertEquals(1, QueryType::INSERT);
self::assertEquals(2, QueryType::UPDATE);

View File

@ -24,9 +24,16 @@ class RelationTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(7, RelationType::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(1, RelationType::NONE);
self::assertEquals(2, RelationType::NEWEST);
self::assertEquals(4, RelationType::BELONGS_TO);

View File

@ -24,11 +24,24 @@ class QueryTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(13, QueryType::getConstants());
self::assertEquals(QueryType::getConstants(), \array_unique(QueryType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(QueryType::getConstants(), \array_unique(QueryType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(128, QueryType::DROP_DATABASE);
self::assertEquals(129, QueryType::ALTER);
self::assertEquals(130, QueryType::TABLES);

View File

@ -26,8 +26,9 @@ class ISO8601EnumArrayTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(4, ISO8601EnumArray::getConstants());
}
}

View File

@ -26,9 +26,16 @@ class LogLevelTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(8, LogLevel::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('emergency', LogLevel::EMERGENCY);
self::assertEquals('alert', LogLevel::ALERT);
self::assertEquals('critical', LogLevel::CRITICAL);

View File

@ -47,7 +47,7 @@ class MatrixTest extends \PHPUnit\Framework\TestCase
}
/**
* @testdox A matrix can return the dimension
* @testdox A matrix can return its dimension
* @covers phpOMS\Math\Matrix\Matrix
*/
public function testBase() : void

View File

@ -24,11 +24,24 @@ class NumberTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(9, NumberType::getConstants());
self::assertEquals(NumberType::getConstants(), \array_unique(NumberType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(NumberType::getConstants(), \array_unique(NumberType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(0, NumberType::N_INTEGER);
self::assertEquals(1, NumberType::N_NATURAL);
self::assertEquals(2, NumberType::N_EVEN);

View File

@ -25,7 +25,7 @@ class LinearInterpolationTest extends \PHPUnit\Framework\TestCase
{
/**
* @testdox The linear interpolation is correct
* @covers phpOMS\Math\Numerics\LinearInterpolation
* @covers phpOMS\Math\Numerics\Interpolation\LinearInterpolation
*/
public function testInterpolation() : void
{

View File

@ -21,14 +21,27 @@ use phpOMS\Message\Http\BrowserType;
*/
class BrowserTypeTest extends \PHPUnit\Framework\TestCase
{
/**
* @coversNothing
*/
public function testEnumCount() : void
{
self::assertCount(12, BrowserType::getConstants());
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(BrowserType::getConstants(), \array_unique(BrowserType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(12, BrowserType::count());
self::assertEquals(BrowserType::getConstants(), \array_unique(BrowserType::getConstants()));
self::assertEquals('msie', BrowserType::IE);
self::assertEquals('edge', BrowserType::EDGE);
self::assertEquals('firefox', BrowserType::FIREFOX);

View File

@ -24,9 +24,17 @@ class OSTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(24, OSType::getConstants());
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(OSType::getConstants(), \array_unique(OSType::getConstants()));
}
}

View File

@ -24,11 +24,24 @@ class RequestMethodTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(6, RequestMethod::getConstants());
self::assertEquals(RequestMethod::getConstants(), \array_unique(RequestMethod::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(RequestMethod::getConstants(), \array_unique(RequestMethod::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('GET', RequestMethod::GET);
self::assertEquals('POST', RequestMethod::POST);
self::assertEquals('PUT', RequestMethod::PUT);

View File

@ -24,11 +24,24 @@ class RequestStatusCodeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(55, RequestStatusCode::getConstants());
self::assertEquals(RequestStatusCode::getConstants(), \array_unique(RequestStatusCode::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(RequestStatusCode::getConstants(), \array_unique(RequestStatusCode::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(100, RequestStatusCode::R_100);
self::assertEquals(101, RequestStatusCode::R_101);
self::assertEquals(102, RequestStatusCode::R_102);

View File

@ -24,11 +24,24 @@ class RequestStatusTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(55, RequestStatus::getConstants());
self::assertEquals(RequestStatus::getConstants(), \array_unique(RequestStatus::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(RequestStatus::getConstants(), \array_unique(RequestStatus::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('Continue', RequestStatus::R_100);
self::assertEquals('Switching Protocols', RequestStatus::R_101);
self::assertEquals('Processing', RequestStatus::R_102);

View File

@ -24,10 +24,24 @@ class PacketTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(11, PacketType::getConstants());
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(PacketType::getConstants(), \array_unique(PacketType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(0, PacketType::CONNECT);
self::assertEquals(1, PacketType::DISCONNECT);
self::assertEquals(2, PacketType::KICK);

View File

@ -24,11 +24,24 @@ class DomActionTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(9, DomAction::getConstants());
self::assertEquals(DomAction::getConstants(), \array_unique(DomAction::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(DomAction::getConstants(), \array_unique(DomAction::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(0, DomAction::CREATE_BEFORE);
self::assertEquals(1, DomAction::CREATE_AFTER);
self::assertEquals(2, DomAction::DELETE);

View File

@ -24,11 +24,24 @@ class NotifyTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(5, NotifyType::getConstants());
self::assertEquals(NotifyType::getConstants(), \array_unique(NotifyType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(NotifyType::getConstants(), \array_unique(NotifyType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(0, NotifyType::BINARY);
self::assertEquals(1, NotifyType::INFO);
self::assertEquals(2, NotifyType::WARNING);

View File

@ -23,7 +23,7 @@ use phpOMS\Security\PhpCode;
*
* @internal
*/
class RouteVerbTest extends \PHPUnit\Framework\TestCase
class PhpCodeTest extends \PHPUnit\Framework\TestCase
{
/**
* @testdox A file with unicode characters gets correctly identified

View File

@ -33,7 +33,7 @@ class AddressTest extends \PHPUnit\Framework\TestCase
/**
* @testdox The address has the expected attributes
* @covers phpOMS\Stdlib\Base\Address<extended>
* @covers phpOMS\Stdlib\Base\Address
*/
public function testAttributes() : void
{
@ -44,7 +44,7 @@ class AddressTest extends \PHPUnit\Framework\TestCase
/**
* @testdox The address has the expected default values after initialization
* @covers phpOMS\Stdlib\Base\Address<extended>
* @covers phpOMS\Stdlib\Base\Address
*/
public function testDefault() : void
{
@ -73,7 +73,7 @@ class AddressTest extends \PHPUnit\Framework\TestCase
/**
* @testdox The fao can be set and returned
* @covers phpOMS\Stdlib\Base\Address<extended>
* @covers phpOMS\Stdlib\Base\Address
*/
public function testFAOInputOutput() : void
{
@ -83,7 +83,7 @@ class AddressTest extends \PHPUnit\Framework\TestCase
/**
* @testdox The recepient can be set and returned
* @covers phpOMS\Stdlib\Base\Address<extended>
* @covers phpOMS\Stdlib\Base\Address
*/
public function testRecipientInputOutput() : void
{
@ -93,7 +93,7 @@ class AddressTest extends \PHPUnit\Framework\TestCase
/**
* @testdox The location can be set and returned
* @covers phpOMS\Stdlib\Base\Address<extended>
* @covers phpOMS\Stdlib\Base\Address
*/
public function testLocationInputOutput() : void
{
@ -105,7 +105,7 @@ class AddressTest extends \PHPUnit\Framework\TestCase
/**
* @testdox The address can be turned into array data
* @covers phpOMS\Stdlib\Base\Address<extended>
* @covers phpOMS\Stdlib\Base\Address
*/
public function testArray() : void
{
@ -134,7 +134,7 @@ class AddressTest extends \PHPUnit\Framework\TestCase
/**
* @testdox The address can be json serialized
* @covers phpOMS\Stdlib\Base\Address<extended>
* @covers phpOMS\Stdlib\Base\Address
*/
public function testJsonSerialize() : void
{

View File

@ -24,9 +24,16 @@ class AddressTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(7, AddressType::getconstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(1, AddressType::HOME);
self::assertEquals(2, AddressType::BUSINESS);
self::assertEquals(3, AddressType::SHIPPING);

View File

@ -17,10 +17,30 @@ namespace phpOMS\tests\Stdlib\Base;
use phpOMS\Stdlib\Base\Heap;
/**
* @testdox phpOMS\tests\Stdlib\Base\HeapTest: Heap
*
* @internal
*/
class HeapTest extends \PHPUnit\Framework\TestCase
{
/**
* @testdox Elements get correctly pushed to the heap
* @covers phpOMS\Stdlib\Base\Heap
*/
public function testSize(): void
{
$heap = new Heap();
for ($i = 1; $i < 6; ++$i) {
$heap->push($i);
}
self::assertEquals(5, $heap->size());
}
/**
* @testdox Heap elements get returned in the correct order
* @covers phpOMS\Stdlib\Base\Heap
*/
public function testPushAndPop() : void
{
$heap = new Heap();
@ -39,6 +59,10 @@ class HeapTest extends \PHPUnit\Framework\TestCase
self::assertEquals($sortedFunction, $sorted);
}
/**
* @testdox Heap elements get returned in the correct order by using a custom comparator
* @covers phpOMS\Stdlib\Base\Heap
*/
public function testPushAndPopCustomComparator() : void
{
$heap = new Heap(function($a, $b) { return ($a <=> $b) * -1; });
@ -57,6 +81,24 @@ class HeapTest extends \PHPUnit\Framework\TestCase
self::assertEquals(\array_reverse($sortedFunction), $sorted);
}
/**
* @testdox The heap can be turned into an array
* @covers phpOMS\Stdlib\Base\Heap
*/
public function testArray() : void
{
$heap = new Heap();
for ($i = 1; $i < 6; ++$i) {
$heap->push($i);
}
self::assertEquals([1, 2, 3, 4, 5], $heap->toArray());
}
/**
* @testdox Heap elements can be replaced
* @covers phpOMS\Stdlib\Base\Heap
*/
public function testReplace() : void
{
$heap = new Heap();
@ -68,6 +110,10 @@ class HeapTest extends \PHPUnit\Framework\TestCase
self::assertEquals([2, 3, 3, 4, 5], $heap->toArray());
}
/**
* @testdox A heap element can be returned while adding a new one
* @covers phpOMS\Stdlib\Base\Heap
*/
public function testPushPop() : void
{
$heap = new Heap();
@ -82,6 +128,10 @@ class HeapTest extends \PHPUnit\Framework\TestCase
self::assertEquals([2, 3, 4, 5, 6], $heapArray);
}
/**
* @testdox The heap can be checked if it contains certain elements
* @covers phpOMS\Stdlib\Base\Heap
*/
public function testContains(): void
{
$heap = new Heap();
@ -98,6 +148,10 @@ class HeapTest extends \PHPUnit\Framework\TestCase
self::assertFalse($heap->contains(6));
}
/**
* @testdox The first heap element can be returned without removing it
* @covers phpOMS\Stdlib\Base\Heap
*/
public function testPeek() : void
{
$heap = new Heap();
@ -112,6 +166,10 @@ class HeapTest extends \PHPUnit\Framework\TestCase
self::assertEquals(2, $heap->peek());
}
/**
* @testdox The n smallest elements can be returned from the heap
* @covers phpOMS\Stdlib\Base\Heap
*/
public function testNSmallest() : void
{
$heap = new Heap();
@ -123,6 +181,10 @@ class HeapTest extends \PHPUnit\Framework\TestCase
self::assertEquals([1, 1, 3], $heap->getNSmallest(3));
}
/**
* @testdox The n largest elements can be returned from the heap
* @covers phpOMS\Stdlib\Base\Heap
*/
public function testNLargest(): void
{
$heap = new Heap();
@ -135,16 +197,10 @@ class HeapTest extends \PHPUnit\Framework\TestCase
self::assertEquals([4, 4, 3], $heap->getNLargest(3));
}
public function testSize(): void
{
$heap = new Heap();
for ($i = 1; $i < 6; ++$i) {
$heap->push($i);
}
self::assertEquals(5, $heap->size());
}
/**
* @testdox The heap can be cleared of all elements
* @covers phpOMS\Stdlib\Base\Heap
*/
public function testClear(): void
{
$heap = new Heap();
@ -156,6 +212,10 @@ class HeapTest extends \PHPUnit\Framework\TestCase
self::assertEquals(0, $heap->size());
}
/**
* @testdox The heap can be checked if it has elements
* @covers phpOMS\Stdlib\Base\Heap
*/
public function testEmpty(): void
{
$heap = new Heap();

View File

@ -18,17 +18,17 @@ use phpOMS\Localization\ISO3166TwoEnum;
use phpOMS\Stdlib\Base\Iban;
/**
* @testdox phpOMS\tests\Stdlib\Base\IbanTest: Iban type
*
* @internal
*/
class IbanTest extends \PHPUnit\Framework\TestCase
{
public function testAttributes() : void
{
$iban = new Iban('DE22 6008 0000 0960 0280 00');
self::assertObjectHasAttribute('iban', $iban);
}
public function testMethods() : void
/**
* @testdox A iban can be correctly parsed into its different components
* @covers phpOMS\Stdlib\Base\Iban
*/
public function testInputOutput() : void
{
$strRepresentation = 'DE22 6008 0000 0960 0280 00';
$iban = new Iban($strRepresentation);
@ -37,11 +37,6 @@ class IbanTest extends \PHPUnit\Framework\TestCase
self::assertEquals('22', $iban->getChecksum());
self::assertEquals('60080000', $iban->getBankCode());
self::assertEquals('0960028000', $iban->getAccount());
self::assertEquals($strRepresentation, $iban->prettyPrint());
self::assertEquals($strRepresentation, $iban->serialize());
$iban->unserialize('dE226008000009600280 00');
self::assertEquals('DE22 6008 0000 0960 0280 00', $iban->serialize());
self::assertEquals('', $iban->getAccountType());
self::assertEquals('', $iban->getBicCode());
@ -53,6 +48,26 @@ class IbanTest extends \PHPUnit\Framework\TestCase
self::assertEquals(22, $iban->getLength());
}
/**
* @testdox A iban can be serialized and unserialized
* @covers phpOMS\Stdlib\Base\Iban
*/
public function testSearialization() : void
{
$strRepresentation = 'DE22 6008 0000 0960 0280 00';
$iban = new Iban($strRepresentation);
self::assertEquals($strRepresentation, $iban->prettyPrint());
self::assertEquals($strRepresentation, $iban->serialize());
$iban->unserialize('dE226008000009600280 00');
self::assertEquals('DE22 6008 0000 0960 0280 00', $iban->serialize());
}
/**
* @testdox A invalid iban country code throws a InvalidArgumentException
* @covers phpOMS\Stdlib\Base\Iban
*/
public function testInvalidIbanCountry() : void
{
self::expectException(\InvalidArgumentException::class);
@ -60,6 +75,10 @@ class IbanTest extends \PHPUnit\Framework\TestCase
$iban = new Iban('ZZ22 6008 0000 0960 0280 00');
}
/**
* @testdox A invalid iban length throws a InvalidArgumentException
* @covers phpOMS\Stdlib\Base\Iban
*/
public function testInvalidIbanLength() : void
{
self::expectException(\InvalidArgumentException::class);
@ -67,6 +86,10 @@ class IbanTest extends \PHPUnit\Framework\TestCase
$iban = new Iban('DE22 6008 0000 0960 0280 0');
}
/**
* @testdox A invalid iban checksum throws a InvalidArgumentException
* @covers phpOMS\Stdlib\Base\Iban
*/
public function testInvalidIbanChecksum() : void
{
self::expectException(\InvalidArgumentException::class);

View File

@ -18,21 +18,37 @@ use phpOMS\Stdlib\Base\AddressType;
use phpOMS\Stdlib\Base\Location;
/**
* @testdox phpOMS\tests\Stdlib\Base\LocationTest: Location type
*
* @internal
*/
class LocationTest extends \PHPUnit\Framework\TestCase
{
public function testAttributes() : void
protected Location $location;
protected function setUp() : void
{
$location = new Location();
self::assertObjectHasAttribute('postal', $location);
self::assertObjectHasAttribute('city', $location);
self::assertObjectHasAttribute('country', $location);
self::assertObjectHasAttribute('address', $location);
self::assertObjectHasAttribute('state', $location);
self::assertObjectHasAttribute('geo', $location);
$this->location = new Location();
}
/**
* @testdox The location has the expected attributes
* @covers phpOMS\Stdlib\Base\Location
*/
public function testAttributes() : void
{
self::assertObjectHasAttribute('postal', $this->location);
self::assertObjectHasAttribute('city', $this->location);
self::assertObjectHasAttribute('country', $this->location);
self::assertObjectHasAttribute('address', $this->location);
self::assertObjectHasAttribute('state', $this->location);
self::assertObjectHasAttribute('geo', $this->location);
}
/**
* @testdox The location has the expected default values after initialization
* @covers phpOMS\Stdlib\Base\Location
*/
public function testDefault() : void
{
$expected = [
@ -47,20 +63,93 @@ class LocationTest extends \PHPUnit\Framework\TestCase
],
];
$location = new Location();
self::assertEquals('', $location->getPostal());
self::assertEquals('', $location->getCity());
self::assertEquals('', $location->getCountry());
self::assertEquals('', $location->getAddress());
self::assertEquals('', $location->getState());
self::assertEquals(0, $location->getId());
self::assertEquals(AddressType::HOME, $location->getType());
self::assertEquals(['lat' => 0, 'long' => 0], $location->getGeo());
self::assertEquals($expected, $location->toArray());
self::assertEquals($expected, $location->jsonSerialize());
self::assertEquals('', $this->location->getPostal());
self::assertEquals('', $this->location->getCity());
self::assertEquals('', $this->location->getCountry());
self::assertEquals('', $this->location->getAddress());
self::assertEquals('', $this->location->getState());
self::assertEquals(0, $this->location->getId());
self::assertEquals(AddressType::HOME, $this->location->getType());
self::assertEquals(['lat' => 0, 'long' => 0], $this->location->getGeo());
self::assertEquals($expected, $this->location->toArray());
self::assertEquals($expected, $this->location->jsonSerialize());
}
public function testGetSet() : void
/**
* @testdox The postal can be set and returned
* @covers phpOMS\Stdlib\Base\Location
*/
public function testPostalInputOutput() : void
{
$this->location->setPostal('0123456789');
self::assertEquals('0123456789', $this->location->getPostal());
}
/**
* @testdox The type can be set and returned
* @covers phpOMS\Stdlib\Base\Location
*/
public function testTypeInputOutput() : void
{
$this->location->setType(AddressType::BUSINESS);
self::assertEquals(AddressType::BUSINESS, $this->location->getType());
}
/**
* @testdox The city can be set and returned
* @covers phpOMS\Stdlib\Base\Location
*/
public function testCityInputOutput() : void
{
$this->location->setCity('city');
self::assertEquals('city', $this->location->getCity());
}
/**
* @testdox The country can be set and returned
* @covers phpOMS\Stdlib\Base\Location
*/
public function testCountryInputOutput() : void
{
$this->location->setCountry('Country');
self::assertEquals('Country', $this->location->getCountry());
}
/**
* @testdox The address can be set and returned
* @covers phpOMS\Stdlib\Base\Location
*/
public function testAddressInputOutput() : void
{
$this->location->setAddress('Some address here');
self::assertEquals('Some address here', $this->location->getAddress());
}
/**
* @testdox The state can be set and returned
* @covers phpOMS\Stdlib\Base\Location
*/
public function testStateInputOutput() : void
{
$this->location->setState('This is a state 123');
self::assertEquals('This is a state 123', $this->location->getState());
}
/**
* @testdox The geo location can be set and returned
* @covers phpOMS\Stdlib\Base\Location
*/
public function testGeoInputOutput() : void
{
$this->location->setGeo(['lat' => 12.1, 'long' => 11.2,]);
self::assertEquals(['lat' => 12.1, 'long' => 11.2], $this->location->getGeo());
}
/**
* @testdox The location can be turned into an array
* @covers phpOMS\Stdlib\Base\Location
*/
public function testArray() : void
{
$expected = [
'postal' => '0123456789',
@ -74,24 +163,43 @@ class LocationTest extends \PHPUnit\Framework\TestCase
],
];
$location = new Location();
$this->location->setPostal('0123456789');
$this->location->setType(AddressType::BUSINESS);
$this->location->setCity('city');
$this->location->setCountry('Country');
$this->location->setAddress('Some address here');
$this->location->setState('This is a state 123');
$this->location->setGeo(['lat' => 12.1, 'long' => 11.2,]);
$location->setPostal('0123456789');
$location->setType(AddressType::BUSINESS);
$location->setCity('city');
$location->setCountry('Country');
$location->setAddress('Some address here');
$location->setState('This is a state 123');
$location->setGeo(['lat' => 12.1, 'long' => 11.2,]);
self::assertEquals($expected, $this->location->toArray());
}
self::assertEquals(AddressType::BUSINESS, $location->getType());
self::assertEquals('0123456789', $location->getPostal());
self::assertEquals('city', $location->getCity());
self::assertEquals('Country', $location->getCountry());
self::assertEquals('Some address here', $location->getAddress());
self::assertEquals('This is a state 123', $location->getState());
self::assertEquals(['lat' => 12.1, 'long' => 11.2], $location->getGeo());
self::assertEquals($expected, $location->toArray());
self::assertEquals($expected, $location->jsonSerialize());
/**
* @testdox The location can be json serialized
* @covers phpOMS\Stdlib\Base\Location
*/
public function testJsonSerialize() : void
{
$expected = [
'postal' => '0123456789',
'city' => 'city',
'country' => 'Country',
'address' => 'Some address here',
'state' => 'This is a state 123',
'geo' => [
'lat' => 12.1,
'long' => 11.2,
],
];
$this->location->setPostal('0123456789');
$this->location->setType(AddressType::BUSINESS);
$this->location->setCity('city');
$this->location->setCountry('Country');
$this->location->setAddress('Some address here');
$this->location->setState('This is a state 123');
$this->location->setGeo(['lat' => 12.1, 'long' => 11.2,]);
self::assertEquals($expected, $this->location->jsonSerialize());
}
}

View File

@ -24,9 +24,16 @@ class PhoneTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(4, PhoneType::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(1, PhoneType::HOME);
self::assertEquals(2, PhoneType::BUSINESS);
self::assertEquals(3, PhoneType::MOBILE);

View File

@ -17,22 +17,41 @@ namespace phpOMS\tests\Stdlib\Base;
use phpOMS\Stdlib\Base\SmartDateTime;
/**
* @testdox phpOMS\tests\Stdlib\Base\SmartDateTimeTest: DateTime type with additional functionality
*
* @internal
*/
class SmartDateTimeTest extends \PHPUnit\Framework\TestCase
{
/**
* @testdox The smart datetime extends the datetime
* @covers phpOMS\Stdlib\Base\SmartDateTime
*/
public function testAttributes() : void
{
$datetime = new SmartDateTime();
self::assertInstanceOf('\DateTime', $datetime);
}
public function testGetSet() : void
/**
* @testdox The smart datetime can be formatted like the datetime
* @covers phpOMS\Stdlib\Base\SmartDateTime
*/
public function testFormat() : void
{
$datetime = new SmartDateTime('1970-01-01');
self::assertEquals('1970-01-01', $datetime->format('Y-m-d'));
}
/**
* @testdox The smart datetime can be modified an creates a new smart datetime
* @covers phpOMS\Stdlib\Base\SmartDateTime
*/
public function testCreateModify() : void
{
$datetime = new SmartDateTime('1970-01-01');
$new = $datetime->createModify(1, 1, 1);
$new = $datetime->createModify(1, 1, 1);
self::assertEquals('1970-01-01', $datetime->format('Y-m-d'));
self::assertEquals('1971-02-02', $new->format('Y-m-d'));
@ -44,24 +63,96 @@ class SmartDateTimeTest extends \PHPUnit\Framework\TestCase
self::assertEquals('1973-11-01', $datetime->createModify(0, -19)->format('Y-m-d'));
self::assertEquals('1973-12-01', $datetime->createModify(0, -19, 30)->format('Y-m-d'));
self::assertEquals('1973-12-31', $datetime->createModify(0, -18, 30)->format('Y-m-d'));
self::assertEquals(30, $datetime->getDaysOfMonth());
self::assertEquals(0, $datetime->getFirstDayOfMonth());
}
/**
* @testdox The days of the month can be returned
* @covers phpOMS\Stdlib\Base\SmartDateTime
*/
public function testDaysOfMonth() : void
{
$datetime = new SmartDateTime('1975-06-01');
self::assertEquals(30, $datetime->getDaysOfMonth());
}
/**
* @testdox The week day index of the first day of the month can be returned
* @covers phpOMS\Stdlib\Base\SmartDateTime
*/
public function testFirstDayOfMonth() : void
{
$datetime = new SmartDateTime('1975-06-01');
self::assertEquals(0, $datetime->getFirstDayOfMonth());
}
/**
* @testdox A smart datetime can be created from a datetime
* @covers phpOMS\Stdlib\Base\SmartDateTime
*/
public function testCreateFromDateTime() : void
{
$expected = new \DateTime('now');
$obj = SmartDateTime::createFromDateTime($expected);
self::assertEquals($expected->format('Y-m-d H:i:s'), $obj->format('Y-m-d H:i:s'));
self::assertEquals(\date("Y-m-t", \strtotime($expected->format('Y-m-d'))), $obj->getEndOfMonth()->format('Y-m-d'));
self::assertEquals(\date("Y-m-01", \strtotime($expected->format('Y-m-d'))), $obj->getStartOfMonth()->format('Y-m-d'));
}
/**
* @testdox A smart datetime can be returned of the last day of the month
* @covers phpOMS\Stdlib\Base\SmartDateTime
*/
public function testEndOfMonth() : void
{
$expected = new \DateTime('now');
$obj = SmartDateTime::createFromDateTime($expected);
self::assertEquals(\date("Y-m-t", \strtotime($expected->format('Y-m-d'))), $obj->getEndOfMonth()->format('Y-m-d'));
}
/**
* @testdox A smart datetime can be returned of the fist day of the month
* @covers phpOMS\Stdlib\Base\SmartDateTime
*/
public function testStartOfMonth() : void
{
$expected = new \DateTime('now');
$obj = SmartDateTime::createFromDateTime($expected);
self::assertEquals(\date("Y-m-01", \strtotime($expected->format('Y-m-d'))), $obj->getStartOfMonth()->format('Y-m-d'));
}
/**
* @testdox A date or year can be checked if it is a leap year
* @covers phpOMS\Stdlib\Base\SmartDateTime
*/
public function testLeapYear() : void
{
self::assertFalse((new SmartDateTime('2103-07-20'))->isLeapYear());
self::assertTrue((new SmartDateTime('2104-07-20'))->isLeapYear());
self::assertFalse(SmartDateTime::leapYear(2103));
self::assertTrue(SmartDateTime::leapYear(2104));
}
self::assertEquals(\date('w', $expected->getTimestamp()), SmartDateTime::getDayOfWeek((int) $expected->format('Y'), (int) $expected->format('m'), (int) $expected->format('d')));
/**
* @testdox The day of the week index can be retruned from a date
* @covers phpOMS\Stdlib\Base\SmartDateTime
*/
public function testDayOfWeek() : void
{
$expected = new \DateTime('now');
$obj = SmartDateTime::createFromDateTime($expected);
// todo: i think this assertion is wrong! or the function getFirstDay... doesn't do what is supposed to do
self::assertEquals(\date('w', $expected->getTimestamp()), $obj->getFirstDayOfWeek());
self::assertEquals(\date('w', $expected->getTimestamp()), SmartDateTime::dayOfWeek((int) $expected->format('Y'), (int) $expected->format('m'), (int) $expected->format('d')));
self::assertEquals(\date('w', $expected->getTimestamp()), $obj->getDayOfWeek());
}
/**
* @testdox A calendar sheet is retunred containing all days of the month and some days of the previous and next month
* @covers phpOMS\Stdlib\Base\SmartDateTime
*/
public function testCalendarSheet() : void
{
$expected = new \DateTime('now');
$obj = SmartDateTime::createFromDateTime($expected);
self::assertCount(42, $obj->getMonthCalendar());
self::assertCount(42, $obj->getMonthCalendar(1));

View File

@ -24,9 +24,16 @@ class KeyTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(2, KeyType::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(0, KeyType::SINGLE);
self::assertEquals(1, KeyType::MULTIPLE);
}

View File

@ -19,20 +19,16 @@ use phpOMS\Stdlib\Map\MultiMap;
use phpOMS\Stdlib\Map\OrderType;
/**
* @testdox phpOMS\tests\Stdlib\Map\MultiMapTest: Map which associates multiple keys with the same value
*
* @internal
*/
class MultiMapTest extends \PHPUnit\Framework\TestCase
{
public function testAttributes() : void
{
$map = new MultiMap();
self::assertInstanceOf('\phpOMS\Stdlib\Map\MultiMap', $map);
/* Testing members */
self::assertObjectHasAttribute('values', $map);
self::assertObjectHasAttribute('keys', $map);
}
/**
* @testdox The map has the expected default values and functionality after initialization
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testDefault() : void
{
$map = new MultiMap();
@ -49,6 +45,10 @@ class MultiMapTest extends \PHPUnit\Framework\TestCase
self::assertFalse($map->remove('someKey'));
}
/**
* @testdox Elements with multiple optional keys can be added
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testBasicAddAny() : void
{
$map = new MultiMap();
@ -56,28 +56,66 @@ class MultiMapTest extends \PHPUnit\Framework\TestCase
$inserted = $map->add(['a', 'b'], 'val1');
self::assertEquals(1, $map->count());
self::assertTrue($inserted);
}
/**
* @testdox Elements with multiple optional keys can be returned if any of the keys matches
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testBasicGetAny() : void
{
$map = new MultiMap();
$map->add(['a', 'b'], 'val1');
self::assertEquals('val1', $map->get('a'));
self::assertEquals('val1', $map->get('b'));
}
/**
* @testdox Elements can be forcefully overwritten
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testOverwriteAny() : void
{
$map = new MultiMap();
$inserted = $map->add(['a', 'b'], 'val1');
$inserted = $map->add(['a', 'b'], 'val2');
$map->add(['a', 'b'], 'val1');
$inserted = $map->add(['a', 'b'], 'val2', true);
self::assertEquals(1, $map->count());
self::assertTrue($inserted);
self::assertEquals('val2', $map->get('a'));
self::assertEquals('val2', $map->get('b'));
}
public function testOverwritePartialFalseAny() : void
/**
* @testdox By default elements are not overwritten
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testInvalidOverwriteSubkeyAny() : void
{
$map = new MultiMap();
$inserted = $map->add(['a', 'b'], 'val2');
$inserted = $map->add(['a', 'c'], 'val3', false);
$map->add(['a', 'b'], 'val2');
$inserted = $map->add(['a'], 'val3');
self::assertEquals(1, $map->count());
self::assertFalse($inserted);
self::assertEquals('val2', $map->get('a'));
self::assertEquals('val2', $map->get('b'));
}
/**
* @testdox If a element with partially matching keys is already in the map it will be only added for the new key
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testOverwriteCreateAny() : void
{
$map = new MultiMap();
$map->add(['a', 'b'], 'val2');
$inserted = $map->add(['a', 'c'], 'val3');
self::assertEquals(2, $map->count());
self::assertTrue($inserted);
self::assertEquals('val2', $map->get('a'));
@ -85,13 +123,17 @@ class MultiMapTest extends \PHPUnit\Framework\TestCase
self::assertEquals('val3', $map->get('c'));
}
public function testOverwriteFalseFalseAny() : void
/**
* @testdox If all keys exist in the map no new element will be created
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testInvalidOverwriteAny() : void
{
$map = new MultiMap();
$inserted = $map->add(['a', 'b'], 'val2');
$inserted = $map->add(['a', 'c'], 'val3', false);
$inserted = $map->add(['a', 'c'], 'val4', false);
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$inserted = $map->add(['a', 'c'], 'val4');
self::assertEquals(2, $map->count());
self::assertFalse($inserted);
self::assertEquals('val2', $map->get('a'));
@ -99,16 +141,16 @@ class MultiMapTest extends \PHPUnit\Framework\TestCase
self::assertEquals('val3', $map->get('c'));
}
public function testSetAny() : void
/**
* @testdox Values can be set/replaced by key
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testSetByKeyAny() : void
{
$map = new MultiMap();
$inserted = $map->add(['a', 'b'], 'val2');
$inserted = $map->add(['a', 'c'], 'val3', false);
$set = $map->set('d', 'val4');
self::assertFalse($set);
self::assertEquals(2, $map->count());
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$set = $map->set('b', 'val4');
self::assertEquals(2, $map->count());
@ -118,27 +160,48 @@ class MultiMapTest extends \PHPUnit\Framework\TestCase
self::assertEquals('val3', $map->get('c'));
}
public function testRemapAny() : void
/**
* @testdox Values cannot be set/replaced if the key doesn't exist
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testInvalidSetByKeyAny() : void
{
$map = new MultiMap();
$inserted = $map->add(['a', 'b'], 'val2');
$inserted = $map->add(['a', 'c'], 'val3', false);
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$set = $map->set('d', 'val4');
$set = $map->set('b', 'val4');
self::assertFalse($set);
self::assertEquals(2, $map->count());
}
/**
* @testdox A key cannot be remapped to a none-existing key
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testInvalidRemapNewAny() : void
{
$map = new MultiMap();
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$remap = $map->remap('b', 'd');
self::assertEquals(2, $map->count());
self::assertFalse($remap);
}
$remap = $map->remap('d', 'b');
self::assertEquals(2, $map->count());
self::assertFalse($remap);
/**
* @testdox A key can be remapped to the value of an existing key
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testRemapAny() : void
{
$map = new MultiMap();
$remap = $map->remap('d', 'e');
self::assertEquals(2, $map->count());
self::assertFalse($remap);
$map->add(['a', 'b'], 'val4');
$map->add(['a', 'c'], 'val3');
$remap = $map->remap('b', 'c');
self::assertEquals(2, $map->count());
@ -148,68 +211,144 @@ class MultiMapTest extends \PHPUnit\Framework\TestCase
self::assertEquals('val3', $map->get('c'));
}
public function testMapInfoAny() : void
/**
* @testdox If no more keys are associated with a value after a remap the value is removed from the map
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testRemapUnmapAny() : void
{
$map = new MultiMap();
$inserted = $map->add(['a', 'b'], 'val2');
$inserted = $map->add(['a', 'c'], 'val3', false);
$map->add(['b'], 'val4');
$map->add(['a', 'c'], 'val3');
$set = $map->set('d', 'val4');
$set = $map->set('b', 'val4');
$remap = $map->remap('b', 'c');
self::assertEquals(1, $map->count());
self::assertTrue($remap);
self::assertEquals('val3', $map->get('b'));
self::assertEquals('val3', $map->get('a'));
self::assertEquals('val3', $map->get('c'));
}
/**
* @testdox All keys of the map can be returned
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testMapKeysAny() : void
{
$map = new MultiMap();
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$map->set('d', 'val4');
$map->set('b', 'val4');
self::assertCount(3, $map->keys());
self::assertCount(2, $map->values());
self::assertIsArray($map->keys());
}
/**
* @testdox All values of the map can be returned
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testMapValuesAny() : void
{
$map = new MultiMap();
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$map->set('d', 'val4');
$map->set('b', 'val4');
self::assertCount(2, $map->values());
self::assertIsArray($map->values());
}
/**
* @testdox Sibling keys can be found
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testSiblingsAny() : void
{
$map = new MultiMap();
$inserted = $map->add(['a', 'b'], 'val2');
$set = $map->set('d', 'val4');
$set = $map->set('b', 'val4');
$siblings = $map->getSiblings('d');
self::assertEmpty($siblings);
self::assertCount(0, $siblings);
$map->add(['a', 'b'], 'val2');
$siblings = $map->getSiblings('b');
self::assertCount(1, $siblings);
self::assertEquals(['a'], $siblings);
}
/**
* @testdox If a key doesn't exist or has no siblings no siblings are returned
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testInvalidSiblingsAny() : void
{
$map = new MultiMap();
$map->add(['a', 'b'], 'val2');
$siblings = $map->getSiblings('d');
self::assertEmpty($siblings);
}
/**
* @testdox A key for a value can be removed
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testRemoveAny() : void
{
$map = new MultiMap();
$inserted = $map->add(['a', 'b'], 'val2');
$inserted = $map->add(['a', 'c'], 'val3', false);
$set = $map->set('d', 'val4');
$set = $map->set('b', 'val4');
$removed = $map->remove('d');
self::assertFalse($removed);
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$removed = $map->remove('c');
self::assertTrue($removed);
self::assertCount(2, $map->keys());
self::assertCount(1, $map->values());
}
$removed = $map->removeKey('d');
self::assertFalse($removed);
/**
* @testdox If the last key of a value is removed the value is also removed from the map
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testRemoveLastAny() : void
{
$map = new MultiMap();
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$map->remove('c');
$removed = $map->removeKey('a');
self::assertTrue($removed);
self::assertEquals(1, $map->count());
self::assertCount(1, $map->keys());
self::assertCount(1, $map->values());
}
/**
* @testdox If a key doesn't exist it cannot be removed
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testInvalidRemoveAny() : void
{
$map = new MultiMap();
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$removed = $map->remove('d');
self::assertFalse($removed);
}
/**
* @testdox Elements with multiple required keys can be added
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testBasicAddExact() : void
{
$map = new MultiMap(KeyType::MULTIPLE);
@ -217,10 +356,37 @@ class MultiMapTest extends \PHPUnit\Framework\TestCase
$inserted = $map->add(['a', 'b'], 'val1');
self::assertEquals(1, $map->count());
self::assertTrue($inserted);
}
/**
* @testdox Elements with multiple required keys can be returned if all match
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testBasicGetExact() : void
{
$map = new MultiMap(KeyType::MULTIPLE);
$map->add(['a', 'b'], 'val1');
self::assertEquals('val1', $map->get(['a', 'b']));
self::assertEquals('val1', $map->get(['b', 'a']));
}
/**
* @testdox Elements with multiple required keys cannot be returned if they don't match exactly
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testBasicInvalidGetExact() : void
{
$map = new MultiMap(KeyType::MULTIPLE);
$map->add(['a', 'b'], 'val1');
self::assertNotEquals('val1', $map->get(['b']));
}
/**
* @testdox Elements with multiple required and ordered keys can be added
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testBasicAddExactOrdered() : void
{
$map = new MultiMap(KeyType::MULTIPLE, OrderType::STRICT);
@ -228,150 +394,322 @@ class MultiMapTest extends \PHPUnit\Framework\TestCase
$inserted = $map->add(['a', 'b'], 'val1');
self::assertEquals(1, $map->count());
self::assertTrue($inserted);
}
/**
* @testdox Elements with multiple required ordered keys can be if all match in the correct order
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testBasicGetExactOrdered() : void
{
$map = new MultiMap(KeyType::MULTIPLE, OrderType::STRICT);
$map->add(['a', 'b'], 'val1');
self::assertEquals('val1', $map->get(['a', 'b']));
}
/**
* @testdox Elements with multiple required keys cannot be returned if they don't match exactly in the correct order
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testBasicInvalidOrderedGetExact() : void
{
$map = new MultiMap(KeyType::MULTIPLE, OrderType::STRICT);
$map->add(['a', 'b'], 'val1');
self::assertNull($map->get(['b', 'a']));
}
/**
* @testdox Elements with multiple required keys can be forcefully overwritten
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testOverwriteExact() : void
{
$map = new MultiMap(KeyType::MULTIPLE);
$inserted = $map->add(['a', 'b'], 'val1');
$inserted = $map->add(['a', 'b'], 'val2');
$map->add(['a', 'b'], 'val1');
$inserted = $map->add(['a', 'b'], 'val2', true);
self::assertEquals(1, $map->count());
self::assertTrue($inserted);
self::assertEquals('val2', $map->get(['a', 'b']));
}
public function testOverwritePartialFalseExact() : void
/**
* @testdox Elements with multiple required ordered keys can be forcefully overwritten
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testOverwriteExactOrdered() : void
{
$map = new MultiMap(KeyType::MULTIPLE, OrderType::STRICT);
$map->add(['a', 'b'], 'val1');
$inserted = $map->add(['a', 'b'], 'val2', true);
self::assertEquals(1, $map->count());
self::assertTrue($inserted);
self::assertEquals('val2', $map->get(['a', 'b']));
}
/**
* @testdox An element cannot be added to for multiple required keys if the keys already exist in a different order
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testInvalidAddDifferentOrderExact() : void
{
$map = new MultiMap(KeyType::MULTIPLE);
$inserted = $map->add(['a', 'b'], 'val2');
$inserted = $map->add(['a', 'c'], 'val3', false);
$map->add(['a', 'b'], 'val2');
$inserted = $map->add(['b', 'a'], 'val3');
self::assertEquals(1, $map->count());
self::assertFalse($inserted);
self::assertEquals('val2', $map->get(['a', 'b']));
self::assertEquals('val2', $map->get(['b', 'a']));
}
/**
* @testdox If a element with partially matching multiple keys is already in the map it will be only added for the new key
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testOverwriteCreateExact() : void
{
$map = new MultiMap(KeyType::MULTIPLE);
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val1');
$inserted = $map->add(['b', 'c'], 'val3');
self::assertEquals(3, $map->count());
self::assertTrue($inserted);
self::assertEquals('val2', $map->get(['a', 'b']));
self::assertEquals('val3', $map->get(['b', 'c']));
self::assertEquals('val1', $map->get(['a', 'c']));
}
/**
* @testdox Adding differently ordered keys for multiple required keys will create a new entry in the map
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testAddDifferentlyOrderedKeys() : void
{
$map = new MultiMap(KeyType::MULTIPLE, OrderType::STRICT);
$map->add(['a', 'b'], 'val2');
$inserted = $map->add(['b', 'a'], 'val3');
self::assertEquals(2, $map->count());
self::assertTrue($inserted);
self::assertEquals('val2', $map->get(['a', 'b']));
self::assertEquals('val3', $map->get(['c', 'a']));
self::assertEquals('val3', $map->get(['b', 'a']));
}
public function testOverwriteFalseFalseExact() : void
/**
* @testdox If all keys for multiple required keys exist in the map no new element will be created
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testInvalidOverwriteExact() : void
{
$map = new MultiMap(KeyType::MULTIPLE);
$inserted = $map->add(['a', 'b'], 'val2');
$inserted = $map->add(['a', 'c'], 'val3', false);
$inserted = $map->add(['a', 'c'], 'val4', false);
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$inserted = $map->add(['a', 'c'], 'val4');
self::assertEquals(2, $map->count());
self::assertFalse($inserted);
self::assertEquals('val2', $map->get(['a', 'b']));
self::assertEquals('val3', $map->get(['a', 'c']));
}
public function testSetExact() : void
/**
* @testdox If all keys for multiple required ordered keys exist in the map no new element will be created
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testInvalidOverwriteExactOrdered() : void
{
$map = new MultiMap(KeyType::MULTIPLE, OrderType::STRICT);
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$inserted = $map->add(['a', 'c'], 'val4');
self::assertEquals(2, $map->count());
self::assertFalse($inserted);
self::assertEquals('val2', $map->get(['a', 'b']));
self::assertEquals('val3', $map->get(['a', 'c']));
}
/**
* @testdox Values can be set/replaced by multiple required keys
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testSetByKeyExact() : void
{
$map = new MultiMap(KeyType::MULTIPLE);
$inserted = $map->add(['a', 'b'], 'val2');
$inserted = $map->add(['a', 'c'], 'val3', false);
$set = $map->set('d', 'val4');
self::assertFalse($set);
self::assertEquals(2, $map->count());
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$set = $map->set(['a', 'b'], 'val4');
self::assertEquals(2, $map->count());
self::assertTrue($set);
self::assertEquals('val4', $map->get(['a', 'b']));
self::assertEquals('val4', $map->get(['b', 'a']));
self::assertEquals('val3', $map->get(['a', 'c']));
}
public function testSetExactOrdered() : void
/**
* @testdox Values cannot be set/replaced if the multiple required keys don't match or exist
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testInvalidSetByKeyExact() : void
{
$map = new MultiMap(KeyType::MULTIPLE);
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$set = $map->set('a', 'val4');
self::assertFalse($set);
self::assertEquals(2, $map->count());
$set = $map->set(['b', 'c'], 'val4');
self::assertFalse($set);
}
/**
* @testdox Values can be set/replaced by multiple required ordered keys if the order is correct
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testSetByKeyExactOrdered() : void
{
$map = new MultiMap(KeyType::MULTIPLE, OrderType::STRICT);
$inserted = $map->add(['a', 'b'], 'val2');
$inserted = $map->add(['a', 'c'], 'val3', false);
$set = $map->set('c', 'val4');
self::assertFalse($set);
self::assertEquals(2, $map->count());
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$set = $map->set(['a', 'b'], 'val4');
self::assertEquals(2, $map->count());
self::assertTrue($set);
self::assertEquals('val4', $map->get(['a', 'b']));
}
/**
* @testdox Values cannot be set/replaced if the multiple required ordered keys don't match or exist in the correct order
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testInvalidSetByKeyExactOrdered() : void
{
$map = new MultiMap(KeyType::MULTIPLE, OrderType::STRICT);
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$set = $map->set(['b', 'a'], 'val5');
self::assertEquals(2, $map->count());
self::assertFalse($set);
}
public function testRemapExact() : void
/**
* @testdox Multiple keys cannot be remapped
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testInvalidRemapExact() : void
{
$map = new MultiMap(KeyType::MULTIPLE);
$inserted = $map->add(['a', 'b'], 'val2');
$remap = $map->remap(['a', 'b'], ['c', 'd']);
$map->add(['a', 'b'], 'val2');
$remap = $map->remap(['a', 'b'], ['c', 'd']);
self::assertFalse($remap);
}
/**
* @testdox All sibling key combinations can be found for multiple required keys
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testSiblingsExact() : void
{
$map = new MultiMap(KeyType::MULTIPLE);
$inserted = $map->add(['a', 'b'], 'val2');
$map->add(['a', 'b'], 'val2');
self::assertEquals([['a', 'b'], ['b', 'a']], $map->getSiblings(['a', 'b']));
}
/**
* @testdox For multiple required ordered keys don't exist any siblings
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testSiblingsExactOrdered() : void
{
$map = new MultiMap(KeyType::MULTIPLE, OrderType::STRICT);
$inserted = $map->add(['a', 'b'], 'val2');
$map->add(['a', 'b'], 'val2');
self::assertEquals([], $map->getSiblings(['a', 'b']));
}
/**
* @testdox A multiple required key combination for a value can be removed
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testRemoveExact() : void
{
$map = new MultiMap(KeyType::MULTIPLE);
$inserted = $map->add(['a', 'b'], 'val2');
$inserted = $map->add(['a', 'c'], 'val3', false);
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
self::assertCount(2, $map->keys());
self::assertCount(2, $map->values());
$removed = $map->remove(['a', 'b']);
self::assertTrue($removed);
self::assertCount(1, $map->keys());
self::assertCount(1, $map->values());
}
/**
* @testdox If a multiple required key combination doesn't exist it cannot be removed
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testInvalidRemoveExact() : void
{
$map = new MultiMap(KeyType::MULTIPLE);
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$removed = $map->remove('d');
self::assertFalse($removed);
$removed = $map->remove(['a', 'b']);
self::assertTrue($removed);
self::assertCount(1, $map->keys());
self::assertCount(1, $map->values());
self::assertFalse($map->removeKey(['a', 'b']));
}
/**
* @testdox A multiple required ordered key combination for a value can be removed
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testRemoveExactOrdered() : void
{
$map = new MultiMap(KeyType::MULTIPLE, OrderType::STRICT);
$inserted = $map->add(['a', 'b'], 'val2');
$inserted = $map->add(['a', 'c'], 'val3', false);
self::assertCount(2, $map->keys());
self::assertCount(2, $map->values());
$removed = $map->remove(['b', 'a']);
self::assertFalse($removed);
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$removed = $map->remove(['a', 'b']);
self::assertTrue($removed);
self::assertCount(1, $map->keys());
self::assertCount(1, $map->values());
}
/**
* @testdox If a multiple required ordered key combination doesn't exist it cannot be removed
* @covers phpOMS\Stdlib\Map\MultiMap
*/
public function testInvalidRemoveExactOrdered() : void
{
$map = new MultiMap(KeyType::MULTIPLE, OrderType::STRICT);
$map->add(['a', 'b'], 'val2');
$map->add(['a', 'c'], 'val3');
$removed = $map->remove(['b', 'a']);
self::assertFalse($removed);
$removed = $map->remove(['a', 'b']);
self::assertFalse($map->removeKey(['a', 'b']));
}
}

View File

@ -24,9 +24,16 @@ class OrderTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(2, OrderType::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(0, OrderType::LOOSE);
self::assertEquals(1, OrderType::STRICT);
}

View File

@ -24,9 +24,16 @@ class PriorityModeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(4, PriorityMode::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(1, PriorityMode::FIFO);
self::assertEquals(2, PriorityMode::LIFO);
self::assertEquals(4, PriorityMode::HIGHEST);

View File

@ -18,10 +18,16 @@ use phpOMS\Stdlib\Queue\PriorityMode;
use phpOMS\Stdlib\Queue\PriorityQueue;
/**
* @testdox phpOMS\tests\Stdlib\Queue\PriorityQueueTest: Priority queue
*
* @internal
*/
class PriorityQueueTest extends \PHPUnit\Framework\TestCase
{
/**
* @testdox The queue has the expected default values and functionality after initialization
* @covers phpOMS\Stdlib\Queue\PriorityQueue
*/
public function testDefault() : void
{
$queue = new PriorityQueue();
@ -32,18 +38,105 @@ class PriorityQueueTest extends \PHPUnit\Framework\TestCase
self::assertEquals(PriorityMode::FIFO, $queue->getType());
}
public function testGeneral() : void
/**
* @testdox Queue elements can be added with the default value of 1.0 and returned
* @covers phpOMS\Stdlib\Queue\PriorityQueue
*/
public function testInputOutput() : void
{
$queue = new PriorityQueue();
self::assertGreaterThan(0, $id1 = $queue->insert('a'));
self::assertEquals(1, $queue->count());
self::assertGreaterThan(0, $id = $queue->insert('a'));
self::assertEquals(['data' => 'a', 'priority' => 1.0], $queue->get($id));
}
self::assertGreaterThan(0, $id2 = $queue->insert('b', 2));
self::assertEquals(2, $queue->count());
/**
* @testdox Queue elements can be added with a priority
* @covers phpOMS\Stdlib\Queue\PriorityQueue
*/
public function testAddWithPriority() : void
{
$queue = new PriorityQueue();
self::assertGreaterThan(0, $id3 = $queue->insert('c', -1));
self::assertGreaterThan(0, $id = $queue->insert('b', 2));
self::assertEquals(2, $queue->get($id)['priority']);
self::assertGreaterThan(0, $id = $queue->insert('c', -1));
self::assertEquals(-1, $queue->get($id)['priority']);
}
/**
* @testdox The priority queue returns the correct amount of elements it holds
* @covers phpOMS\Stdlib\Queue\PriorityQueue
*/
public function testCount() : void
{
$queue = new PriorityQueue();
$queue->insert('a');
$queue->insert('b', 2);
$queue->insert('c', -1);
self::assertEquals(3, $queue->count());
}
/**
* @testdox A queue element can be removed
* @covers phpOMS\Stdlib\Queue\PriorityQueue
*/
public function testRemove() : void
{
$queue = new PriorityQueue();
$id = $queue->insert('a');
$queue->insert('b', 2);
$queue->insert('c', -1);
self::assertTrue($queue->delete($id));
self::assertEquals(2, $queue->count());
}
/**
* @testdox A none-existing queue element id cannot be removed
* @covers phpOMS\Stdlib\Queue\PriorityQueue
*/
public function testInvalidRemove() : void
{
$queue = new PriorityQueue();
$id = $queue->insert('a');
$queue->insert('b', 2);
$queue->insert('c', -1);
$queue->delete($id);
self::assertFalse($queue->delete($id));
self::assertEquals(2, $queue->count());
}
/**
* @testdox A removed or none-existing queue element returns a empty data
* @covers phpOMS\Stdlib\Queue\PriorityQueue
*/
public function testInvalidGet() : void
{
$queue = new PriorityQueue();
$id = $queue->insert('a');
$queue->delete($id);
self::assertEquals([], $queue->get($id));
}
/**
* @testdox The priority of all queue elements can be uniformly increased
* @covers phpOMS\Stdlib\Queue\PriorityQueue
*/
public function testPriorityIncreaseAll() : void
{
$queue = new PriorityQueue();
$queue->insert('a');
$queue->insert('b', 2);
$queue->insert('c', -1);
$queue->increaseAll(2);
self::assertEquals([
@ -52,9 +145,33 @@ class PriorityQueueTest extends \PHPUnit\Framework\TestCase
['data' => 'a', 'priority' => 3],
], \array_values($queue->getAll())
);
}
/**
* @testdox The priority or a queue element can be changed
* @covers phpOMS\Stdlib\Queue\PriorityQueue
*/
public function testPriorityChange() : void
{
$queue = new PriorityQueue();
$id1 = $queue->insert('a');
$queue->setPriority($id1, 3);
self::assertEquals(3, $queue->get($id1)['priority']);
}
/**
* @testdox The queue can be serialized and unserialized
* @covers phpOMS\Stdlib\Queue\PriorityQueue
*/
public function testSerialize() : void
{
$queue = new PriorityQueue();
$queue->insert('a');
$queue->insert('b', 2);
$queue->insert('c', -1);
$queue2 = new PriorityQueue();
$queue2->unserialize($queue->serialize());
@ -62,159 +179,93 @@ class PriorityQueueTest extends \PHPUnit\Framework\TestCase
self::assertEquals($queue->serialize(), $queue2->serialize());
}
/**
* @testdox A queue element can be popped from the que which also removes it from the queue
* @covers phpOMS\Stdlib\Queue\PriorityQueue
*/
public function testPop() : void
{
$queue = new PriorityQueue();
$id = $queue->insert('a');
self::assertEquals(['data' => 'a', 'priority' => 1.0], $queue->pop());
self::assertEquals([], $queue->get($id));
self::assertEquals(0, $queue->count());
}
/**
* @testdox A FIFO queue returns the elements in FIFO order
* @covers phpOMS\Stdlib\Queue\PriorityQueue
*/
public function testFIFO() : void
{
$queue = new PriorityQueue(PriorityMode::FIFO);
self::assertGreaterThan(0, $id1 = $queue->insert('a'));
self::assertEquals(1, $queue->count());
$queue->insert('a', -2);
$queue->insert('b', 2);
$queue->insert('c', -1);
self::assertGreaterThan(0, $id2 = $queue->insert('b', 2));
self::assertEquals(2, $queue->count());
self::assertGreaterThan(0, $id3 = $queue->insert('c', -1));
self::assertEquals(3, $queue->count());
self::assertEquals([
['data' => 'c', 'priority' => -1],
['data' => 'b', 'priority' => 2],
['data' => 'a', 'priority' => 1],
], \array_values($queue->getAll())
);
$queue->setPriority($id1, -2);
self::assertEquals(-2, $queue->get($id1)['priority']);
self::assertEquals([
['data' => 'c', 'priority' => -1],
['data' => 'b', 'priority' => 2],
['data' => 'a', 'priority' => -2],
], \array_values($queue->getAll())
);
self::assertEquals(['data' => 'a', 'priority' => -2], $queue->get($id1));
self::assertEquals(['data' => 'a', 'priority' => -2], $queue->pop());
self::assertEquals(2, $queue->count());
self::assertTrue($queue->delete($id3));
self::assertFalse($queue->delete($id3));
self::assertEquals(1, $queue->count());
self::assertEquals(['data' => 'b', 'priority' => 2], $queue->pop());
self::assertEquals(['data' => 'c', 'priority' => -1], $queue->pop());
}
/**
* @testdox A LIFO queue returns the elements in LIFO order
* @covers phpOMS\Stdlib\Queue\PriorityQueue
*/
public function testLIFO() : void
{
$queue = new PriorityQueue(PriorityMode::LIFO);
self::assertGreaterThan(0, $id1 = $queue->insert('a'));
self::assertEquals(1, $queue->count());
$queue->insert('a', -2);
$queue->insert('b', 2);
$queue->insert('c', -1);
self::assertGreaterThan(0, $id2 = $queue->insert('b', 2));
self::assertEquals(2, $queue->count());
self::assertGreaterThan(0, $id3 = $queue->insert('c', -1));
self::assertEquals(3, $queue->count());
self::assertEquals([
['data' => 'a', 'priority' => 1],
['data' => 'b', 'priority' => 2],
['data' => 'c', 'priority' => -1],
], \array_values($queue->getAll())
);
$queue->setPriority($id1, 3);
self::assertEquals(3, $queue->get($id1)['priority']);
self::assertEquals([
['data' => 'a', 'priority' => 3],
['data' => 'b', 'priority' => 2],
['data' => 'c', 'priority' => -1],
], \array_values($queue->getAll())
);
self::assertEquals(['data' => 'c', 'priority' => -1], $queue->get($id3));
self::assertEquals(['data' => 'c', 'priority' => -1], $queue->pop());
self::assertEquals(2, $queue->count());
self::assertTrue($queue->delete($id1));
self::assertFalse($queue->delete($id1));
self::assertEquals(1, $queue->count());
self::assertEquals(['data' => 'b', 'priority' => 2], $queue->pop());
self::assertEquals(['data' => 'a', 'priority' => -2], $queue->pop());
}
/**
* @testdox A highest queue returns the elements in highest priority order
* @covers phpOMS\Stdlib\Queue\PriorityQueue
*/
public function testHighest() : void
{
$queue = new PriorityQueue(PriorityMode::HIGHEST);
self::assertGreaterThan(0, $id1 = $queue->insert('a'));
self::assertEquals(1, $queue->count());
$queue->insert('a', -2);
$queue->insert('b', 2);
$queue->insert('c', -1);
self::assertGreaterThan(0, $id2 = $queue->insert('b', 2));
self::assertEquals(2, $queue->count());
self::assertGreaterThan(0, $id3 = $queue->insert('c', -1));
self::assertEquals(3, $queue->count());
self::assertEquals([
['data' => 'c', 'priority' => -1],
['data' => 'a', 'priority' => 1],
['data' => 'b', 'priority' => 2],
], \array_values($queue->getAll())
);
$queue->setPriority($id1, 3);
self::assertEquals(3, $queue->get($id1)['priority']);
self::assertEquals([
['data' => 'c', 'priority' => -1],
['data' => 'b', 'priority' => 2],
['data' => 'a', 'priority' => 3],
], \array_values($queue->getAll())
);
self::assertEquals(['data' => 'a', 'priority' => 3], $queue->get($id1));
self::assertEquals(['data' => 'a', 'priority' => 3], $queue->pop());
self::assertEquals(2, $queue->count());
self::assertTrue($queue->delete($id2));
self::assertFalse($queue->delete($id2));
self::assertEquals(1, $queue->count());
self::assertEquals(['data' => 'b', 'priority' => 2], $queue->pop());
self::assertEquals(['data' => 'c', 'priority' => -1], $queue->pop());
self::assertEquals(['data' => 'a', 'priority' => -2], $queue->pop());
}
/**
* @testdox A lowest queue returns the elements in lowest priority order
* @covers phpOMS\Stdlib\Queue\PriorityQueue
*/
public function testLowest() : void
{
$queue = new PriorityQueue(PriorityMode::LOWEST);
self::assertGreaterThan(0, $id1 = $queue->insert('a'));
self::assertEquals(1, $queue->count());
$queue->insert('a', -2);
$queue->insert('b', 2);
$queue->insert('c', -1);
self::assertGreaterThan(0, $id2 = $queue->insert('b', 2));
self::assertEquals(2, $queue->count());
self::assertGreaterThan(0, $id3 = $queue->insert('c', -1));
self::assertEquals(3, $queue->count());
self::assertEquals([
['data' => 'b', 'priority' => 2],
['data' => 'a', 'priority' => 1],
['data' => 'c', 'priority' => -1],
], \array_values($queue->getAll())
);
$queue->setPriority($id3, 2);
self::assertEquals(2, $queue->get($id3)['priority']);
self::assertEquals([
['data' => 'b', 'priority' => 2],
['data' => 'c', 'priority' => 2],
['data' => 'a', 'priority' => 1],
], \array_values($queue->getAll())
);
self::assertEquals(['data' => 'a', 'priority' => 1], $queue->get($id1));
self::assertEquals(['data' => 'a', 'priority' => 1], $queue->pop());
self::assertEquals(2, $queue->count());
self::assertTrue($queue->delete($id2));
self::assertFalse($queue->delete($id2));
self::assertEquals(1, $queue->count());
self::assertEquals(['data' => 'a', 'priority' => -2], $queue->pop());
self::assertEquals(['data' => 'c', 'priority' => -1], $queue->pop());
self::assertEquals(['data' => 'b', 'priority' => 2], $queue->pop());
}
/**
* @testdox A invalid priority queue type throws a InvalidEnumValue
* @covers phpOMS\Stdlib\Queue\PriorityQueue
*/
public function testInvalidPriority() : void
{
self::expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class);

View File

@ -24,11 +24,24 @@ class ContentPutModeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(4, ContentPutMode::getConstants());
self::assertEquals(ContentPutMode::getConstants(), \array_unique(ContentPutMode::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(ContentPutMode::getConstants(), \array_unique(ContentPutMode::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(1, ContentPutMode::APPEND);
self::assertEquals(2, ContentPutMode::PREPEND);
self::assertEquals(4, ContentPutMode::REPLACE);

View File

@ -24,11 +24,24 @@ class ExtensionTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(13, ExtensionType::getConstants());
self::assertEquals(ExtensionType::getConstants(), \array_unique(ExtensionType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(ExtensionType::getConstants(), \array_unique(ExtensionType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(1, ExtensionType::UNKNOWN);
self::assertEquals(2, ExtensionType::CODE);
self::assertEquals(4, ExtensionType::AUDIO);

View File

@ -26,9 +26,16 @@ class SystemTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(4, SystemType::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(1, SystemType::UNKNOWN);
self::assertEquals(2, SystemType::WIN);
self::assertEquals(3, SystemType::LINUX);

View File

@ -24,11 +24,24 @@ class OrientationTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(2, OrientationType::getConstants());
self::assertEquals(OrientationType::getConstants(), \array_unique(OrientationType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(OrientationType::getConstants(), \array_unique(OrientationType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(0, OrientationType::HORIZONTAL);
self::assertEquals(1, OrientationType::VERTICAL);
}

View File

@ -24,11 +24,24 @@ class AngleTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(10, AngleType::getConstants());
self::assertEquals(AngleType::getConstants(), \array_unique(AngleType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(AngleType::getConstants(), \array_unique(AngleType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('deg', AngleType::DEGREE);
self::assertEquals('rad', AngleType::RADIAN);
self::assertEquals('arcsec', AngleType::SECOND);

View File

@ -24,11 +24,24 @@ class AreaTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(13, AreaType::getConstants());
self::assertEquals(AreaType::getConstants(), \array_unique(AreaType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(AreaType::getConstants(), \array_unique(AreaType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('ft', AreaType::SQUARE_FEET);
self::assertEquals('m', AreaType::SQUARE_METERS);
self::assertEquals('km', AreaType::SQUARE_KILOMETERS);

View File

@ -24,11 +24,24 @@ class EnergyPowerTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(9, EnergyPowerType::getConstants());
self::assertEquals(EnergyPowerType::getConstants(), \array_unique(EnergyPowerType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(EnergyPowerType::getConstants(), \array_unique(EnergyPowerType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('kWh', EnergyPowerType::KILOWATT_HOUERS);
self::assertEquals('MWh', EnergyPowerType::MEGAWATT_HOUERS);
self::assertEquals('kt', EnergyPowerType::KILOTONS);

View File

@ -24,9 +24,16 @@ class FileSizeTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(10, FileSizeType::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('TB', FileSizeType::TERRABYTE);
self::assertEquals('GB', FileSizeType::GIGABYTE);
self::assertEquals('MB', FileSizeType::MEGABYTE);

View File

@ -24,11 +24,24 @@ class LengthTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(21, LengthType::getConstants());
self::assertEquals(LengthType::getConstants(), \array_unique(LengthType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(LengthType::getConstants(), \array_unique(LengthType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('mi', LengthType::MILES);
self::assertEquals('m', LengthType::METERS);
self::assertEquals('micron', LengthType::MICROMETER);

View File

@ -24,11 +24,24 @@ class PressureTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(13, PressureType::getConstants());
self::assertEquals(PressureType::getConstants(), \array_unique(PressureType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(PressureType::getConstants(), \array_unique(PressureType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('Pa', PressureType::PASCALS);
self::assertEquals('bar', PressureType::BAR);
self::assertEquals('psi', PressureType::POUND_PER_SQUARE_INCH);

View File

@ -24,11 +24,24 @@ class SpeedTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(34, SpeedType::getConstants());
self::assertEquals(SpeedType::getConstants(), \array_unique(SpeedType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(SpeedType::getConstants(), \array_unique(SpeedType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('mpd', SpeedType::MILES_PER_DAY);
self::assertEquals('mph', SpeedType::MILES_PER_HOUR);
self::assertEquals('mpm', SpeedType::MILES_PER_MINUTE);

View File

@ -24,11 +24,24 @@ class TemperatureTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(8, TemperatureType::getConstants());
self::assertEquals(TemperatureType::getConstants(), \array_unique(TemperatureType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(TemperatureType::getConstants(), \array_unique(TemperatureType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('celsius', TemperatureType::CELSIUS);
self::assertEquals('fahrenheit', TemperatureType::FAHRENHEIT);
self::assertEquals('kelvin', TemperatureType::KELVIN);

View File

@ -24,11 +24,24 @@ class TimeTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(9, TimeType::getConstants());
self::assertEquals(TimeType::getConstants(), \array_unique(TimeType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(TimeType::getConstants(), \array_unique(TimeType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('ms', TimeType::MILLISECONDS);
self::assertEquals('s', TimeType::SECONDS);
self::assertEquals('i', TimeType::MINUTES);

View File

@ -24,11 +24,24 @@ class VolumeTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(38, VolumeType::getConstants());
self::assertEquals(VolumeType::getConstants(), \array_unique(VolumeType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(VolumeType::getConstants(), \array_unique(VolumeType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('UK gal', VolumeType::UK_GALLON);
self::assertEquals('US gal lqd', VolumeType::US_GALLON_LIQUID);
self::assertEquals('US gal dry', VolumeType::US_GALLON_DRY);

View File

@ -24,11 +24,24 @@ class WeightTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(14, WeightType::getConstants());
self::assertEquals(WeightType::getConstants(), \array_unique(WeightType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(WeightType::getConstants(), \array_unique(WeightType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals('mg', WeightType::MICROGRAM);
self::assertEquals('mug', WeightType::MILLIGRAM);
self::assertEquals('g', WeightType::GRAM);

View File

@ -24,11 +24,24 @@ class DistributionTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(2, DistributionType::getConstants());
self::assertEquals(DistributionType::getConstants(), \array_unique(DistributionType::getConstants()));
}
/**
* @coversNothing
*/
public function testUnique() : void
{
self::assertEquals(DistributionType::getConstants(), \array_unique(DistributionType::getConstants()));
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(0, DistributionType::UNIFORM);
self::assertEquals(1, DistributionType::NORMAL);
}

View File

@ -24,9 +24,16 @@ class IbanErrorTypeTest extends \PHPUnit\Framework\TestCase
/**
* @coversNothing
*/
public function testEnums() : void
public function testEnumCount() : void
{
self::assertCount(5, IbanErrorType::getConstants());
}
/**
* @coversNothing
*/
public function testEnums() : void
{
self::assertEquals(1, IbanErrorType::INVALID_COUNTRY);
self::assertEquals(2, IbanErrorType::INVALID_LENGTH);
self::assertEquals(4, IbanErrorType::INVALID_CHECKSUM);