Skip to content

Commit

Permalink
Use IntegrationTestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
hkreuter committed Dec 19, 2024
1 parent dea3c74 commit 0d8ebdf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 38 deletions.
41 changes: 13 additions & 28 deletions tests/Integration/Infrastructure/RefreshTokenRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,18 @@

use DateTime;
use DateTimeImmutable;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use Doctrine\DBAL\Connection;
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;
use OxidEsales\GraphQL\Base\Infrastructure\RefreshTokenRepositoryInterface;
use OxidEsales\GraphQL\Base\Tests\Integration\TestCase;
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(RefreshTokenRepository::class)]
class RefreshTokenRepositoryTest extends TestCase
class RefreshTokenRepositoryTest extends IntegrationTestCase
{
protected function tearDown(): void
{
$this->cleanUp();

parent::tearDown();
}

public function testGetNewRefreshTokenGivesCorrectlyFilledDataType(): void
{
$sut = $this->getSut();
Expand Down Expand Up @@ -181,16 +174,19 @@ public function testInvalidateRefreshTokensWrongUserId(): void

public function getSut(): RefreshTokenRepositoryInterface
{
return self::$container->get(RefreshTokenRepositoryInterface::class);
return $this->get(RefreshTokenRepositoryInterface::class);
}

public function getDbConnection(): Connection
{
return $this->get(ConnectionFactoryInterface::class)->create();
}

private function checkRefreshTokenWithIdExists(string $oxid): bool
{
$result = ContainerFacade::get(ConnectionFactoryInterface::class)
->create()
->executeQuery(
"select count(*) from `oegraphqlrefreshtoken` where OXID=:oxid",
['oxid' => $oxid]
$result = $this->getDbConnection()->executeQuery(
"select count(*) from `oegraphqlrefreshtoken` where OXID=:oxid",
['oxid' => $oxid]
);

return $result->fetchOne() > 0;
Expand All @@ -204,22 +200,11 @@ public function addToken(
): void {
$insertTokensQuery = "insert into `oegraphqlrefreshtoken` (OXID, OXUSERID, TOKEN, EXPIRES_AT)
values (:oxid, :oxuserid, :token, :expires)";
ContainerFacade::get(ConnectionFactoryInterface::class)
->create()
->executeQuery($insertTokensQuery, [
$this->getDbConnection()->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`'
);
}
}
14 changes: 4 additions & 10 deletions tests/Integration/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionFactoryInterface;
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;
use OxidEsales\EshopCommunity\Tests\TestContainerFactory;
use OxidEsales\Facts\Facts;
use OxidEsales\GraphQL\Base\DataType\UserInterface;
Expand All @@ -30,10 +31,8 @@
use Psr\Log\LoggerInterface;
use ReflectionClass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use PHPUnit\Framework\TestCase as FrameworkTestCase;


abstract class TestCase extends FrameworkTestCase
abstract class TestCase extends IntegrationTestCase
{
protected static $queryResult;

Expand All @@ -44,7 +43,7 @@ abstract class TestCase extends FrameworkTestCase

protected static $query;

protected function setUp(): void
public function setUp(): void
{
parent::setUp();

Expand All @@ -61,9 +60,6 @@ protected function setUp(): void
if (static::$container !== null) {
return;
}

# ContainerFactory::resetContainer();

$containerFactory = new TestContainerFactory();
static::$container = $containerFactory->create();

Expand Down Expand Up @@ -112,7 +108,7 @@ protected function setUp(): void
static::$container->compile();
}

protected function tearDown(): void
public function tearDown(): void
{
parent::tearDown();
static::$queryResult = null;
Expand All @@ -125,8 +121,6 @@ protected function tearDown(): void
}
unset($_SERVER['HTTP_AUTHORIZATION']);
}

# ContainerFactory::resetContainer();
}

protected function setAuthToken(string $token): void
Expand Down

0 comments on commit 0d8ebdf

Please sign in to comment.