From d03fc92862f39d41e1a2d07d7f088e59aec3ed09 Mon Sep 17 00:00:00 2001 From: hkreuter Date: Wed, 18 Dec 2024 16:51:12 +0100 Subject: [PATCH] Run with shop 8.0.x and facts spike --- .../RefreshTokenRepositoryTest.php | 33 +++++++++++++++---- tests/Integration/TestCase.php | 20 +++++------ 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/tests/Integration/Infrastructure/RefreshTokenRepositoryTest.php b/tests/Integration/Infrastructure/RefreshTokenRepositoryTest.php index 3dcfb422..df16c88b 100644 --- a/tests/Integration/Infrastructure/RefreshTokenRepositoryTest.php +++ b/tests/Integration/Infrastructure/RefreshTokenRepositoryTest.php @@ -11,7 +11,8 @@ use DateTime; use DateTimeImmutable; -use Doctrine\DBAL\Connection; +use OxidEsales\EshopCommunity\Core\Di\ContainerFacade; +use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionFactoryInterface; use OxidEsales\GraphQL\Base\DataType\UserInterface; use OxidEsales\GraphQL\Base\Exception\InvalidRefreshToken; use OxidEsales\GraphQL\Base\Infrastructure\RefreshTokenRepository; @@ -22,6 +23,13 @@ #[CoversClass(RefreshTokenRepository::class)] class RefreshTokenRepositoryTest extends TestCase { + protected function tearDown(): void + { + $this->cleanUp(); + + parent::tearDown(); + } + public function testGetNewRefreshTokenGivesCorrectlyFilledDataType(): void { $sut = $this->getSut(); @@ -173,14 +181,16 @@ public function testInvalidateRefreshTokensWrongUserId(): void public function getSut(): RefreshTokenRepositoryInterface { - return $this->get(RefreshTokenRepositoryInterface::class); + return self::$container->get(RefreshTokenRepositoryInterface::class); } private function checkRefreshTokenWithIdExists(string $oxid): bool { - $result = $this->getDbConnection()->executeQuery( - "select count(*) from `oegraphqlrefreshtoken` where OXID=:oxid", - ['oxid' => $oxid] + $result = ContainerFacade::get(ConnectionFactoryInterface::class) + ->create() + ->executeQuery( + "select count(*) from `oegraphqlrefreshtoken` where OXID=:oxid", + ['oxid' => $oxid] ); return $result->fetchOne() > 0; @@ -194,11 +204,22 @@ public function addToken( ): void { $insertTokensQuery = "insert into `oegraphqlrefreshtoken` (OXID, OXUSERID, TOKEN, EXPIRES_AT) values (:oxid, :oxuserid, :token, :expires)"; - $this->getDbConnection()->executeQuery($insertTokensQuery, [ + ContainerFacade::get(ConnectionFactoryInterface::class) + ->create() + ->executeQuery($insertTokensQuery, [ "oxid" => $oxid, "oxuserid" => $userId ?? uniqid(), 'token' => $token ?? uniqid(), "expires" => $expires, ]); } + + private function cleanUp(): void + { + ContainerFacade::get(ConnectionFactoryInterface::class) + ->create() + ->executeQuery( + 'truncate table `oegraphqlrefreshtoken`' + ); + } } diff --git a/tests/Integration/TestCase.php b/tests/Integration/TestCase.php index cd2d1285..852bf7f9 100644 --- a/tests/Integration/TestCase.php +++ b/tests/Integration/TestCase.php @@ -12,8 +12,8 @@ use DateTimeImmutable; use Lcobucci\JWT\UnencryptedToken; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; -use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; -use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase; +use OxidEsales\EshopCommunity\Core\Di\ContainerFacade; +use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionFactoryInterface; use OxidEsales\EshopCommunity\Tests\TestContainerFactory; use OxidEsales\Facts\Facts; use OxidEsales\GraphQL\Base\DataType\UserInterface; @@ -30,8 +30,10 @@ use Psr\Log\LoggerInterface; use ReflectionClass; use Symfony\Component\DependencyInjection\ContainerBuilder; +use PHPUnit\Framework\TestCase as FrameworkTestCase; -abstract class TestCase extends IntegrationTestCase + +abstract class TestCase extends FrameworkTestCase { protected static $queryResult; @@ -42,17 +44,13 @@ abstract class TestCase extends IntegrationTestCase protected static $query; - public function setUp(): void + protected function setUp(): void { parent::setUp(); - $connection = ContainerFactory::getInstance() - ->getContainer() - ->get(QueryBuilderFactoryInterface::class) + ContainerFacade::get(ConnectionFactoryInterface::class) ->create() - ->getConnection(); - - $connection->executeStatement( + ->executeStatement( file_get_contents( __DIR__ . '/../Fixtures/dump.sql' ) @@ -114,7 +112,7 @@ public function setUp(): void static::$container->compile(); } - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); static::$queryResult = null;