-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/gibmyx/quicktrack-api
- Loading branch information
Showing
3 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
tests/Unit/Quicktrack/User/Application/Auth/CheckAuthRequestMother.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
53
tests/Unit/Quicktrack/User/Application/Auth/CheckAuthTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters