From 99f429f7ed1bf2fe7aa7e0ccf2c18f748226709a Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 19 Apr 2019 19:01:59 +0200 Subject: [PATCH] Improve account test --- tests/Account/AccountManagerTest.php | 93 +++++++++++++++++++++------- 1 file changed, 72 insertions(+), 21 deletions(-) diff --git a/tests/Account/AccountManagerTest.php b/tests/Account/AccountManagerTest.php index 22cab2477..3d508448a 100644 --- a/tests/Account/AccountManagerTest.php +++ b/tests/Account/AccountManagerTest.php @@ -18,45 +18,96 @@ use phpOMS\Account\AccountManager; require_once __DIR__ . '/../Autoloader.php'; +/** + * @testdox phpOMS\tests\Account\AccountManager: Account/user manager to handle/access loaded accounts + */ class AccountManagerTest extends \PHPUnit\Framework\TestCase { + protected $manager = null; + protected $account = null; + protected function setUp() : void + { + $this->manager = new AccountManager($GLOBALS['httpSession']); + + $this->account = new Account(3); + $this->account->generatePassword('abcd'); + } + + /** + * @testdox The manager has the expected member variables + */ public function testAttributes() : void { - $manager = new AccountManager($GLOBALS['httpSession']); - self::assertInstanceOf('\phpOMS\Account\AccountManager', $manager); + self::assertInstanceOf('\phpOMS\Account\AccountManager', $this->manager); /* Testing members */ - self::assertObjectHasAttribute('accounts', $manager); + self::assertObjectHasAttribute('accounts', $this->manager); } + /** + * @testdox The manager has the expected default values after initialization + */ public function testDefault() : void { - $manager = new AccountManager($GLOBALS['httpSession']); - - self::assertEquals(0, $manager->count()); - self::assertInstanceOf('\phpOMS\Account\Account', $manager->get(0)); - self::assertInstanceOf('\phpOMS\Account\NullAccount', $manager->get(-1)); + self::assertEquals(0, $this->manager->count()); + self::assertInstanceOf('\phpOMS\Account\Account', $this->manager->get(0)); + self::assertInstanceOf('\phpOMS\Account\NullAccount', $this->manager->get(-1)); } - public function testSetGet() : void + /** + * @testdox An account can be added to the manager + */ + public function testAddAccount() : void { - $manager = new AccountManager($GLOBALS['httpSession']); - $account = new Account(3); - - $account->generatePassword('abcd'); - - $added = $manager->add($account); + $added = $this->manager->add($this->account); self::assertTrue($added); - self::assertEquals($account, $manager->get($account->getId())); - self::assertEquals(1, $manager->count()); + self::assertEquals(1, $this->manager->count()); + } - $added = $manager->add($account); + /** + * @testdox An account can be retrieved from the manager + */ + public function testRetrieveAccount() : void + { + $this->manager->add($this->account); + self::assertEquals($this->account, $this->manager->get($this->account->getId())); + } + + /** + * @testdox An account can only be added once to the account manager (no duplication) + */ + public function testNoAccountDuplication() : void + { + $this->manager->add($this->account); + $added = $this->manager->add($this->account); self::assertFalse($added); - self::assertTrue($manager->remove($account->getId())); - self::assertFalse($manager->remove(-1)); - self::assertEquals(0, $manager->count()); + self::assertTrue($this->manager->remove($this->account->getId())); + self::assertFalse($this->manager->remove(-1)); + self::assertEquals(0, $this->manager->count()); + } + /** + * @testdox An account can be removed from the account manager + */ + public function testRemoveAccount() : void + { + $this->manager->add($this->account); + self::assertTrue($this->manager->remove($this->account->getId())); + self::assertEquals(0, $this->manager->count()); + self::assertFalse($this->manager->remove(-1)); + } + + /** + * @testdox Only a valid account can be removed from the manager + */ + public function testRemoveOnlyValidAccount() : void + { + $this->manager->add($this->account); + self::assertFalse($this->manager->remove(-1)); + self::assertEquals(1, $this->manager->count()); + self::assertTrue($this->manager->remove($this->account->getId())); + self::assertEquals(0, $this->manager->count()); } }