From 60a071c428b4639c805c6d79fd75d33cb3b00c94 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 4 Nov 2018 12:40:57 +0100 Subject: [PATCH] Implemented more tests for user --- application/src/Entity/User.php | 1 + .../Unit/Entity/Attribut/UserAttributTest.php | 36 +++++++++++++++++++ .../Entity/Source/Data/UserSourceTest.php | 2 ++ application/tests/Unit/Entity/UserTest.php | 1 + 4 files changed, 40 insertions(+) create mode 100644 application/tests/Unit/Entity/Attribut/UserAttributTest.php diff --git a/application/src/Entity/User.php b/application/src/Entity/User.php index cb4b939..256e15a 100644 --- a/application/src/Entity/User.php +++ b/application/src/Entity/User.php @@ -54,6 +54,7 @@ class User extends BaseUser implements UserInterface parent::__construct(); $this->isActive = true; $this->source = new UserSource(); + $this->source->setUser($this); //LawModificator::grantAllRights($this->source->getNode()->getLaw(), $this->source->getNode()); } } diff --git a/application/tests/Unit/Entity/Attribut/UserAttributTest.php b/application/tests/Unit/Entity/Attribut/UserAttributTest.php new file mode 100644 index 0000000..4236080 --- /dev/null +++ b/application/tests/Unit/Entity/Attribut/UserAttributTest.php @@ -0,0 +1,36 @@ +user = new class() implements UserAttributInterface { + use UserAttribut; + }; + } + + public function testConstructor(): void + { + $this->expectException(\TypeError::class); + $this->user->getUser(); + } + + public function testAccessors(): void + { + $user = $this->createMock(UserInterface::class); + $this->assertNull($this->user->setUser($user)); + $this->assertEquals($user, $this->user->getUser()); + } +} diff --git a/application/tests/Unit/Entity/Source/Data/UserSourceTest.php b/application/tests/Unit/Entity/Source/Data/UserSourceTest.php index bfa868c..4acd747 100644 --- a/application/tests/Unit/Entity/Source/Data/UserSourceTest.php +++ b/application/tests/Unit/Entity/Source/Data/UserSourceTest.php @@ -24,5 +24,7 @@ class UserSourceTest extends TestCase { $this->assertInstanceOf(Collection::class, $this->userSource->getMemberships()); $this->assertInstanceOf(NameSourceInterface::class, $this->userSource->getNameSource()); + $this->expectException(\TypeError::class); + $this->userSource->getUser(); } } diff --git a/application/tests/Unit/Entity/UserTest.php b/application/tests/Unit/Entity/UserTest.php index ca64f70..eb9ba1a 100644 --- a/application/tests/Unit/Entity/UserTest.php +++ b/application/tests/Unit/Entity/UserTest.php @@ -47,5 +47,6 @@ class UserTest extends TestCase public function testSource(): void { $this->assertInstanceOf(UserSource::class, $this->user->getSource()); + $this->assertEquals($this->user, $this->user->getSource()->getUser()); } }