From bd2318ab5b98366853873acb7548c9ab392bbd06 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 3 Feb 2019 00:30:53 +0100 Subject: [PATCH] Made user for UserAttribut optional --- .../symfony/src/Attribut/UserAttribut.php | 18 +++++++++++++++++- .../src/Attribut/UserAttributInterface.php | 11 +++++++++++ .../tests/Unit/Attribut/UserAttributTest.php | 5 +++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/application/symfony/src/Attribut/UserAttribut.php b/application/symfony/src/Attribut/UserAttribut.php index 286682e..e24b00c 100644 --- a/application/symfony/src/Attribut/UserAttribut.php +++ b/application/symfony/src/Attribut/UserAttribut.php @@ -7,21 +7,37 @@ use App\Entity\UserInterface; /** * @author kevinfrantz + * + * @see UserAttributInterface */ trait UserAttribut { /** - * @var User + * @var User|null */ protected $user; + /** + * @param UserInterface $user + */ public function setUser(UserInterface $user): void { $this->user = $user; } + /** + * @return UserInterface + */ public function getUser(): UserInterface { return $this->user; } + + /** + * @return bool + */ + public function hasUser(): bool + { + return isset($this->user); + } } diff --git a/application/symfony/src/Attribut/UserAttributInterface.php b/application/symfony/src/Attribut/UserAttributInterface.php index 8ff9d0b..a06b15d 100644 --- a/application/symfony/src/Attribut/UserAttributInterface.php +++ b/application/symfony/src/Attribut/UserAttributInterface.php @@ -9,7 +9,18 @@ use App\Entity\UserInterface; */ interface UserAttributInterface { + /** + * @param UserInterface $user + */ public function setUser(UserInterface $user): void; + /** + * @return UserInterface + */ public function getUser(): UserInterface; + + /** + * @return bool Returns if a user is set + */ + public function hasUser(): bool; } diff --git a/application/symfony/tests/Unit/Attribut/UserAttributTest.php b/application/symfony/tests/Unit/Attribut/UserAttributTest.php index f64572f..9d73a4c 100644 --- a/application/symfony/tests/Unit/Attribut/UserAttributTest.php +++ b/application/symfony/tests/Unit/Attribut/UserAttributTest.php @@ -7,6 +7,9 @@ use App\Attribut\UserAttributInterface; use App\Attribut\UserAttribut; use App\Entity\UserInterface; +/** + * @author kevinfrantz + */ class UserAttributTest extends TestCase { /** @@ -23,6 +26,7 @@ class UserAttributTest extends TestCase public function testConstructor(): void { + $this->assertFalse($this->user->hasUser()); $this->expectException(\TypeError::class); $this->user->getUser(); } @@ -32,5 +36,6 @@ class UserAttributTest extends TestCase $user = $this->createMock(UserInterface::class); $this->assertNull($this->user->setUser($user)); $this->assertEquals($user, $this->user->getUser()); + $this->assertTrue($this->user->hasUser()); } }