-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Adjustment due to the immutable times and authentication check
- Loading branch information
Showing
8 changed files
with
77 additions
and
19 deletions.
There are no files selected for viewing
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
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
15 changes: 15 additions & 0 deletions
15
src/App/Hydrator/DateTimeImmutableFormatterStrategyFactory.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,15 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App\Hydrator; | ||
|
||
use Laminas\Hydrator\Strategy\DateTimeFormatterStrategy; | ||
use Laminas\Hydrator\Strategy\DateTimeImmutableFormatterStrategy; | ||
use Psr\Container\ContainerInterface; | ||
|
||
readonly class DateTimeImmutableFormatterStrategyFactory | ||
{ | ||
public function __invoke(ContainerInterface $container): DateTimeImmutableFormatterStrategy | ||
{ | ||
return new DateTimeImmutableFormatterStrategy(new DateTimeFormatterStrategy('Y-m-d H:i:s')); | ||
} | ||
} |
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
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
33 changes: 33 additions & 0 deletions
33
tests/Unit/App/Handler/Authentication/LoginHandlerTest.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,33 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Test\Unit\App\Handler\Authentication; | ||
|
||
use App\Entity\User; | ||
use App\Handler\Authentication\LoginHandler; | ||
use Laminas\Diactoros\Response\JsonResponse; | ||
use Test\Data\Entity\UserTestEntity; | ||
use Test\Unit\App\Handler\AbstractHandler; | ||
|
||
use function json_decode; | ||
|
||
class LoginHandlerTest extends AbstractHandler | ||
{ | ||
public function testUserIsLoggedIn(): void | ||
{ | ||
$handler = new LoginHandler('abcd', 100); | ||
|
||
$response = $handler->handle( | ||
$this->request->withAttribute(User::AUTHENTICATED_USER, new User(...UserTestEntity::getDefaultUserValue())) | ||
); | ||
|
||
$responseData = $response->getBody()->getContents(); | ||
|
||
$responseDataAsArray = json_decode($responseData, true); | ||
|
||
self::assertInstanceOf(JsonResponse::class, $response); | ||
self::assertIsString($responseData); | ||
self::assertJson($responseData); | ||
self::assertIsArray($responseDataAsArray); | ||
self::assertArrayHasKey('token', $responseDataAsArray); | ||
} | ||
} |
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
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