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 69879db commit b3a1cb3
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 76 deletions.
36 changes: 0 additions & 36 deletions tests/cases/unit/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

namespace FastyBird\Module\Ui\Tests\Cases\Unit;

use DateTimeImmutable;
use Error;
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;
Expand All @@ -26,39 +23,6 @@ abstract class BaseTestCase extends TestCase
/** @var array<string> */
protected array $neonFiles = [];

/**
* @throws ApplicationExceptions\InvalidArgument
* @throws ApplicationExceptions\InvalidState
* @throws Error
*/
protected function setUp(): void
{
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,
);
}

/**
* @throws ApplicationExceptions\InvalidArgument
* @throws ApplicationExceptions\InvalidState
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,14 +2,11 @@

namespace FastyBird\Module\Ui\Tests\Cases\Unit;

use DateTimeImmutable;
use Doctrine\DBAL;
use Doctrine\ORM;
use Error;
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;
Expand Down Expand Up @@ -65,41 +62,11 @@ abstract class DbTestCase extends TestCase
/** @var array<string> */
protected 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
7 changes: 0 additions & 7 deletions tests/cases/unit/Router/RouterTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ const VALID_TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjb20uZmFzdH
final class RouterTest extends Tests\Cases\Unit\DbTestCase
{

/**
* @throws ApplicationExceptions\InvalidArgument
* @throws Exceptions\InvalidArgument
* @throws Nette\DI\MissingServiceException
* @throws RuntimeException
* @throws Error
*/
public function setUp(): void
{
$this->registerNeonConfigurationFile(__DIR__ . '/prefixedRoutes.neon');
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 b3a1cb3

Please sign in to comment.