Skip to content

Commit

Permalink
Run with shop 8.0.x, WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hkreuter committed Dec 11, 2024
1 parent a626fe7 commit 35d4e73
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 90 deletions.
12 changes: 2 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
"keywords": ["oxid", "modules", "eShop", "GraphQL"],
"homepage": "https://www.oxid-esales.com",
"license": ["proprietary"],
"extra": {
"oxideshop": {
"target-directory": "oe/graphql-base",
"blacklist-filter": [
"tests/**/*"
]
}
},
"require": {
"php": "^8.2",
"ext-json": "*",
Expand All @@ -26,7 +18,7 @@
"require-dev": {
"phpunit/phpunit": "^10.4",
"ext-xdebug": "*",
"oxid-esales/oxideshop-ce": "dev-b-7.2.x",
"oxid-esales/oxideshop-ce": "dev-b-8.0.x",
"phpstan/phpstan": "^1.10",
"squizlabs/php_codesniffer": "3.*",
"phpmd/phpmd": "^2.11",
Expand All @@ -35,7 +27,7 @@
"codeception/module-phpbrowser": "*",
"codeception/module-db": "*",
"codeception/codeception": "^5.0",
"oxid-esales/codeception-modules": "dev-b-7.2.x",
"oxid-esales/codeception-modules": "dev-b-8.0.x",
"codeception/module-asserts": "^3.0"
},
"conflict": {
Expand Down
1 change: 1 addition & 0 deletions tests/Codeception/Acceptance.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ modules:
- \OxidEsales\GraphQL\Base\Tests\Codeception\Module\AcceptanceHelper:
depends:
- REST
- \OxidEsales\Codeception\Module\OxideshopModules
152 changes: 152 additions & 0 deletions tests/Codeception/Config/CodeceptionParametersProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\Graphql\Base\Tests\Codeception\Config;

use OxidEsales\Codeception\Module\Database;
use OxidEsales\EshopCommunity\Internal\Framework\Configuration\DataObject\DatabaseConfiguration;
use OxidEsales\EshopCommunity\Internal\Framework\Edition\Edition;
use OxidEsales\EshopCommunity\Internal\Framework\Edition\EditionDirectoriesLocator;
use OxidEsales\EshopCommunity\Internal\Framework\Env\DotenvLoader;
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\DirectoryNotExistentException;
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\ProjectDirectoriesLocator;
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\ProjectRootLocator;
use Symfony\Component\Filesystem\Path;

class CodeceptionParametersProvider
{
private DatabaseConfiguration $dbConfig;

public function getParameters(): array
{
$this->loadEnvironmentVariables();

$this->dbConfig = (new DatabaseConfiguration(getenv('OXID_DB_URL')));
return [
'SHOP_URL' => getenv('OXID_SHOP_BASE_URL'),
'PROJECT_ROOT' => $this->getProjectRoot(),
'VENDOR_PATH' => (new ProjectDirectoriesLocator())->getVendorPath(),
'SOURCE_RELATIVE_PACKAGE_PATH' => $this->getSourceRelativePackagePath(),
'DB_NAME' => $this->getDbName(),
'DB_USERNAME' => $this->getDbUser(),
'DB_PASSWORD' => $this->getDbPass(),
'DB_HOST' => $this->getDbHost(),
'DB_PORT' => $this->getDbPort(),
'DUMP_PATH' => $this->getTestDataDumpFilePath(),
'MODULE_DUMP_PATH' => $this->getCodeceptionSpecificFixtureFilePath(),
'FIXTURES_PATH' => $this->getTestFixtureSqlFilePath(),
'OUT_DIRECTORY' => (new ProjectDirectoriesLocator())->getOutPath(),
'OUT_DIRECTORY_FIXTURES' => $this->getOutDirectoryFixturesPath(),
'MYSQL_CONFIG_PATH' => $this->generateMysqlStarUpConfigurationFile(),
'SELENIUM_SERVER_PORT' => getenv('SELENIUM_SERVER_PORT') ?: '4444',
'SELENIUM_SERVER_HOST' => getenv('SELENIUM_SERVER_HOST') ?: 'selenium',
'PHP_BIN' => (getenv('PHPBIN')) ?: 'php',
'SCREEN_SHOT_URL' => getenv('CC_SCREEN_SHOTS_URL') ?: '',
'BROWSER' => getenv('BROWSER_NAME') ?: 'chrome',
'THEME_ID' => getenv('THEME_ID') ?: 'apex',
'MAIL_HOST' => getenv('MAIL_HOST') ?: 'mailpit',
'MAIL_WEB_PORT' => getenv('MAIL_WEB_PORT') ?: '8025',
];
}

private function getSourceRelativePackagePath(): string
{
return(str_replace($this->getProjectRoot(), '..', __DIR__) . '/../../../');
}

private function getCodeceptionSpecificFixtureFilePath(): string
{
return Path::join(__DIR__, '../Support/Data', 'dump.sql');
}

private function getTestDataDumpFilePath(): string
{
return Path::join(
$this->getShopTestPath(),
'/Codeception/Support/_generated/shop-dump.sql'
);
}

private function getTestFixtureSqlFilePath(): string
{
return Path::join(
$this->getShopTestPath(),
'/Codeception/Support/Data/dump.sql',
);
}

private function getOutDirectoryFixturesPath(): string
{
return Path::join(
$this->getShopTestPath(),
'/Codeception/Support/Data/out',
);
}

private function getShopTestPath(): string
{
try {
$testsPath = Path::join(
(new EditionDirectoriesLocator())->getEditionRootPath(Edition::Enterprise),
'Tests'
);
} catch (DirectoryNotExistentException) {
$testsPath = Path::join(
$this->getProjectRoot(),
'tests'
);
}
return $testsPath;
}

private function generateMysqlStarUpConfigurationFile(): string
{
return Database::generateStartupOptionsFile(
$this->getDbUser(),
$this->getDbPass(),
$this->getDbHost(),
$this->getDbPort(),
);
}

private function getDbName(): string
{
return getenv('DB_NAME') ?: $this->dbConfig->getName();
}

private function getDbUser(): string
{
return getenv('DB_USERNAME') ?: $this->dbConfig->getUser();
}

private function getDbPass(): string
{
return getenv('DB_PASSWORD') ?: $this->dbConfig->getPass();
}

private function getDbHost(): string
{
return getenv('DB_HOST') ?: $this->dbConfig->getHost();
}

private function getDbPort(): int
{
return (int) getenv('DB_PORT') ?: $this->dbConfig->getPort();
}

private function loadEnvironmentVariables(): void
{
(new DotenvLoader($this->getProjectRoot()))->loadEnvironmentVariables();
}

private function getProjectRoot(): string
{
return (new ProjectRootLocator())->getProjectRoot();
}
}
41 changes: 2 additions & 39 deletions tests/Codeception/Config/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,6 @@

declare(strict_types=1);

use OxidEsales\Codeception\Module\Database\DatabaseDefaultsFileGenerator;
use OxidEsales\Facts\Config\ConfigFile;
use OxidEsales\Facts\Facts;
use Symfony\Component\Filesystem\Path;
namespace OxidEsales\Graphql\Base\Tests\Codeception\Config;

if ($shopRootPath = getenv('SHOP_ROOT_PATH')){
require_once(Path::join($shopRootPath, 'source', 'bootstrap.php'));
}

$facts = new Facts();
$php = (getenv('PHPBIN')) ?: 'php';

return [
'SHOP_URL' => $facts->getShopUrl(),
'SHOP_SOURCE_PATH' => $facts->getSourcePath(),
'VENDOR_PATH' => $facts->getVendorPath(),
'DB_NAME' => $facts->getDatabaseName(),
'DB_USERNAME' => $facts->getDatabaseUserName(),
'DB_PASSWORD' => $facts->getDatabasePassword(),
'DB_HOST' => $facts->getDatabaseHost(),
'DB_PORT' => $facts->getDatabasePort(),
'MODULE_DUMP_PATH' => getModuleTestDataDumpFilePath(),
'MYSQL_CONFIG_PATH' => getMysqlConfigPath(),
'PHP_BIN' => $php,
];

function getModuleTestDataDumpFilePath()
{
return Path::join(__DIR__, '..', 'Support', 'Data', 'dump.sql');
}

function getMysqlConfigPath()
{
$facts = new Facts();
$configFile = new ConfigFile($facts->getSourcePath() . '/config.inc.php');

$generator = new DatabaseDefaultsFileGenerator($configFile);

return $generator->generate();
}
return (new CodeceptionParametersProvider())->getParameters();
20 changes: 0 additions & 20 deletions tests/Codeception/Module/AcceptanceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Lcobucci\JWT\Token;
use Lcobucci\JWT\Token\Parser;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\Facts\Facts;
use OxidEsales\GraphQL\Base\Service\JwtConfigurationBuilder;
use PHPUnit\Framework\AssertionFailedError;
use Symfony\Component\BrowserKit\CookieJar;
Expand Down Expand Up @@ -46,25 +45,6 @@ public function getRest(): REST
return $this->rest;
}

public function _beforeSuite($settings = []): void // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
{
$rootPath = (new Facts())->getShopRootPath();
$possiblePaths = [
'/bin/oe-console',
'/vendor/bin/oe-console',
];

foreach ($possiblePaths as $path) {
if (is_file($rootPath . $path)) {
exec($rootPath . $path . ' oe:module:activate oe_graphql_base');

return;
}
}

throw new Exception('Could not find script "/bin/oe-console" to activate module');
}

public function sendGQLQuery(
string $query,
?array $variables = null,
Expand Down
23 changes: 11 additions & 12 deletions tests/Integration/Infrastructure/RefreshTokenRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

use DateTime;
use DateTimeImmutable;
use Doctrine\DBAL\Connection;
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionProviderInterface;
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;
Expand Down Expand Up @@ -172,21 +172,18 @@ public function testInvalidateRefreshTokensWrongUserId(): void
$this->assertTrue($sut->getTokenUser($token) instanceof UserInterface);
}

private function getDbConnection(): Connection
{
return $this->get(ConnectionProviderInterface::class)->get();
}

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;
Expand All @@ -200,7 +197,9 @@ 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(),
Expand Down
3 changes: 3 additions & 0 deletions tests/Integration/Infrastructure/TokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
use OxidEsales\GraphQL\Base\Infrastructure\Token as TokenInfrastructure;
use OxidEsales\GraphQL\Base\Service\Token;
use OxidEsales\GraphQL\Base\Service\Token as TokenService;
use OxidEsales\EshopCommunity\Tests\ContainerTrait;

class TokenTest extends IntegrationTestCase
{
use ContainerTrait;

private const TEST_TOKEN_ID = '_my_test_token';

private const TEST_USER_ID = '_testuser';
Expand Down
25 changes: 16 additions & 9 deletions tests/Integration/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@

use DateTimeImmutable;
use Lcobucci\JWT\UnencryptedToken;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionFactoryInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionParameterProviderInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface;
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;
use OxidEsales\EshopCommunity\Tests\TestContainerFactory;
use OxidEsales\Facts\Facts;
use OxidEsales\GraphQL\Base\DataType\UserInterface;
use OxidEsales\GraphQL\Base\Framework\GraphQLQueryHandler;
use OxidEsales\GraphQL\Base\Framework\RequestReader;
use OxidEsales\GraphQL\Base\Framework\ResponseWriter;
use OxidEsales\GraphQL\Base\Framework\SchemaFactory;
use OxidEsales\GraphQL\Base\Infrastructure\Legacy;
use OxidEsales\GraphQL\Base\Infrastructure\RefreshTokenRepositoryInterface;
use OxidEsales\GraphQL\Base\Infrastructure\Token as TokenInfrastructure;
use OxidEsales\GraphQL\Base\Service\Authentication;
use OxidEsales\GraphQL\Base\Service\Authorization;
Expand All @@ -46,13 +50,9 @@ public 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'
)
Expand Down Expand Up @@ -97,6 +97,14 @@ public function setUp(): void
'oxidesales.graphqlbase.cacheadapter',
$cache
);
static::$container->setParameter(
'oxid_esales.db.replicate',
false
);
static::$container->setParameter(
'oxid_esales.db.replicas',
[]
);

static::beforeContainerCompile();

Expand Down Expand Up @@ -194,8 +202,7 @@ protected function uploadFile(
$boundary = '-------------' . uniqid();
$postData = $this->buildFileUpload($boundary, $fields, $map, $files);

$facts = new Facts();
$ch = curl_init($facts->getShopUrl() . '/graphql?lang=0&shp=1');
$ch = curl_init(getenv('OXID_SHOP_BASE_URL') . '/graphql?lang=0&shp=1');

$headers = [
'Connection: keep-alive',
Expand Down

0 comments on commit 35d4e73

Please sign in to comment.