Skip to content

Commit

Permalink
Upgraded to use latest datetime factory library
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Aug 29, 2024
1 parent 21c061b commit ce65679
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 31 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"casbin/casbin": "^3.23",
"contributte/event-dispatcher": "^0.9",
"cweagans/composer-patches": "^1.7",
"fastybird/datetime-factory": "^0.6",
"fastybird/datetime-factory": "^0.7",
"ipub/doctrine-crud": "^5.0",
"ipub/doctrine-orm-query": "^0.1",
"ipub/slim-router": "^0.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/Security/TokenBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class TokenBuilder
public function __construct(
private readonly string $tokenSignature,
private readonly string $tokenIssuer,
private readonly DateTimeFactory\Factory $dateTimeFactory,
private readonly DateTimeFactory\Clock $clock,
)
{
}
Expand All @@ -65,7 +65,7 @@ public function build(
JWT\Signer\Key\InMemory::plainText($this->tokenSignature),
);

$now = $this->dateTimeFactory->getNow();
$now = $this->clock->getNow();
assert($now instanceof DateTimeImmutable);

$jwtBuilder = $configuration->builder();
Expand Down
2 changes: 0 additions & 2 deletions src/Security/TokenReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Lcobucci\JWT;
use Nette;
use Psr\Http\Message\ServerRequestInterface;
use function count;
use function is_array;
use function is_string;
use function preg_match;
Expand Down Expand Up @@ -57,7 +56,6 @@ public function read(ServerRequestInterface $request): JWT\UnencryptedToken|null
if (
is_string($headerJWT)
&& preg_match(SimpleAuth\Constants::TOKEN_HEADER_REGEXP, $headerJWT, $matches) !== false
&& count($matches) >= 2
) {
$token = $this->tokenValidator->validate($matches[1]);

Expand Down
4 changes: 2 additions & 2 deletions src/Security/TokenValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class TokenValidator
public function __construct(
private readonly string $tokenSignature,
private readonly string $tokenIssuer,
private readonly DateTimeFactory\Factory $dateTimeFactory,
private readonly DateTimeFactory\Clock $clock,
)
{
}
Expand All @@ -64,7 +64,7 @@ public function validate(string $token): JWT\Token|null
JWT\Signer\Key\InMemory::plainText($this->tokenSignature),
);

$now = $this->dateTimeFactory->getNow();
$now = $this->clock->getNow();
assert($now instanceof DateTimeImmutable);

$configuration->setValidationConstraints(
Expand Down
12 changes: 0 additions & 12 deletions tests/cases/unit/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace FastyBird\SimpleAuth\Tests\Cases\Unit;

use DateTimeImmutable;
use Doctrine\ORM;
use FastyBird\DateTimeFactory;
use FastyBird\SimpleAuth;
use Nette;
use Nette\DI;
Expand Down Expand Up @@ -34,16 +32,6 @@ protected function setUp(): void

$this->container = $this->createContainer();
$this->em = $this->container->getByType(Nettrine\ORM\EntityManagerDecorator::class);

$dateTimeFactory = $this->createMock(DateTimeFactory\Factory::class);
$dateTimeFactory
->method('getNow')
->willReturn(new DateTimeImmutable('2020-04-01T12:00:00+00:00'));

$this->mockContainerService(
DateTimeFactory\Factory::class,
$dateTimeFactory,
);
}

protected function createContainer(string|null $additionalConfig = null): Nette\DI\Container
Expand Down
12 changes: 0 additions & 12 deletions tests/cases/unit/DbTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace FastyBird\SimpleAuth\Tests\Cases\Unit;

use DateTimeImmutable;
use Doctrine\DBAL;
use Doctrine\ORM;
use FastyBird\DateTimeFactory;
use FastyBird\SimpleAuth;
use FastyBird\SimpleAuth\Exceptions;
use IPub\DoctrineCrud;
Expand Down Expand Up @@ -58,16 +56,6 @@ public function setUp(): void

$this->container = $this->createContainer();
$this->em = $this->container->getByType(NettrineORM\EntityManagerDecorator::class);

$dateTimeFactory = $this->createMock(DateTimeFactory\Factory::class);
$dateTimeFactory
->method('getNow')
->willReturn(new DateTimeImmutable('2020-04-01T12:00:00+00:00'));

$this->mockContainerService(
DateTimeFactory\Factory::class,
$dateTimeFactory,
);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/common.neon
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ fbSimpleAuth:
identity: true
casbin:
policy: %appDir%tests/fixtures/policy.csv

fbDateTimeFactory:
frozen: new DateTimeImmutable('2020-04-01T12:00:00+00:00')

0 comments on commit ce65679

Please sign in to comment.