From f5e7cda9dad0c2044850f5cc31bb266acef4eff6 Mon Sep 17 00:00:00 2001 From: hkreuter Date: Wed, 22 Jan 2025 10:26:14 +0100 Subject: [PATCH] OXDEV-7248 Update module to work with shop 8.0 --- .github/oxid-esales/graphql-base.yaml | 11 +- .github/oxid-esales/install.sh | 81 ++++++++++ .github/workflows/dispatch_module.yaml | 2 +- .github/workflows/schedule_module.yaml | 2 +- .github/workflows/trigger.yaml | 2 +- composer.json | 9 +- recipes/setup-development.sh | 22 +-- tests/Codeception/Acceptance.suite.yml | 2 + tests/Codeception/Acceptance/_bootstrap.php | 3 +- .../Config/CodeceptionParametersProvider.php | 151 ++++++++++++++---- .../Codeception/Support/Helper/Acceptance.php | 21 --- tests/Integration/EnterpriseTestCase.php | 8 +- .../GraphQLQueryHandlerFileUploadTest.php | 3 + .../RefreshTokenRepositoryTest.php | 28 +++- .../Integration/Infrastructure/TokenTest.php | 38 ++++- tests/Integration/TestCase.php | 32 ++-- tests/Unit/DataType/LoginTest.php | 2 +- tests/Unit/DataType/RefreshTokenTest.php | 2 +- tests/phpunit.xml | 1 + 19 files changed, 314 insertions(+), 106 deletions(-) create mode 100644 .github/oxid-esales/install.sh diff --git a/.github/oxid-esales/graphql-base.yaml b/.github/oxid-esales/graphql-base.yaml index d369afcc..788cce71 100644 --- a/.github/oxid-esales/graphql-base.yaml +++ b/.github/oxid-esales/graphql-base.yaml @@ -6,6 +6,8 @@ install: cache: prepared_shop: false + method: 'script' + script: 'source/.github/oxid-esales/install.sh' git: repository: '{{ $repo }}' ref: &ref '{{ .Github.RefName }}' @@ -25,11 +27,8 @@ install: custom_script_container: | perl -pi -e 'print "SetEnvIf Authorization \"(.*)\" HTTP_AUTHORIZATION=\$1\n\n" if $. == 1' source/.htaccess - vendor/bin/oe-console oe:database:reset --db-host=mysql --db-port=3306 --db-name=example --db-user=root --db-password=root --force vendor/bin/oe-console oe:module:install ./ - - vendor/bin/oe-eshop-doctrine_migration migrations:migrate - vendor/bin/oe-eshop-db_views_generate + vendor/bin/oe-console oe:database:reset --force vendor/bin/oe-console oe:module:activate "{{ $ids }}" vendor/bin/oe-console oe:theme:activate apex @@ -73,5 +72,5 @@ sonarcloud: -Dsonar.sources=src \ -Dsonar.tests=tests -finish: - slack_title: '{{ print $name }} ({{ .Data.global.git.shop_ref }}) by {{ .Github.Actor }}' +#finish: +# slack_title: '{{ print $name }} ({{ .Data.global.git.shop_ref }}) by {{ .Github.Actor }}' diff --git a/.github/oxid-esales/install.sh b/.github/oxid-esales/install.sh new file mode 100644 index 00000000..e91d72e1 --- /dev/null +++ b/.github/oxid-esales/install.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# shellcheck disable=SC2154 +# Lower case environment variables are passed from the workflow and used here +# We use a validation loop in init to ensure, they're set +# shellcheck disable=SC2086 +# We want install_container_options to count as multiple arguments +set -e + +function error() { + echo -e "\033[0;31m${1}\033[0m" + exit 1 +} + +function init() { + for VAR in install_container_method install_container_options install_container_name \ + install_config_idebug install_is_enterprise; do + echo -n "Checking, if $VAR is set ..." + if [ -z ${VAR+x} ]; then + error "Variable '${VAR}' not set" + fi + echo "OK, ${VAR}='${!VAR}'" + done + echo -n "Locating oe-console ... " + cd source || exit 1 + if [ -f 'bin/oe-console' ]; then + OE_CONSOLE='bin/oe-console' + else + if [ -f 'vendor/bin/oe-console' ]; then + OE_CONSOLE='vendor/bin/oe-console' + else + error "Can't find oe-console in bin or vendor/bin!" + fi + fi + echo "OK, using '${OE_CONSOLE}'" + if [ -z "${OXID_BUILD_DIRECTORY}" ]; then + echo "OXID_BUILD_DIRECTORY is not set, setting it to /var/www/var/cache/" + export OXID_BUILD_DIRECTORY="/var/www/var/cache/" + else + echo "OXID_BUILD_DIRECTORY is set to '${OXID_BUILD_DIRECTORY}'" + fi + if [ ! -d "${OXID_BUILD_DIRECTORY/\/var\/www/source}" ]; then + echo "Creating '${OXID_BUILD_DIRECTORY}'" + + docker compose "${install_container_method}" -T \ + ${install_container_options} \ + "${install_container_name}" \ + mkdir -p "${OXID_BUILD_DIRECTORY}" + + echo "done with build directory" + fi +} + +init + +cp vendor/oxid-esales/oxideshop-ce/.env.dist .env +cat .env + + +# Run Install Shop +docker compose "${install_container_method}" -T \ + ${install_container_options} \ + "${install_container_name}" \ + ${OE_CONSOLE} oe:database:reset --force + +# Activate iDebug +if [ "${install_config_idebug}" == 'true' ]; then + export OXID_DEBUG_MODE="true" +fi + +# Activate theme +docker compose "${install_container_method}" -T \ + ${install_container_options} \ + "${install_container_name}" \ + ${OE_CONSOLE} oe:theme:activate apex + +# Output PHP error log +if [ -s data/php/logs/error_log.txt ]; then + echo -e "\033[0;35mPHP error log\033[0m" + cat data/php/logs/error_log.txt +fi +exit 0 diff --git a/.github/workflows/dispatch_module.yaml b/.github/workflows/dispatch_module.yaml index f078975e..5c16b36d 100644 --- a/.github/workflows/dispatch_module.yaml +++ b/.github/workflows/dispatch_module.yaml @@ -44,7 +44,7 @@ jobs: ;; esac # shellcheck disable=SC2088 - TESTPLAN="~/defaults/7.3.x.yaml,${LIMIT}~/graphql-base.yaml" + TESTPLAN="~/defaults/8.0.x.yaml,${LIMIT}~/graphql-base.yaml" echo "testplan=${TESTPLAN}" | tee -a "${GITHUB_OUTPUT}" dispatch_stable: diff --git a/.github/workflows/schedule_module.yaml b/.github/workflows/schedule_module.yaml index 19145bab..e38f4870 100644 --- a/.github/workflows/schedule_module.yaml +++ b/.github/workflows/schedule_module.yaml @@ -8,7 +8,7 @@ jobs: call_matrix: uses: OXID-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v4 with: - testplan: '~/defaults/7.3.x.yaml,~/graphql-base.yaml' + testplan: '~/defaults/8.0.x.yaml,~/graphql-base.yaml' runs_on: '"ubuntu-latest"' defaults: 'v4' plan_folder: '.github/oxid-esales' diff --git a/.github/workflows/trigger.yaml b/.github/workflows/trigger.yaml index 6cb80f05..c8083506 100644 --- a/.github/workflows/trigger.yaml +++ b/.github/workflows/trigger.yaml @@ -8,7 +8,7 @@ jobs: call_matrix: uses: OXID-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v4 with: - testplan: '~/defaults/7.3.x.yaml,~/defaults/php8.2_mysql8.0_only.yaml,~/graphql-base.yaml' + testplan: '~/defaults/8.0.x.yaml,~/defaults/php8.3_mysql8.0_only.yaml,~/graphql-base.yaml' runs_on: '"ubuntu-latest"' defaults: 'v4' plan_folder: '.github/oxid-esales' diff --git a/composer.json b/composer.json index 702e5f7c..9c207dc1 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "require-dev": { "phpunit/phpunit": "^10.4", "ext-xdebug": "*", - "oxid-esales/oxideshop-ce": "dev-b-7.3.x", + "oxid-esales/oxideshop-ce": "dev-b-8.0.x", "phpstan/phpstan": "^1.10", "squizlabs/php_codesniffer": "3.*", "phpmd/phpmd": "^2.11", @@ -27,15 +27,16 @@ "codeception/module-phpbrowser": "*", "codeception/module-db": "*", "codeception/codeception": "^5.0", - "oxid-esales/codeception-modules": "dev-b-7.3.x", + "oxid-esales/codeception-modules": "dev-b-8.0.x", "codeception/module-asserts": "^3.0" }, "conflict": { - "oxid-esales/oxideshop-ce": "<7.3" + "oxid-esales/oxideshop-ce": "<8.0" }, "autoload": { "psr-4": { - "OxidEsales\\GraphQL\\Base\\": "src" + "OxidEsales\\GraphQL\\Base\\": "src", + "OxidEsales\\GraphQL\\Base\\Tests\\": "tests" } }, "minimum-stability": "dev", diff --git a/recipes/setup-development.sh b/recipes/setup-development.sh index f5bf1b82..35f58099 100755 --- a/recipes/setup-development.sh +++ b/recipes/setup-development.sh @@ -37,33 +37,35 @@ docker compose up --build -d php docker compose exec -T php git config --global --add safe.directory /var/www -$SCRIPT_PATH/parts/shared/require_shop_edition_packages.sh -e"${edition}" -v"dev-b-7.3.x" -$SCRIPT_PATH/parts/shared/require_twig_components.sh -e"${edition}" -b"b-7.3.x" -$SCRIPT_PATH/parts/shared/require.sh -n"oxid-esales/developer-tools" -v"dev-b-7.3.x" -$SCRIPT_PATH/parts/shared/require.sh -n"oxid-esales/oxideshop-doctrine-migration-wrapper" -v"dev-b-7.3.x" -$SCRIPT_PATH/parts/shared/require_theme_dev.sh -t"apex" -b"b-7.3.x" +$SCRIPT_PATH/parts/shared/require_shop_edition_packages.sh -e"${edition}" -v"dev-b-8.0.x" +$SCRIPT_PATH/parts/shared/require_twig_components.sh -e"${edition}" -b"b-8.0.x" +$SCRIPT_PATH/parts/shared/require.sh -n"oxid-esales/developer-tools" -v"dev-b-8.0.x" +$SCRIPT_PATH/parts/shared/require.sh -n"oxid-esales/oxideshop-doctrine-migration-wrapper" -v"dev-b-8.0.x" +$SCRIPT_PATH/parts/shared/require_theme_dev.sh -t"apex" -b"b-8.0.x" git clone https://github.com/OXID-eSales/oxapi-documentation source/documentation/oxapi-documentation make docpath=./source/documentation/oxapi-documentation addsphinxservice make up +docker compose exec php composer update --no-interaction --no-scripts --no-plugins +docker compose exec -T php cp /var/www/vendor/oxid-esales/oxideshop-ce/.env.dist /var/www/.env docker compose exec php composer update --no-interaction perl -pi\ -e 'print "SetEnvIf Authorization \"(.*)\" HTTP_AUTHORIZATION=\$1\n\n" if $. == 1'\ source/source/.htaccess -$SCRIPT_PATH/parts/shared/setup_database.sh --no-demodata - docker compose exec -T php vendor/bin/oe-console oe:module:install ./ -docker compose exec -T php vendor/bin/oe-eshop-doctrine_migration migrations:migrate -docker compose exec -T php vendor/bin/oe-eshop-db_views_generate +docker compose exec -T php vendor/bin/oe-console oe:database:reset --force docker compose exec -T php vendor/bin/oe-console oe:module:activate oe_graphql_base docker compose exec -T php vendor/bin/oe-console oe:theme:activate apex -$SCRIPT_PATH/parts/shared/create_admin.sh +email=${ADMIN_EMAIL:-noreply@oxid-esales.com} +password=${ADMIN_PASSWORD:-admin} +CONSOLE_PATH=$( [ -e "source/bin/oe-console" ] && echo "bin/oe-console" || echo "vendor/bin/oe-console" ) +docker compose exec -T php ${CONSOLE_PATH} oe:admin:create "$email" "$password" # Register all related project packages git repositories mkdir -p .idea; mkdir -p source/.idea; cp "${SCRIPT_PATH}/parts/bases/vcs.xml.base" .idea/vcs.xml diff --git a/tests/Codeception/Acceptance.suite.yml b/tests/Codeception/Acceptance.suite.yml index 82e18e36..f0cdafa8 100644 --- a/tests/Codeception/Acceptance.suite.yml +++ b/tests/Codeception/Acceptance.suite.yml @@ -1,6 +1,8 @@ # suite config actor: AcceptanceTester path: Acceptance +bootstrap: _bootstrap.php + modules: enabled: - Asserts diff --git a/tests/Codeception/Acceptance/_bootstrap.php b/tests/Codeception/Acceptance/_bootstrap.php index e6961e78..37110b4c 100644 --- a/tests/Codeception/Acceptance/_bootstrap.php +++ b/tests/Codeception/Acceptance/_bootstrap.php @@ -8,6 +8,7 @@ declare(strict_types=1); // This is acceptance bootstrap +use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\ProjectRootLocator; use Symfony\Component\Filesystem\Path; -require_once Path::join((new \OxidEsales\Facts\Facts())->getShopRootPath(), 'source', 'bootstrap.php'); +require_once Path::join((new ProjectRootLocator())->getProjectRoot(), 'source', 'bootstrap.php'); diff --git a/tests/Codeception/Config/CodeceptionParametersProvider.php b/tests/Codeception/Config/CodeceptionParametersProvider.php index 97c3ebd8..7bd45bd3 100644 --- a/tests/Codeception/Config/CodeceptionParametersProvider.php +++ b/tests/Codeception/Config/CodeceptionParametersProvider.php @@ -9,51 +9,144 @@ namespace OxidEsales\GraphQL\Base\Tests\Codeception\Config; -use OxidEsales\Codeception\Module\Database\DatabaseDefaultsFileGenerator; -use OxidEsales\Facts\Config\ConfigFile; -use OxidEsales\Facts\Facts; +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; -if ($shopRootPath = getenv('SHOP_ROOT_PATH')) { - require_once(Path::join($shopRootPath, 'source', 'bootstrap.php')); -} - -class CodeceptionParametersProvider { +class CodeceptionParametersProvider +{ + private DatabaseConfiguration $dbConfig; public function getParameters(): array { - $facts = new Facts(); - $php = (getenv('PHPBIN')) ?: 'php'; + $this->loadEnvironmentVariables(); + $this->dbConfig = (new DatabaseConfiguration(getenv('OXID_DB_URL'))); 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' => $this->getModuleTestDataDumpFilePath(), - 'MYSQL_CONFIG_PATH' => $this->getMysqlConfigPath(), - 'PHP_BIN' => $php, + '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 getModuleTestDataDumpFilePath() + private function getSourceRelativePackagePath(): string { - return Path::join(__DIR__, '..', 'Support', 'Data', 'dump.sql'); + return(str_replace($this->getProjectRoot(), '..', __DIR__) . '/../../../'); } - private function getMysqlConfigPath() + private function getCodeceptionSpecificFixtureFilePath(): string { - $facts = new Facts(); - $configFile = new ConfigFile($facts->getSourcePath() . '/config.inc.php'); + return Path::join(__DIR__, '../Support/Data', 'dump.sql'); + } - $generator = new DatabaseDefaultsFileGenerator($configFile); + private function getTestDataDumpFilePath(): string + { + return Path::join( + $this->getShopTestPath(), + '/Codeception/Support/_generated/shop-dump.sql' + ); + } - return $generator->generate(); + 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(); + } +} diff --git a/tests/Codeception/Support/Helper/Acceptance.php b/tests/Codeception/Support/Helper/Acceptance.php index 61f31204..dabc96b4 100644 --- a/tests/Codeception/Support/Helper/Acceptance.php +++ b/tests/Codeception/Support/Helper/Acceptance.php @@ -9,27 +9,6 @@ namespace OxidEsales\GraphQL\Base\Tests\Codeception\Helper; -use Exception; -use OxidEsales\Facts\Facts; - class Acceptance extends \Codeception\Module { - 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'); - } } diff --git a/tests/Integration/EnterpriseTestCase.php b/tests/Integration/EnterpriseTestCase.php index 41043333..e80975c7 100644 --- a/tests/Integration/EnterpriseTestCase.php +++ b/tests/Integration/EnterpriseTestCase.php @@ -9,17 +9,15 @@ namespace OxidEsales\GraphQL\Base\Tests\Integration; -use OxidEsales\Facts\Facts; +use OxidEsales\EshopCommunity\Internal\Framework\Edition\Edition; +use OxidEsales\EshopCommunity\Internal\Framework\Edition\EditionDirectoriesLocator; abstract class EnterpriseTestCase extends TokenTestCase { public function setUp(): void { - $facts = new Facts(); - - if ($facts->getEdition() !== 'EE') { + if (!(new EditionDirectoriesLocator())->getEditionRootPath(Edition::Enterprise)) { $this->markTestSkipped('Skip EE related tests for CE/PE edition'); - return; } diff --git a/tests/Integration/Framework/GraphQLQueryHandlerFileUploadTest.php b/tests/Integration/Framework/GraphQLQueryHandlerFileUploadTest.php index 18b2aa0c..17988fbc 100644 --- a/tests/Integration/Framework/GraphQLQueryHandlerFileUploadTest.php +++ b/tests/Integration/Framework/GraphQLQueryHandlerFileUploadTest.php @@ -9,6 +9,7 @@ namespace OxidEsales\GraphQL\Base\Tests\Integration\Framework; +use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; use OxidEsales\EshopCommunity\Internal\Container\BootstrapContainerFactory; use OxidEsales\EshopCommunity\Internal\Framework\DIContainer\Dao\ProjectYamlDao; use OxidEsales\EshopCommunity\Internal\Framework\DIContainer\Service\ProjectYamlImportService; @@ -34,6 +35,8 @@ public static function tearDownAfterClass(): void public function testFileUpload(): void { + ContainerFactory::resetContainer(); + $expected = file_get_contents(self::UPLOAD_FILE); $result = $this->uploadFile(self::UPLOAD_FILE, $this->getMutationData()); diff --git a/tests/Integration/Infrastructure/RefreshTokenRepositoryTest.php b/tests/Integration/Infrastructure/RefreshTokenRepositoryTest.php index 7f205890..1261eb9b 100644 --- a/tests/Integration/Infrastructure/RefreshTokenRepositoryTest.php +++ b/tests/Integration/Infrastructure/RefreshTokenRepositoryTest.php @@ -12,17 +12,31 @@ 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; 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 { + public function setUp(): void + { + parent::setUp(); + + ContainerFacade::get(ConnectionFactoryInterface::class) + ->create() + ->executeStatement( + file_get_contents( + __DIR__ . '/../../Fixtures/dump.sql' + ) + ); + } + public function testGetNewRefreshTokenGivesCorrectlyFilledDataType(): void { $sut = $this->getSut(); @@ -172,14 +186,14 @@ public function testInvalidateRefreshTokensWrongUserId(): void $this->assertTrue($sut->getTokenUser($token) instanceof UserInterface); } - private function getDbConnection(): Connection + public function getSut(): RefreshTokenRepositoryInterface { - return $this->get(ConnectionProviderInterface::class)->get(); + return $this->get(RefreshTokenRepositoryInterface::class); } - public function getSut(): RefreshTokenRepositoryInterface + public function getDbConnection(): Connection { - return $this->get(RefreshTokenRepositoryInterface::class); + return $this->get(ConnectionFactoryInterface::class)->create(); } private function checkRefreshTokenWithIdExists(string $oxid): bool diff --git a/tests/Integration/Infrastructure/TokenTest.php b/tests/Integration/Infrastructure/TokenTest.php index ffce3513..523544b3 100644 --- a/tests/Integration/Infrastructure/TokenTest.php +++ b/tests/Integration/Infrastructure/TokenTest.php @@ -13,7 +13,8 @@ use Lcobucci\JWT\Token\DataSet; use Lcobucci\JWT\UnencryptedToken; use OxidEsales\Eshop\Application\Model\User; -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\GraphQL\Base\DataType\Token as TokenDataType; use OxidEsales\GraphQL\Base\DataType\User as UserDataType; @@ -21,8 +22,10 @@ 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; +use PHPUnit\Framework\TestCase; -class TokenTest extends IntegrationTestCase +class TokenTest extends TestCase { private const TEST_TOKEN_ID = '_my_test_token'; @@ -31,15 +34,33 @@ class TokenTest extends IntegrationTestCase /** @var TokenInfrastructure */ private $tokenInfrastructure; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $containerFactory = new TestContainerFactory(); $container = $containerFactory->create(); + + $container->setParameter( + 'oxid_esales.db.replicate', + false + ); + $container->setParameter( + 'oxid_esales.db.replicas', + [] + ); + $container->compile(); $this->tokenInfrastructure = $container->get(TokenInfrastructure::class); } + protected function tearDown(): void + { + $this->cleanUp(); + + parent::tearDown(); + } + + public function testRegisterToken(): void { $this->tokenInfrastructure->registerToken( @@ -311,7 +332,7 @@ public function testUserHasToken(): void public function testInvalidateTokenAfterDeleteUser(): void { $userModel = oxNew(User::class); - $userModel->setId('_testUser'); + $userModel->setId(self::TEST_USER_ID); $userModel->setPassword('_testPassword'); $userModel->assign(['oxusername' => '_testUsername']); $userModel->save(); @@ -379,4 +400,13 @@ private function getTokenMock( return $token; } + + private function cleanUp(): void + { + ContainerFacade::get(ConnectionFactoryInterface::class) + ->create() + ->executeQuery( + 'truncate table `oegraphqltoken`' + ); + } } diff --git a/tests/Integration/TestCase.php b/tests/Integration/TestCase.php index 772ac35a..fec05adc 100644 --- a/tests/Integration/TestCase.php +++ b/tests/Integration/TestCase.php @@ -12,10 +12,10 @@ use DateTimeImmutable; use Lcobucci\JWT\UnencryptedToken; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; -use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; +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; use OxidEsales\GraphQL\Base\Framework\GraphQLQueryHandler; use OxidEsales\GraphQL\Base\Framework\RequestReader; @@ -46,23 +46,20 @@ public function setUp(): void { parent::setUp(); - $connection = ContainerFactory::getInstance() - ->getContainer() - ->get(QueryBuilderFactoryInterface::class) + ContainerFacade::get(ConnectionFactoryInterface::class) ->create() - ->getConnection(); - - $connection->executeStatement( - file_get_contents( - __DIR__ . '/../Fixtures/dump.sql' - ) - ); + ->executeStatement( + file_get_contents( + __DIR__ . '/../Fixtures/dump.sql' + ) + ); \OxidEsales\Eshop\Core\Registry::getLang()->resetBaseLanguage(); if (static::$container !== null) { return; } + $containerFactory = new TestContainerFactory(); static::$container = $containerFactory->create(); @@ -97,6 +94,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(); @@ -194,8 +199,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', diff --git a/tests/Unit/DataType/LoginTest.php b/tests/Unit/DataType/LoginTest.php index f2e16faf..dc38a35f 100644 --- a/tests/Unit/DataType/LoginTest.php +++ b/tests/Unit/DataType/LoginTest.php @@ -9,7 +9,7 @@ namespace OxidEsales\GraphQL\Base\Tests\Unit\DataType; -use Codeception\PHPUnit\TestCase; +use PHPUnit\Framework\TestCase; use Lcobucci\JWT\UnencryptedToken; use OxidEsales\GraphQL\Base\DataType\Login; use PHPUnit\Framework\Attributes\CoversClass; diff --git a/tests/Unit/DataType/RefreshTokenTest.php b/tests/Unit/DataType/RefreshTokenTest.php index fd51db2e..4f7f5d34 100644 --- a/tests/Unit/DataType/RefreshTokenTest.php +++ b/tests/Unit/DataType/RefreshTokenTest.php @@ -9,7 +9,7 @@ namespace OxidEsales\GraphQL\Base\Tests\Unit\DataType; -use Codeception\PHPUnit\TestCase; +use PHPUnit\Framework\TestCase; use OxidEsales\GraphQL\Base\DataType\RefreshToken; use OxidEsales\GraphQL\Base\Infrastructure\Model\RefreshToken as RefreshTokenModel; use PHPUnit\Framework\Attributes\CoversClass; diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 375c3643..1e4d404f 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -8,6 +8,7 @@ displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnTestsThatTriggerErrors="true" displayDetailsOnTestsThatTriggerNotices="true" + processIsolation="true" >