Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarcanor committed Oct 15, 2022
2 parents 83b0507 + 7096eaa commit cff417f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Tests\Unit\Quicktrack\User\Application\Auth;

use Quicktrack\User\Application\Auth\CheckAuthRequest;
use Quicktrack\User\Domain\ValueObjects\UserToken;

final class CheckAuthRequestMother
{
public static function create(UserToken $token): CheckAuthRequest
{
return new CheckAuthRequest($token->value());
}
}
53 changes: 53 additions & 0 deletions tests/Unit/Quicktrack/User/Application/Auth/CheckAuthTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace Tests\Unit\Quicktrack\User\Application\Auth;

use PHPUnit\Framework\MockObject\MockObject;
use Quicktrack\User\Application\Auth\CheckAuth;
use Quicktrack\User\Domain\Contract\AuthRepository;
use Quicktrack\User\Domain\ValueObjects\UserToken;
use Tests\Shared\Infrastructure\Laravel\TestCase;
use Tests\Unit\Quicktrack\User\Domain\UserTokenMother;

final class CheckAuthTest extends TestCase
{
/**
* @test
*/
public function itShouldCheckAuthTrue()
{
$token = UserTokenMother::random();
$request = CheckAuthRequestMother::create($token);
$repository = $this->createMock(AuthRepository::class);
$this->shouldResponseReposiroty($repository, $token, true);

$response = (new CheckAuth($repository))->__invoke($request);
$this->assertEquals(true, $response);
}

/**
* @test
*/
public function itShouldCheckAuthFalse()
{
$token = UserTokenMother::random();
$request = CheckAuthRequestMother::create($token);
$repository = $this->createMock(AuthRepository::class);
$this->shouldResponseReposiroty($repository, $token, false);

$response = (new CheckAuth($repository))->__invoke($request);
$this->assertEquals(false, $response);
}

private function shouldResponseReposiroty(
MockObject $repository,
UserToken $token,
bool $result
): void {
$repository->method('validateAuthToken')
->with($token)
->willReturn($result);
}
}
12 changes: 11 additions & 1 deletion tests/Unit/Quicktrack/User/Domain/UserTokenMother.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@

declare(strict_types=1);


namespace Tests\Unit\Quicktrack\User\Domain;

use Quicktrack\User\Domain\ValueObjects\UserToken;
use Tests\Unit\Shared\Domain\NameMother;

final class UserTokenMother
{
private static function create(
string $token,
): UserToken {
return new UserToken($token);
}

public static function random(): UserToken
{
return self::create(NameMother::random());
}
}

0 comments on commit cff417f

Please sign in to comment.