Commit d16541d1 authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Add tests for the commander authorizer

parent a1e3ed89
<?php
namespace Tests\Unit\Source\UseCases\Door\Access\Authorizers;
use Carbon\Carbon;
use Source\Entities\User;
use PHPUnit\Framework\TestCase;
use Tests\Doubles\AuthorizerStub;
use Source\UseCases\Door\Access\AccessAuthorizer;
use Source\UseCases\Door\Access\Authorizers\CommanderAuthorizer;
class CommanderAuthorizerTest extends TestCase
{
/**
* @var \Source\UseCases\Door\Access\Authorizers\CommanderAuthorizer
*/
protected CommanderAuthorizer $authorizer;
/**
* @var \Tests\Doubles\AuthorizerStub
*/
protected AuthorizerStub $auth;
protected int $status;
public function setUp(): void
{
parent::setUp();
$this->auth = new AuthorizerStub();
$this->authorizer = new CommanderAuthorizer($this->auth);
}
protected function handleTest(?User $user): void
{
$this->status = $this->authorizer->check($user, Carbon::now(), '', '', null);
}
protected function createUser(int $id): User
{
return new User($id, '', '', '', '');
}
/**
* @test
*/
public function it_does_nothing_if_there_is_no_given_user(): void
{
$this->handleTest(null);
$this->assertEquals(AccessAuthorizer::CONTINUE, $this->status);
}
/**
* @test
*/
public function it_allows_for_an_authorized_user(): void
{
$this->auth->setNext(true);
$this->handleTest($this->createUser(1));
$this->assertEquals(AccessAuthorizer::ALLOW, $this->status);
}
/**
* @test
*/
public function it_does_nothing_for_normal_users(): void
{
$this->auth->setNext(false);
$this->handleTest($this->createUser(1));
$this->assertEquals(AccessAuthorizer::CONTINUE, $this->status);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment