diff --git a/composer.json b/composer.json index 1923b29..047cd6e 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "guzzlehttp/guzzle": "^7.5", "ipub/doctrine-crud": "^5.0", "nette/di": "^3.0", - "orisai/nette-object-mapper": "^0.1", + "orisai/object-mapper": "^0.2", "psr/log": "^3.0", "ramsey/uuid": "^4.5", "react/async": "^4.0", diff --git a/src/API/TelevisionApi.php b/src/API/TelevisionApi.php index e7b3b44..bde9634 100644 --- a/src/API/TelevisionApi.php +++ b/src/API/TelevisionApi.php @@ -138,7 +138,7 @@ public function __construct( private readonly EventLoop\LoopInterface $eventLoop, private readonly Helpers\MessageBuilder $messageBuilder, private readonly Viera\Logger $logger, - private readonly DateTimeFactory\Factory $dateTimeFactory, + private readonly DateTimeFactory\Clock $clock, ) { $this->isEncrypted = $this->appId !== null && $this->encryptionKey !== null; @@ -161,7 +161,7 @@ public function connect(bool $subscribe = false): void } $this->isConnected = true; - $this->connectedAt = $this->dateTimeFactory->getNow(); + $this->connectedAt = $this->clock->getNow(); } /** diff --git a/src/Clients/Television.php b/src/Clients/Television.php index 3202437..89ed3d6 100644 --- a/src/Clients/Television.php +++ b/src/Clients/Television.php @@ -93,7 +93,7 @@ public function __construct( private readonly DevicesModels\Configuration\Channels\Repository $channelsConfigurationRepository, private readonly DevicesModels\Configuration\Channels\Properties\Repository $channelsPropertiesConfigurationRepository, private readonly DevicesUtilities\DeviceConnection $deviceConnectionManager, - private readonly DateTimeFactory\Factory $dateTimeFactory, + private readonly DateTimeFactory\Clock $clock, private readonly EventLoop\LoopInterface $eventLoop, ) { @@ -265,7 +265,7 @@ private function processDevice(Documents\Devices\Device $device): bool $client->getLastConnectAttempt() === null || ( // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong - $this->dateTimeFactory->getNow()->getTimestamp() - $client->getLastConnectAttempt()->getTimestamp() >= self::RECONNECT_COOL_DOWN_TIME + $this->clock->getNow()->getTimestamp() - $client->getLastConnectAttempt()->getTimestamp() >= self::RECONNECT_COOL_DOWN_TIME ) ) { try { @@ -392,7 +392,7 @@ private function processDevice(Documents\Devices\Device $device): bool if ( $cmdResult instanceof DateTimeInterface && ( - $this->dateTimeFactory->getNow()->getTimestamp() - $cmdResult->getTimestamp() + $this->clock->getNow()->getTimestamp() - $cmdResult->getTimestamp() < $this->deviceHelper->getStateReadingDelay($device) ) ) { @@ -400,7 +400,7 @@ private function processDevice(Documents\Devices\Device $device): bool } } - $this->processedChannelsProperties[$device->getId()->toString()][$property->getId()->toString()] = $this->dateTimeFactory->getNow(); + $this->processedChannelsProperties[$device->getId()->toString()][$property->getId()->toString()] = $this->clock->getNow(); $deviceState = $this->deviceConnectionManager->getState($device); @@ -515,7 +515,7 @@ private function processDevice(Documents\Devices\Device $device): bool $result ->then(function (int|bool $value) use ($device, $property): void { // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong - $this->processedChannelsProperties[$device->getId()->toString()][$property->getId()->toString()] = $this->dateTimeFactory->getNow(); + $this->processedChannelsProperties[$device->getId()->toString()][$property->getId()->toString()] = $this->clock->getNow(); $this->queue->append( $this->messageBuilder->create( diff --git a/src/Commands/Discover.php b/src/Commands/Discover.php index 51242a8..60f557c 100644 --- a/src/Commands/Discover.php +++ b/src/Commands/Discover.php @@ -81,7 +81,7 @@ public function __construct( private readonly DevicesModels\Entities\Devices\DevicesRepository $devicesRepository, private readonly DevicesModels\Configuration\Connectors\Repository $connectorsConfigurationRepository, private readonly DevicesModels\Configuration\Devices\Repository $devicesConfigurationRepository, - private readonly DateTimeFactory\Factory $dateTimeFactory, + private readonly DateTimeFactory\Clock $clock, private readonly Localization\Translator $translator, string|null $name = null, ) @@ -304,7 +304,7 @@ function (string|int|null $answer) use ($connectors): Documents\Connectors\Conne $io->info((string) $this->translator->translate('//viera-connector.cmd.discover.messages.starting')); - $this->executedTime = $this->dateTimeFactory->getNow(); + $this->executedTime = $this->clock->getNow(); $serviceCmd = $symfonyApp->find(DevicesCommands\Connector::NAME); diff --git a/src/Commands/Install.php b/src/Commands/Install.php index b95e09b..b28697c 100644 --- a/src/Commands/Install.php +++ b/src/Commands/Install.php @@ -99,7 +99,7 @@ public function __construct( private readonly DevicesModels\Entities\Channels\ChannelsManager $channelsManager, private readonly DevicesModels\Entities\Channels\Properties\PropertiesRepository $channelsPropertiesRepository, private readonly ApplicationHelpers\Database $databaseHelper, - private readonly DateTimeFactory\Factory $dateTimeFactory, + private readonly DateTimeFactory\Clock $clock, private readonly Localization\Translator $translator, string|null $name = null, ) @@ -537,7 +537,7 @@ private function listConnectors(Style\SymfonyStyle $io): void */ private function createDevice(Style\SymfonyStyle $io, Entities\Connectors\Connector $connector): void { - $tempIdentifier = 'new-device-' . $this->dateTimeFactory->getNow()->format(DateTimeInterface::ATOM); + $tempIdentifier = 'new-device-' . $this->clock->getNow()->format(DateTimeInterface::ATOM); $ipAddress = $this->askDeviceIpAddress($io); @@ -1712,7 +1712,7 @@ private function discoverDevices(Style\SymfonyStyle $io, Entities\Connectors\Con throw new Exceptions\InvalidState('Something went wrong, console output is not configured'); } - $executedTime = $this->dateTimeFactory->getNow(); + $executedTime = $this->clock->getNow(); $symfonyApp = $this->getApplication(); diff --git a/src/Queue/Consumers/WriteChannelPropertyState.php b/src/Queue/Consumers/WriteChannelPropertyState.php index ae7b801..3e9efc5 100644 --- a/src/Queue/Consumers/WriteChannelPropertyState.php +++ b/src/Queue/Consumers/WriteChannelPropertyState.php @@ -71,7 +71,7 @@ public function __construct( private readonly DevicesModels\Configuration\Channels\Repository $channelsConfigurationRepository, private readonly DevicesModels\Configuration\Channels\Properties\Repository $channelsPropertiesConfigurationRepository, private readonly DevicesModels\States\Async\ChannelPropertiesManager $channelPropertiesStatesManager, - private readonly DateTimeFactory\Factory $dateTimeFactory, + private readonly DateTimeFactory\Clock $clock, ) { } @@ -310,7 +310,7 @@ public function consume(Queue\Messages\Message $message): bool return true; } - $now = $this->dateTimeFactory->getNow(); + $now = $this->clock->getNow(); $pending = $state->getPending(); if ( diff --git a/src/Writers/Exchange.php b/src/Writers/Exchange.php index ebdc070..e17b132 100644 --- a/src/Writers/Exchange.php +++ b/src/Writers/Exchange.php @@ -54,7 +54,7 @@ public function __construct( DevicesModels\Configuration\Channels\Repository $channelsConfigurationRepository, DevicesModels\Configuration\Channels\Properties\Repository $channelsPropertiesConfigurationRepository, DevicesModels\States\Async\ChannelPropertiesManager $channelPropertiesStatesManager, - DateTimeFactory\Factory $dateTimeFactory, + DateTimeFactory\Clock $clock, EventLoop\LoopInterface $eventLoop, private readonly ExchangeConsumers\Container $consumer, ) @@ -67,7 +67,7 @@ public function __construct( $channelsConfigurationRepository, $channelsPropertiesConfigurationRepository, $channelPropertiesStatesManager, - $dateTimeFactory, + $clock, $eventLoop, ); diff --git a/src/Writers/Periodic.php b/src/Writers/Periodic.php index f2aaabe..37039c1 100644 --- a/src/Writers/Periodic.php +++ b/src/Writers/Periodic.php @@ -81,7 +81,7 @@ public function __construct( protected readonly DevicesModels\Configuration\Channels\Repository $channelsConfigurationRepository, private readonly DevicesModels\Configuration\Channels\Properties\Repository $channelsPropertiesConfigurationRepository, private readonly DevicesModels\States\Async\ChannelPropertiesManager $channelPropertiesStatesManager, - private readonly DateTimeFactory\Factory $dateTimeFactory, + private readonly DateTimeFactory\Clock $clock, private readonly EventLoop\LoopInterface $eventLoop, ) { @@ -196,7 +196,7 @@ private function handleCommunication(): void */ private function writeProperty(Documents\Devices\Device $device): bool { - $now = $this->dateTimeFactory->getNow(); + $now = $this->clock->getNow(); foreach ($this->properties[$device->getId()->toString()] as $property) { $debounce = array_key_exists($property->getId()->toString(), $this->processedProperties) diff --git a/tests/cases/unit/DbTestCase.php b/tests/cases/unit/DbTestCase.php index eaa094e..75b7fdb 100644 --- a/tests/cases/unit/DbTestCase.php +++ b/tests/cases/unit/DbTestCase.php @@ -2,16 +2,13 @@ namespace FastyBird\Connector\Viera\Tests\Cases\Unit; -use DateTimeImmutable; use Doctrine\DBAL; use Doctrine\ORM; use Error; use FastyBird\Connector\Viera\DI; use FastyBird\Connector\Viera\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; @@ -49,41 +46,11 @@ abstract class DbTestCase extends TestCase /** @var array */ 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 diff --git a/tests/common.neon b/tests/common.neon index 239784d..f633a51 100644 --- a/tests/common.neon +++ b/tests/common.neon @@ -101,4 +101,7 @@ fbSimpleAuth: fbJsonApi: meta: - copyright: FastyBird s.r.o \ No newline at end of file + copyright: FastyBird s.r.o + +fbDateTimeFactory: + frozen: DateTimeImmutable('2020-04-01T12:00:00+00:00') \ No newline at end of file