diff --git a/src/Drivers/Thermostat.php b/src/Drivers/Thermostat.php index 1ba9f89..6f5d160 100644 --- a/src/Drivers/Thermostat.php +++ b/src/Drivers/Thermostat.php @@ -114,7 +114,7 @@ public function __construct( private readonly VirtualThermostat\Logger $logger, private readonly DevicesModels\Configuration\Channels\Repository $channelsConfigurationRepository, private readonly DevicesModels\States\ChannelPropertiesManager $channelPropertiesStatesManager, - private readonly DateTimeFactory\Factory $dateTimeFactory, + private readonly DateTimeFactory\Clock $clock, ) { $this->presetMode = Types\Preset::MANUAL; @@ -395,7 +395,7 @@ public function connect(): Promise\PromiseInterface } $this->connected = true; - $this->connectedAt = $this->dateTimeFactory->getNow(); + $this->connectedAt = $this->clock->getNow(); return Promise\resolve(true); } @@ -458,7 +458,7 @@ public function process(): Promise\PromiseInterface return Promise\reject(new Exceptions\InvalidState('Thermostat device is not connected')); } - $this->lastProcessedTime = $this->dateTimeFactory->getNow(); + $this->lastProcessedTime = $this->clock->getNow(); if ($this->hvacMode === null || $this->presetMode === null) { $this->stop('Thermostat mode is not configured'); @@ -888,7 +888,7 @@ public function notifyState( if ( $this->lastProcessedTime instanceof DateTimeInterface && ( - $this->dateTimeFactory->getNow()->getTimestamp() - $this->lastProcessedTime->getTimestamp() + $this->clock->getNow()->getTimestamp() - $this->lastProcessedTime->getTimestamp() < self::PROCESSING_DEBOUNCE_DELAY ) ) { @@ -914,7 +914,7 @@ public function notifyState( if ( $this->lastProcessedTime instanceof DateTimeInterface && ( - $this->dateTimeFactory->getNow()->getTimestamp() - $this->lastProcessedTime->getTimestamp() + $this->clock->getNow()->getTimestamp() - $this->lastProcessedTime->getTimestamp() < self::PROCESSING_DEBOUNCE_DELAY ) ) { @@ -947,7 +947,7 @@ public function notifyState( if ( $this->lastProcessedTime instanceof DateTimeInterface && ( - $this->dateTimeFactory->getNow()->getTimestamp() - $this->lastProcessedTime->getTimestamp() + $this->clock->getNow()->getTimestamp() - $this->lastProcessedTime->getTimestamp() < self::PROCESSING_DEBOUNCE_DELAY ) ) { @@ -974,7 +974,7 @@ public function notifyState( if ( $this->lastProcessedTime instanceof DateTimeInterface && ( - $this->dateTimeFactory->getNow()->getTimestamp() - $this->lastProcessedTime->getTimestamp() + $this->clock->getNow()->getTimestamp() - $this->lastProcessedTime->getTimestamp() < self::PROCESSING_DEBOUNCE_DELAY ) ) { @@ -1006,7 +1006,7 @@ public function notifyState( if ( $this->lastProcessedTime instanceof DateTimeInterface && ( - $this->dateTimeFactory->getNow()->getTimestamp() - $this->lastProcessedTime->getTimestamp() + $this->clock->getNow()->getTimestamp() - $this->lastProcessedTime->getTimestamp() < self::PROCESSING_DEBOUNCE_DELAY ) ) { @@ -1038,7 +1038,7 @@ public function notifyState( if ( $this->lastProcessedTime instanceof DateTimeInterface && ( - $this->dateTimeFactory->getNow()->getTimestamp() - $this->lastProcessedTime->getTimestamp() + $this->clock->getNow()->getTimestamp() - $this->lastProcessedTime->getTimestamp() < self::PROCESSING_DEBOUNCE_DELAY ) ) { diff --git a/tests/cases/unit/DbTestCase.php b/tests/cases/unit/DbTestCase.php index 9988211..75ffd03 100644 --- a/tests/cases/unit/DbTestCase.php +++ b/tests/cases/unit/DbTestCase.php @@ -2,16 +2,13 @@ namespace FastyBird\Addon\VirtualThermostat\Tests\Cases\Unit; -use DateTimeImmutable; use Doctrine\DBAL; use Doctrine\ORM; use Error; use FastyBird\Addon\VirtualThermostat\DI; use FastyBird\Addon\VirtualThermostat\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 a43e941..ebe2f9b 100644 --- a/tests/common.neon +++ b/tests/common.neon @@ -121,4 +121,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