From dcf63ad927fa49dfd7ff1184efc4e0c6f7cb026d Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 16 Oct 2023 22:23:57 +0000 Subject: [PATCH] test fixes --- tests/Models/AccountMapperTest.php | 12 ++++ tests/Models/AddressTest.php | 12 ++++ tests/Models/AppTest.php | 35 +++++++++++- tests/Models/DataChangeTest.php | 72 ++++++++++++++++++++++++ tests/Models/NullAppTest.php | 52 +++++++++++++++++ tests/Models/NullGroupPermissionTest.php | 10 ++++ 6 files changed, 190 insertions(+), 3 deletions(-) create mode 100644 tests/Models/DataChangeTest.php create mode 100644 tests/Models/NullAppTest.php diff --git a/tests/Models/AccountMapperTest.php b/tests/Models/AccountMapperTest.php index 56e313a..ccbd0f7 100755 --- a/tests/Models/AccountMapperTest.php +++ b/tests/Models/AccountMapperTest.php @@ -16,6 +16,7 @@ namespace Modules\Admin\tests\Models; use Modules\Admin\Models\Account; use Modules\Admin\Models\AccountMapper; +use Modules\Admin\Models\NullAccount; use phpOMS\Account\AccountStatus; use phpOMS\Account\AccountType; use phpOMS\Auth\LoginReturnType; @@ -162,4 +163,15 @@ final class AccountMapperTest extends \PHPUnit\Framework\TestCase self::assertEquals('admin', $accountR->login); self::assertGreaterThan(0, $accountR->getPermissions()); } + + /** + * @covers Modules\Admin\Models\AccountMapper + * @group module + */ + public function testGetWithPermissionInvalidId() : void + { + $accountR = AccountMapper::getWithPermissions(0); + + self::assertInstanceOf(NullAccount::class, $accountR); + } } diff --git a/tests/Models/AddressTest.php b/tests/Models/AddressTest.php index 96c8c00..e2120dc 100755 --- a/tests/Models/AddressTest.php +++ b/tests/Models/AddressTest.php @@ -132,4 +132,16 @@ final class AddressTest extends \PHPUnit\Framework\TestCase $this->address->unserialize(\json_encode($expected)); self::assertEquals(\json_encode($expected), $this->address->serialize()); } + + public function testUnserializeInvalidType() : void + { + $this->address->unserialize(true); + self::assertTrue(true); + } + + public function testUnserializeInvalidJson() : void + { + $this->address->unserialize('{{}'); + self::assertTrue(true); + } } diff --git a/tests/Models/AppTest.php b/tests/Models/AppTest.php index cc615d1..b94067f 100755 --- a/tests/Models/AppTest.php +++ b/tests/Models/AppTest.php @@ -15,6 +15,8 @@ declare(strict_types=1); namespace Modules\Admin\tests\Models; use Modules\Admin\Models\App; +use phpOMS\Application\ApplicationStatus; +use phpOMS\Application\ApplicationType; /** * @testdox Modules\Admin\tests\Models\AppTest: App model @@ -24,13 +26,40 @@ use Modules\Admin\Models\App; final class AppTest extends \PHPUnit\Framework\TestCase { /** - * @testdox The account has the expected default values after initialization * @covers Modules\Admin\Models\App * @group module */ public function testDefault() : void { - $account = new App(); - self::assertEquals(0, $account->id); + $app = new App(); + self::assertEquals(0, $app->id); + } + + public function testToArray() : void + { + $app = new App(); + self::assertEquals( + [ + 'id' => 0, + 'name' => '', + 'type' => ApplicationType::WEB, + 'status' => ApplicationStatus::NORMAL, + ], + $app->toArray() + ); + } + + public function testJsonSerialize() : void + { + $app = new App(); + self::assertEquals( + [ + 'id' => 0, + 'name' => '', + 'type' => ApplicationType::WEB, + 'status' => ApplicationStatus::NORMAL, + ], + $app->jsonSerialize() + ); } } diff --git a/tests/Models/DataChangeTest.php b/tests/Models/DataChangeTest.php new file mode 100644 index 0000000..e82f75e --- /dev/null +++ b/tests/Models/DataChangeTest.php @@ -0,0 +1,72 @@ +id); + self::assertEquals(32, \strlen($change->getHash())); + self::assertInstanceOf('\DateTimeImmutable', $change->createdAt); + } + + public function testReHash() : void + { + $change = new DataChange(); + $hash = $change->getHash(); + + $change->reHash(); + self::assertNotEquals($hash, $change->getHash()); + } + + public function testToArray() : void + { + $change = new DataChange(); + self::assertEquals( + [ + 'id' => 0, + 'data' => '', + ], + $change->toArray() + ); + } + + public function testJsonSerialize() : void + { + $change = new DataChange(); + self::assertEquals( + [ + 'id' => 0, + 'data' => '', + ], + $change->jsonSerialize() + ); + } +} diff --git a/tests/Models/NullAppTest.php b/tests/Models/NullAppTest.php new file mode 100644 index 0000000..035c3b2 --- /dev/null +++ b/tests/Models/NullAppTest.php @@ -0,0 +1,52 @@ +id); + } + + /** + * @covers Modules\Admin\Models\NullModule + * @group module + */ + public function testJsonSerialize() : void + { + $null = new NullApp(2); + self::assertEquals(['id' => 2], $null); + } +} diff --git a/tests/Models/NullGroupPermissionTest.php b/tests/Models/NullGroupPermissionTest.php index 0117a45..f85126d 100755 --- a/tests/Models/NullGroupPermissionTest.php +++ b/tests/Models/NullGroupPermissionTest.php @@ -39,4 +39,14 @@ final class NullGroupPermissionTest extends \PHPUnit\Framework\TestCase $null = new NullGroupPermission(2); self::assertEquals(2, $null->id); } + + /** + * @covers Modules\Admin\Models\NullModule + * @group module + */ + public function testJsonSerialize() : void + { + $null = new NullGroupPermission(2); + self::assertEquals(['id' => 2], $null); + } }