mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-10 06:27:24 +01:00
Made user for UserAttribut optional
This commit is contained in:
parent
aa735367d9
commit
bd2318ab5b
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user