From 69879db559ec30df8ff5a99df3abf01f99e494fe Mon Sep 17 00:00:00 2001 From: GitHub Date: Thu, 29 Aug 2024 09:47:02 +0000 Subject: [PATCH] [general] Use global date provider for doctrine timestampable (#310) --- composer.json | 2 -- tests/cases/unit/BaseTestCase.php | 14 ++++++++++++++ tests/cases/unit/DbTestCase.php | 14 ++++++++++++++ tests/common.neon | 2 -- tests/tools/DateTimeProvider.php | 27 --------------------------- 5 files changed, 28 insertions(+), 31 deletions(-) delete mode 100644 tests/tools/DateTimeProvider.php diff --git a/composer.json b/composer.json index 5b9f4bf..b236810 100644 --- a/composer.json +++ b/composer.json @@ -45,13 +45,11 @@ "contributte/translation": "^2.0", "cweagans/composer-patches": "^1.7", "fastybird/application-library": "dev-main", - "fastybird/datetime-factory": "^0.6", "fastybird/exchange-library": "dev-main", "fastybird/json-api": "^0.19", "fastybird/metadata-library": "dev-main", "fastybird/simple-auth": "^0.14", "fastybird/tools-library": "dev-main", - "ipub/doctrine-timestampable": "^2.0", "ipub/slim-router": "^0.2", "nettrine/dbal": "^0.8", "nettrine/orm": "^0.8", diff --git a/tests/cases/unit/BaseTestCase.php b/tests/cases/unit/BaseTestCase.php index b9d7e69..19ea78c 100644 --- a/tests/cases/unit/BaseTestCase.php +++ b/tests/cases/unit/BaseTestCase.php @@ -7,6 +7,7 @@ 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 FastyBird\Module\Ui\DI; use Nette; use PHPUnit\Framework\TestCase; @@ -43,6 +44,19 @@ protected function setUp(): void 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, + ); } /** diff --git a/tests/cases/unit/DbTestCase.php b/tests/cases/unit/DbTestCase.php index ce533b1..e1acf28 100644 --- a/tests/cases/unit/DbTestCase.php +++ b/tests/cases/unit/DbTestCase.php @@ -9,6 +9,7 @@ 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 FastyBird\Module\Ui\DI; use FastyBird\Module\Ui\Exceptions; use IPub\DoctrineCrud; @@ -86,6 +87,19 @@ public function setUp(): void 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 12e733e..e23e7dd 100644 --- a/tests/common.neon +++ b/tests/common.neon @@ -37,8 +37,6 @@ services: setup: - addMiddleware(@fbJsonApi.middlewares.jsonapi) - - {factory: FastyBird\Module\Ui\Tests\Tools\DateTimeProvider} - cache.storage: Nette\Caching\Storages\DevNullStorage contributteTranslation: diff --git a/tests/tools/DateTimeProvider.php b/tests/tools/DateTimeProvider.php deleted file mode 100644 index 2ae4b9b..0000000 --- a/tests/tools/DateTimeProvider.php +++ /dev/null @@ -1,27 +0,0 @@ -container->getByType(DateTimeFactory\Factory::class)->getNow(); - } - - public function getTimestamp(): int - { - return $this->container->getByType(DateTimeFactory\Factory::class)->getNow()->getTimestamp(); - } - -}