Skip to content

Commit

Permalink
[general] Upgraded date time factory dueto testing issues (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Aug 29, 2024
1 parent 6ac1449 commit f967f67
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 42 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"ipub/slim-router": "^0.2",
"leigh/curve25519": "^0.1",
"nette/di": "^3.0",
"orisai/nette-object-mapper": "^0.1",
"orisai/object-mapper": "^0.2",
"psr/event-dispatcher": "^1.0",
"psr/log": "^3.0",
"endroid/qr-code": "4.5",
Expand Down
6 changes: 3 additions & 3 deletions src/Controllers/CharacteristicsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(
private readonly Queue\Queue $queue,
private readonly Protocol\Driver $accessoryDriver,
private readonly Clients\Subscriber $subscriber,
private readonly DateTimeFactory\Factory $dateTimeFactory,
private readonly DateTimeFactory\Clock $clock,
)
{
}
Expand Down Expand Up @@ -269,7 +269,7 @@ public function update(
|| !array_key_exists($pid, $this->preparedWrites[strval($requestParams['REMOTE_ADDR'])])
|| $this->preparedWrites[strval(
$requestParams['REMOTE_ADDR'],
)][$pid] < $this->dateTimeFactory->getNow()->getTimestamp()
)][$pid] < $this->clock->getNow()->getTimestamp()
) {
$timedWriteError = true;
}
Expand Down Expand Up @@ -403,7 +403,7 @@ public function prepare(
}

$this->preparedWrites[$clientAddress][intval($body[Types\Representation::PID->value])]
= $this->dateTimeFactory->getNow()->getTimestamp() + (intval(
= $this->clock->getNow()->getTimestamp() + (intval(
$body[Types\Representation::TTL->value],
) / 1_000);

Expand Down
4 changes: 2 additions & 2 deletions src/Writers/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(
DevicesModels\Configuration\Channels\Properties\Repository $channelsPropertiesConfigurationRepository,
DevicesModels\States\Async\DevicePropertiesManager $devicePropertiesStatesManager,
DevicesModels\States\Async\ChannelPropertiesManager $channelPropertiesStatesManager,
DateTimeFactory\Factory $dateTimeFactory,
DateTimeFactory\Clock $clock,
EventLoop\LoopInterface $eventLoop,
private readonly ExchangeConsumers\Container $consumer,
private readonly PsrEventDispatcher\EventDispatcherInterface|null $dispatcher = null,
Expand All @@ -82,7 +82,7 @@ public function __construct(
$accessoryDriver,
$devicePropertiesStatesManager,
$channelPropertiesStatesManager,
$dateTimeFactory,
$clock,
$eventLoop,
);

Expand Down
4 changes: 2 additions & 2 deletions src/Writers/Periodic.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function __construct(
private readonly Protocol\Driver $accessoryDriver,
private readonly DevicesModels\States\Async\DevicePropertiesManager $devicePropertiesStatesManager,
private readonly DevicesModels\States\Async\ChannelPropertiesManager $channelPropertiesStatesManager,
private readonly DateTimeFactory\Factory $dateTimeFactory,
private readonly DateTimeFactory\Clock $clock,
private readonly EventLoop\LoopInterface $eventLoop,
)
{
Expand Down Expand Up @@ -209,7 +209,7 @@ private function handleCommunication(): void
*/
private function writeProperty(Documents\Devices\Device $device): bool
{
$now = $this->dateTimeFactory->getNow();
$now = $this->clock->getNow();

$accessory = $this->accessoryDriver->findAccessory($device->getId());

Expand Down
33 changes: 0 additions & 33 deletions tests/cases/unit/DbTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

namespace FastyBird\Connector\HomeKit\Tests\Cases\Unit;

use DateTimeImmutable;
use Doctrine\DBAL;
use Doctrine\ORM;
use Error;
use FastyBird\Connector\HomeKit\DI;
use FastyBird\Connector\HomeKit\Exceptions;
use FastyBird\DateTimeFactory;
use FastyBird\Library\Application\Boot as ApplicationBoot;
use FastyBird\Library\Application\Exceptions as ApplicationExceptions;
use FastyBird\Library\Application\Utilities as ApplicationUtilities;
use IPub\DoctrineCrud;
use Nette;
use Nettrine\ORM as NettrineORM;
Expand Down Expand Up @@ -49,41 +46,11 @@ abstract class DbTestCase extends TestCase
/** @var array<string> */
private array $neonFiles = [];

/**
* @throws ApplicationExceptions\InvalidArgument
* @throws Exceptions\InvalidArgument
* @throws Nette\DI\MissingServiceException
* @throws RuntimeException
* @throws Error
*/
public function setUp(): void
{
$this->registerDatabaseSchemaFile(__DIR__ . '/../../sql/dummy.data.sql');

parent::setUp();

$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,
);

$dateTimeProvider = $this->createMock(ApplicationUtilities\DateTimeProvider::class);
$dateTimeProvider
->method('getDate')
->willReturn($dateTimeFactory->getNow());
$dateTimeProvider
->method('getTimestamp')
->willReturn($dateTimeFactory->getNow()->getTimestamp());

$this->mockContainerService(
ApplicationUtilities\DateTimeProvider::class,
$dateTimeProvider,
);
}

protected function registerDatabaseSchemaFile(string $file): void
Expand Down
5 changes: 4 additions & 1 deletion tests/common.neon
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@ fbSimpleAuth:

fbJsonApi:
meta:
copyright: FastyBird s.r.o
copyright: FastyBird s.r.o

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

0 comments on commit f967f67

Please sign in to comment.