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 598d1e5 commit cc300ec
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 44 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"fastybird/metadata-library": "dev-main",
"fastybird/tools-library": "dev-main",
"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",
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Discover.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(
private readonly Helpers\Devices\SubDevice $subDeviceHelper,
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,
)
Expand Down Expand Up @@ -297,7 +297,7 @@ function (string|int|null $answer) use ($connectors): Documents\Connectors\Conne

$io->info((string) $this->translator->translate('//zigbee2mqtt-connector.cmd.discover.messages.starting'));

$this->executedTime = $this->dateTimeFactory->getNow();
$this->executedTime = $this->clock->getNow();

$serviceCmd = $symfonyApp->find(DevicesCommands\Connector::NAME);

Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct(
private readonly DevicesModels\Entities\Devices\Properties\PropertiesRepository $devicesPropertiesRepository,
private readonly DevicesModels\Entities\Devices\Properties\PropertiesManager $devicesPropertiesManager,
private readonly ApplicationHelpers\Database $databaseHelper,
private readonly DateTimeFactory\Factory $dateTimeFactory,
private readonly DateTimeFactory\Clock $clock,
private readonly Localization\Translator $translator,
string|null $name = null,
)
Expand Down Expand Up @@ -1098,7 +1098,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();

Expand Down
4 changes: 2 additions & 2 deletions src/Queue/Consumers/WriteSubDeviceChannelPropertyState.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function __construct(
private readonly DevicesModels\Configuration\Connectors\Repository $connectorsConfigurationRepository,
private readonly DevicesModels\Configuration\Devices\Repository $devicesConfigurationRepository,
private readonly DevicesModels\Configuration\Channels\Repository $channelsConfigurationRepository,
private readonly DateTimeFactory\Factory $dateTimeFactory,
private readonly DateTimeFactory\Clock $clock,
)
{
}
Expand Down Expand Up @@ -282,7 +282,7 @@ public function consume(Queue\Messages\Message $message): bool
return true;
}

$now = $this->dateTimeFactory->getNow();
$now = $this->clock->getNow();
$pending = $state->getPending();

if (
Expand Down
4 changes: 2 additions & 2 deletions src/Writers/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -67,7 +67,7 @@ public function __construct(
$channelsConfigurationRepository,
$channelsPropertiesConfigurationRepository,
$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 @@ -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,
)
{
Expand Down Expand Up @@ -196,7 +196,7 @@ private function handleCommunication(): void
*/
private function writeProperty(Documents\Devices\Device $device): bool
{
$now = $this->dateTimeFactory->getNow();
$now = $this->clock->getNow();

if (!array_key_exists($device->getId()->toString(), $this->properties)) {
return false;
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\Zigbee2Mqtt\Tests\Cases\Unit;

use DateTimeImmutable;
use Doctrine\DBAL;
use Doctrine\ORM;
use Error;
use FastyBird\Connector\Zigbee2Mqtt\DI;
use FastyBird\Connector\Zigbee2Mqtt\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
3 changes: 3 additions & 0 deletions tests/common.neon
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ fbSimpleAuth:
fbJsonApi:
meta:
copyright: FastyBird s.r.o

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

0 comments on commit cc300ec

Please sign in to comment.