Skip to content

Commit

Permalink
Improve AutomaticLogoutListenerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Frantisek Vesely committed Jul 30, 2017
1 parent 72718f7 commit 55abc5f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
17 changes: 17 additions & 0 deletions tests/Authentication/AutomaticLogoutListenerTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ final class AutomaticLogoutListenerTest extends \Tester\TestCase
$listener->check();

Assert::false($userStorage->isAuthenticated());
Assert::same($identity, $userStorage->getIdentity());
}

public function testCheckNotFoundEntity(): void
{
$userStorage = new UserStorage();
$identity = new Identity('foo', 'foo', '', false);
$userStorage->setAuthenticated(true);
$userStorage->setIdentity($identity);
$listener = new AutomaticLogoutListener(new AuthenticationManager($userStorage));

$identity->deactivate();
$listener->check();

Assert::false($userStorage->isAuthenticated());
Assert::type('null', $userStorage->getIdentity());
//
}

}
Expand Down
44 changes: 43 additions & 1 deletion tests/Authentication/Mocks/Identity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@

namespace GrandMediaTests\SecurityDoctrine\Authentication\Mocks;

use Doctrine\ORM\EntityNotFoundException;

final class Identity extends \GrandMedia\SecurityDoctrine\Authentication\Identity
{

/** @var string */
private $name;

public function __construct(string $name, string $password, string $role = '')
/** @var bool */
private $entityFound;

public function __construct(
string $name,
string $password,
string $role = '',
bool $entityFound = true
)
{
$this->name = $name;

parent::__construct($password, $role);

$this->entityFound = $entityFound;
}

public function getId(): string
Expand All @@ -22,7 +34,37 @@ public function getId(): string

public function getName(): string
{
$this->loadProxy();

return $this->name;
}

public function verify(string $password): bool
{
$this->loadProxy();

return parent::verify($password);
}

public function isActive(): bool
{
$this->loadProxy();

return parent::isActive();
}

public function getRoles(): array
{
$this->loadProxy();

return parent::getRoles();
}

private function loadProxy(): void
{
if (!$this->entityFound) {
throw new EntityNotFoundException();
}
}

}

0 comments on commit 55abc5f

Please sign in to comment.