From 04f932321281607c80db91dbd3fb93cc29238662 Mon Sep 17 00:00:00 2001 From: hkreuter Date: Wed, 11 Dec 2024 11:20:52 +0100 Subject: [PATCH] OXDEV-7248 Update tests to run with shop 8.0.x --- .github/oxid-esales/module-template.yaml | 2 +- .github/workflows/dispatch_module.yaml | 4 +- CHANGELOG.md | 5 + tests/Codeception/Acceptance.suite.yml | 14 +- tests/Codeception/Acceptance/_bootstrap.php | 3 +- .../Config/CodeceptionParametersProvider.php | 153 ++++++++++++++++++ tests/Codeception/Config/params.php | 60 +------ .../Codeception/Support/AcceptanceTester.php | 5 +- .../Codeception/Support/Helper/Acceptance.php | 7 +- .../Controller/StartControllerTest.php | 8 +- .../Extension/Model/BasketTest.php | 1 + .../Controller/GreetingControllerTest.php | 9 +- .../Repository/GreetingRepositoryTest.php | 22 ++- tests/Integration/IntegrationTestCase.php | 10 +- .../ProductVote/Dao/ProductVoteDaoTest.php | 12 +- .../ProductVote/Dao/ResultDaoTest.php | 12 +- .../Repository/TrackerRepositoryTest.php | 11 +- .../Infrastructure/UserModelFactoryTest.php | 6 +- .../Settings/Service/ModuleSettingsTest.php | 9 +- 19 files changed, 241 insertions(+), 112 deletions(-) create mode 100644 tests/Codeception/Config/CodeceptionParametersProvider.php diff --git a/.github/oxid-esales/module-template.yaml b/.github/oxid-esales/module-template.yaml index 726ddae..a451599 100644 --- a/.github/oxid-esales/module-template.yaml +++ b/.github/oxid-esales/module-template.yaml @@ -18,7 +18,7 @@ install: } } custom_script_container: | - 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:database:reset vendor/bin/oe-console oe:module:install ./ vendor/bin/oe-eshop-doctrine_migration migrations:migrate vendor/bin/oe-console oe:module:activate oe_moduletemplate diff --git a/.github/workflows/dispatch_module.yaml b/.github/workflows/dispatch_module.yaml index a05e94f..760258a 100644 --- a/.github/workflows/dispatch_module.yaml +++ b/.github/workflows/dispatch_module.yaml @@ -12,7 +12,7 @@ on: - 'PHP8.2/MariaDB11' - 'PHP8.3/MySQL8.0' - 'PHP8.3/MariaDB11' - default: 'PHP8.2/MySQL8.0' + default: 'PHP8.3/MySQL8.0' description: 'Limit to one PHP/MySQL combination' use_dev_version: type: choice @@ -42,7 +42,7 @@ jobs: ;; esac # shellcheck disable=SC2088 - TESTPLAN="~/defaults/7.2.x.yaml,${LIMIT}~/module-template.yaml" + TESTPLAN="~/defaults/8.0.x.yaml,${LIMIT}~/module-template.yaml" echo "testplan=${TESTPLAN}" | tee -a "${GITHUB_OUTPUT}" dispatch_stable: diff --git a/CHANGELOG.md b/CHANGELOG.md index ceb6686..c07803a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Undecided] - Unreleased + +### Changed +- Updated to work with OXID eShop 8.0.x. + ## [v5.0.0] - Unreleased ### Changed diff --git a/tests/Codeception/Acceptance.suite.yml b/tests/Codeception/Acceptance.suite.yml index 4035d7e..8e24b68 100644 --- a/tests/Codeception/Acceptance.suite.yml +++ b/tests/Codeception/Acceptance.suite.yml @@ -12,11 +12,17 @@ modules: license: '%license_key%' - WebDriver: url: '%SHOP_URL%' - host: '%SELENIUM_SERVER_HOST%' - browser: '%BROWSER_NAME%' + browser: '%BROWSER%' port: '%SELENIUM_SERVER_PORT%' - window_size: 1920x1080 + host: '%SELENIUM_SERVER_HOST%' + window_size: maximize clear_cookies: true + restart: true + capabilities: + chromeOptions: + excludeSwitches: [ 'enable-automation' ] + prefs: + 'credentials_enable_service': false - Db: dsn: 'mysql:host=%DB_HOST%;dbname=%DB_NAME%;charset=utf8' user: '%DB_USERNAME%' @@ -48,7 +54,7 @@ modules: - \OxidEsales\Codeception\Module\Database - Db - \OxidEsales\Codeception\Module\Translation\TranslationsModule: - shop_path: '%SHOP_SOURCE_PATH%' + shop_path: '%PROJECT_ROOT%/source' paths: - 'Application/views/apex' - 'Application/views/admin_twig' diff --git a/tests/Codeception/Acceptance/_bootstrap.php b/tests/Codeception/Acceptance/_bootstrap.php index 09bcc31..bd92f26 100644 --- a/tests/Codeception/Acceptance/_bootstrap.php +++ b/tests/Codeception/Acceptance/_bootstrap.php @@ -8,9 +8,10 @@ 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'); $helper = new \OxidEsales\Codeception\Module\FixturesHelper(); $helper->loadRuntimeFixtures(__DIR__ . '/../Support/Data/fixtures.php'); diff --git a/tests/Codeception/Config/CodeceptionParametersProvider.php b/tests/Codeception/Config/CodeceptionParametersProvider.php new file mode 100644 index 0000000..36d3874 --- /dev/null +++ b/tests/Codeception/Config/CodeceptionParametersProvider.php @@ -0,0 +1,153 @@ +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', 'fixtures.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(); + } +} diff --git a/tests/Codeception/Config/params.php b/tests/Codeception/Config/params.php index 075bf63..1cada51 100644 --- a/tests/Codeception/Config/params.php +++ b/tests/Codeception/Config/params.php @@ -7,62 +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\ModuleTemplate\Tests\Codeception\Config; -$facts = new Facts(); - -return [ - 'SHOP_URL' => $facts->getShopUrl(), - 'SHOP_SOURCE_PATH' => $facts->getSourcePath(), - 'SOURCE_RELATIVE_PACKAGE_PATH' => getSourceRelativePackagePath($facts), - 'VENDOR_PATH' => $facts->getVendorPath(), - 'DB_NAME' => $facts->getDatabaseName(), - 'DB_USERNAME' => $facts->getDatabaseUserName(), - 'DB_PASSWORD' => $facts->getDatabasePassword(), - 'DB_HOST' => $facts->getDatabaseHost(), - 'DB_PORT' => $facts->getDatabasePort(), - 'DUMP_PATH' => getTemporaryDataDumpFilePath(), - 'MODULE_DUMP_PATH' => getCodeceptionSpecificFixtureFilePath(), - 'MYSQL_CONFIG_PATH' => getMysqlConfigPath(), - 'FIXTURES_PATH' => getGenericFixtureSqlFilePath(), - 'SELENIUM_SERVER_PORT' => getenv('SELENIUM_SERVER_PORT') ?: '4444', - 'SELENIUM_SERVER_HOST' => getenv('SELENIUM_SERVER_HOST') ?: 'selenium', - 'BROWSER_NAME' => getenv('BROWSER_NAME') ?: 'chrome', - 'PHP_BIN' => getenv('PHPBIN') ?: 'php', - 'SCREEN_SHOT_URL' => getenv('CC_SCREEN_SHOTS_PATH') ?: '', - 'THEME_ID' => getenv('THEME_ID') ?: 'apex', -]; - -function getSourceRelativePackagePath(Facts $facts): string -{ - return str_replace($facts->getShopRootPath(), '..', __DIR__) . '/../../../'; -} - -function getTemporaryDataDumpFilePath(): string -{ - return Path::join(__DIR__, '../Support', '_generated', 'dump.sql'); -} - -function getCodeceptionSpecificFixtureFilePath(): string -{ - return Path::join(__DIR__, '../Support/Data', 'fixtures.sql'); -} - -function getMysqlConfigPath(): string -{ - $facts = new Facts(); - $configFilePath = Path::join($facts->getSourcePath(), 'config.inc.php'); - $configFile = new ConfigFile($configFilePath); - $generator = new DatabaseDefaultsFileGenerator($configFile); - - return $generator->generate(); -} - -function getGenericFixtureSqlFilePath(): string -{ - $facts = new Facts(); - return Path::join(__DIR__, '/../../', 'Fixtures', 'testdata_' . strtolower($facts->getEdition()) . '.sql'); -} \ No newline at end of file +return (new CodeceptionParametersProvider())->getParameters(); diff --git a/tests/Codeception/Support/AcceptanceTester.php b/tests/Codeception/Support/AcceptanceTester.php index 6a18554..63cd10d 100644 --- a/tests/Codeception/Support/AcceptanceTester.php +++ b/tests/Codeception/Support/AcceptanceTester.php @@ -14,7 +14,6 @@ use OxidEsales\Codeception\Admin\AdminPanel; use OxidEsales\Codeception\Page\Home; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; -use OxidEsales\Facts\Facts; use OxidEsales\ModuleTemplate\Settings\Service\ModuleSettingsServiceInterface; /** @@ -88,9 +87,7 @@ public function resetGreetingTracker(): void public function getShopUrl(): string { - $facts = new Facts(); - - return $facts->getShopUrl(); + return getenv('OXID_SHOP_BASE_URL'); } public function openAdmin(): AdminLoginPage diff --git a/tests/Codeception/Support/Helper/Acceptance.php b/tests/Codeception/Support/Helper/Acceptance.php index 133431e..1f290a8 100644 --- a/tests/Codeception/Support/Helper/Acceptance.php +++ b/tests/Codeception/Support/Helper/Acceptance.php @@ -9,15 +9,10 @@ namespace OxidEsales\ModuleTemplate\Tests\Codeception\Support\Helper; -use OxidEsales\Facts\Facts; - // here you can define custom actions // all public methods declared in helper class will be available in $I final class Acceptance extends \Codeception\Module { - public function _beforeSuite($settings = []): void - { - exec((new Facts())->getShopRootPath() . '/bin/oe-console oe:module:activate oe_moduletemplate'); - } + } diff --git a/tests/Integration/Extension/Controller/StartControllerTest.php b/tests/Integration/Extension/Controller/StartControllerTest.php index 58e24c0..157571e 100644 --- a/tests/Integration/Extension/Controller/StartControllerTest.php +++ b/tests/Integration/Extension/Controller/StartControllerTest.php @@ -17,6 +17,7 @@ use OxidEsales\ModuleTemplate\Settings\Service\ModuleSettingsServiceInterface; use OxidEsales\ModuleTemplate\Tests\Integration\IntegrationTestCase; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; /* * Here we have full integration test cases for a what we call 'chain extended' shop class. @@ -46,9 +47,7 @@ public function tearDown(): void parent::tearDown(); } - /** - * @dataProvider providerCanUpdateOemtGreeting - */ + #[DataProvider('providerCanUpdateOemtGreeting')] public function testCanUpdateOemtGreeting(bool $hasUser, string $mode, bool $expected): void { $moduleSettings = $this->get(ModuleSettingsServiceInterface::class); @@ -64,10 +63,9 @@ public function testCanUpdateOemtGreeting(bool $hasUser, string $mode, bool $exp } /** - * @dataProvider providerGetOemtGreeting - * * @param mixed $expect */ + #[DataProvider('providerGetOemtGreeting')] public function testGetOemtGreeting(bool $hasUser, string $mode, $expect): void { $moduleSettings = $this->get(ModuleSettingsServiceInterface::class); diff --git a/tests/Integration/Extension/Model/BasketTest.php b/tests/Integration/Extension/Model/BasketTest.php index 1d69775..8cf3338 100644 --- a/tests/Integration/Extension/Model/BasketTest.php +++ b/tests/Integration/Extension/Model/BasketTest.php @@ -38,6 +38,7 @@ private function prepareTestData(): void 'oxvarcount' => null, 'oxstockflag' => null, 'oxshopid' => null, + 'oxlowstockactive' => 0 ]); $product->save(); } diff --git a/tests/Integration/Greeting/Controller/GreetingControllerTest.php b/tests/Integration/Greeting/Controller/GreetingControllerTest.php index 837ffd3..bf4e356 100644 --- a/tests/Integration/Greeting/Controller/GreetingControllerTest.php +++ b/tests/Integration/Greeting/Controller/GreetingControllerTest.php @@ -20,6 +20,7 @@ use OxidEsales\ModuleTemplate\Tracker\Model\TrackerModel; use OxidEsales\ModuleTemplate\Tracker\Repository\TrackerRepositoryInterface; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; /* * We want to test controller behavior going 'full way'. @@ -51,9 +52,7 @@ public function tearDown(): void parent::tearDown(); } - /** - * @dataProvider providerOemtGreeting - */ + #[DataProvider('providerOemtGreeting')] public function testUpdateGreeting(bool $hasUser, string $mode, string $expected, int $count): void { $moduleSettings = $this->get(ModuleSettingsServiceInterface::class); @@ -78,9 +77,7 @@ public function testUpdateGreeting(bool $hasUser, string $mode, string $expected $this->assertSame($count, $tracker->getCount()); } - /** - * @dataProvider providerRender - */ + #[DataProvider('providerRender')] public function testRender(bool $hasUser, string $mode, array $expected): void { $this->createTestTracker(); diff --git a/tests/Integration/Greeting/Repository/GreetingRepositoryTest.php b/tests/Integration/Greeting/Repository/GreetingRepositoryTest.php index 47fc36e..1a051bc 100644 --- a/tests/Integration/Greeting/Repository/GreetingRepositoryTest.php +++ b/tests/Integration/Greeting/Repository/GreetingRepositoryTest.php @@ -10,23 +10,31 @@ namespace OxidEsales\ModuleTemplate\Tests\Integration\Greeting\Repository; use OxidEsales\Eshop\Application\Model\User as EshopModelUser; +use OxidEsales\EshopCommunity\Core\Di\ContainerFacade; use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; -use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase; use OxidEsales\ModuleTemplate\Greeting\Repository\GreetingRepository; use OxidEsales\ModuleTemplate\Greeting\Repository\GreetingRepositoryInterface; +use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(GreetingRepository::class)] -class GreetingRepositoryTest extends IntegrationTestCase +class GreetingRepositoryTest extends TestCase { public const TEST_USER_ID = '_testuser'; public const TEST_GREETING = 'Hi there'; + protected function tearDown(): void + { + $this->cleanUpUsers(); + + parent::tearDown(); + } + public function testGetSavedUserGreeting(): void { $this->prepareTestData(); - $repo = $this->get(GreetingRepositoryInterface::class); + $repo = ContainerFacade::get(GreetingRepositoryInterface::class); $this->assertSame(self::TEST_GREETING, $repo->getSavedUserGreeting(self::TEST_USER_ID)); $this->assertSame('', $repo->getSavedUserGreeting('_notexisting')); @@ -34,13 +42,11 @@ public function testGetSavedUserGreeting(): void private function prepareTestData(): void { - $this->cleanUpUsers(); - $user = oxNew(EshopModelUser::class); $user->assign( [ - 'oxid' => self::TEST_USER_ID, - 'oemtgreeting' => self::TEST_GREETING, + 'oxid' => self::TEST_USER_ID, + 'oemtgreeting' => self::TEST_GREETING ] ); $user->save(); @@ -48,7 +54,7 @@ private function prepareTestData(): void private function cleanUpUsers() { - $queryBuilder = $this->get(QueryBuilderFactoryInterface::class)->create(); + $queryBuilder = ContainerFacade::get(QueryBuilderFactoryInterface::class)->create(); $queryBuilder->delete('oxuser'); $queryBuilder->execute(); } diff --git a/tests/Integration/IntegrationTestCase.php b/tests/Integration/IntegrationTestCase.php index d4d8a44..aa2359b 100644 --- a/tests/Integration/IntegrationTestCase.php +++ b/tests/Integration/IntegrationTestCase.php @@ -10,9 +10,10 @@ namespace OxidEsales\ModuleTemplate\Tests\Integration; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; +use Codeception\PHPUnit\TestCase; use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; -class IntegrationTestCase extends \OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase +class IntegrationTestCase extends TestCase { protected function cleanUpUsers() { @@ -28,6 +29,13 @@ protected function cleanUpTrackers() $queryBuilder->execute(); } + protected function cleanUpVotes() + { + $queryBuilder = $this->get(QueryBuilderFactoryInterface::class)->create(); + $queryBuilder->delete('oemt_product_vote'); + $queryBuilder->execute(); + } + protected function get(string $serviceId) { return ContainerFactory::getInstance()->getContainer()->get($serviceId); diff --git a/tests/Integration/ProductVote/Dao/ProductVoteDaoTest.php b/tests/Integration/ProductVote/Dao/ProductVoteDaoTest.php index 06de141..b8027a9 100644 --- a/tests/Integration/ProductVote/Dao/ProductVoteDaoTest.php +++ b/tests/Integration/ProductVote/Dao/ProductVoteDaoTest.php @@ -9,7 +9,8 @@ namespace OxidEsales\ModuleTemplate\Tests\Integration\ProductVote\Dao; -use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase; +use OxidEsales\EshopCommunity\Tests\ContainerTrait; +use OxidEsales\ModuleTemplate\Tests\Integration\IntegrationTestCase; use OxidEsales\ModuleTemplate\ProductVote\Dao\ProductVoteDao; use OxidEsales\ModuleTemplate\ProductVote\Dao\ProductVoteDaoInterface; use OxidEsales\ModuleTemplate\ProductVote\DataObject\ProductVote; @@ -20,9 +21,18 @@ #[CoversClass(ProductVoteDao::class)] final class ProductVoteDaoTest extends IntegrationTestCase { + use ContainerTrait; + private const TEST_USER_ID = '_testuser'; private const TEST_PRODUCT_ID = '_testproduct'; + protected function tearDown(): void + { + $this->cleanUpVotes(); + + parent::tearDown(); + } + #[Test] public function noVoteForNoRecord(): void { diff --git a/tests/Integration/ProductVote/Dao/ResultDaoTest.php b/tests/Integration/ProductVote/Dao/ResultDaoTest.php index da322cf..3eb561a 100644 --- a/tests/Integration/ProductVote/Dao/ResultDaoTest.php +++ b/tests/Integration/ProductVote/Dao/ResultDaoTest.php @@ -9,19 +9,29 @@ namespace OxidEsales\ModuleTemplate\Tests\Integration\ProductVote\Dao; -use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase; +use OxidEsales\EshopCommunity\Tests\ContainerTrait; use OxidEsales\ModuleTemplate\ProductVote\Dao\ProductVoteDaoInterface; use OxidEsales\ModuleTemplate\ProductVote\Dao\VoteResultDao; use OxidEsales\ModuleTemplate\ProductVote\Dao\VoteResultDaoInterface; use OxidEsales\ModuleTemplate\ProductVote\DataObject\ProductVote; +use OxidEsales\ModuleTemplate\Tests\Integration\IntegrationTestCase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; #[CoversClass(VoteResultDao::class)] final class ResultDaoTest extends IntegrationTestCase { + use ContainerTrait; + private const TEST_PRODUCT_ID = '_testproduct'; + protected function tearDown(): void + { + $this->cleanUpVotes(); + + parent::tearDown(); + } + #[Test] public function calculateNoVotes(): void { diff --git a/tests/Integration/Tracker/Repository/TrackerRepositoryTest.php b/tests/Integration/Tracker/Repository/TrackerRepositoryTest.php index 816fe24..a98cdf3 100644 --- a/tests/Integration/Tracker/Repository/TrackerRepositoryTest.php +++ b/tests/Integration/Tracker/Repository/TrackerRepositoryTest.php @@ -9,15 +9,16 @@ namespace OxidEsales\ModuleTemplate\Tests\Integration\Tracker\Repository; +use Codeception\PHPUnit\TestCase; +use OxidEsales\EshopCommunity\Core\Di\ContainerFacade; use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; -use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase; use OxidEsales\ModuleTemplate\Tracker\Model\TrackerModel; use OxidEsales\ModuleTemplate\Tracker\Repository\TrackerRepository; use OxidEsales\ModuleTemplate\Tracker\Repository\TrackerRepositoryInterface; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(TrackerRepository::class)] -final class TrackerRepositoryTest extends IntegrationTestCase +final class TrackerRepositoryTest extends TestCase { public const TEST_TRACKER_ID = '_testoxid'; @@ -34,7 +35,7 @@ public function setUp(): void private function cleanUpTrackers() { - $queryBuilder = $this->get(QueryBuilderFactoryInterface::class)->create(); + $queryBuilder = ContainerFacade::get(QueryBuilderFactoryInterface::class)->create(); $queryBuilder->delete('oemt_tracker'); $queryBuilder->execute(); } @@ -43,7 +44,7 @@ public function testGetExistingTrackerByUserId(): void { $this->prepareTestData(); - $sut = $this->get(TrackerRepositoryInterface::class); + $sut = ContainerFacade::get(TrackerRepositoryInterface::class); $tracker = $sut->getTrackerByUserId(self::TEST_USER_ID); $this->assertSame(self::TEST_TRACKER_ID, $tracker->getId()); @@ -51,7 +52,7 @@ public function testGetExistingTrackerByUserId(): void public function testGetNotExistingTrackerByUserId(): void { - $sut = $this->get(TrackerRepositoryInterface::class); + $sut = ContainerFacade::get(TrackerRepositoryInterface::class); $tracker = $sut->getTrackerByUserId('_notexisting'); $this->assertEmpty($tracker->getId()); diff --git a/tests/Unit/Greeting/Infrastructure/UserModelFactoryTest.php b/tests/Unit/Greeting/Infrastructure/UserModelFactoryTest.php index 2e4bd71..10b4e9d 100644 --- a/tests/Unit/Greeting/Infrastructure/UserModelFactoryTest.php +++ b/tests/Unit/Greeting/Infrastructure/UserModelFactoryTest.php @@ -11,11 +11,11 @@ use OxidEsales\Eshop\Application\Model\User; use OxidEsales\ModuleTemplate\Greeting\Infrastructure\UserModelFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Attributes; -/** - * @covers \OxidEsales\ModuleTemplate\Greeting\Infrastructure\UserModelFactory - */ +#[CoversClass(UserModelFactory::class)] class UserModelFactoryTest extends TestCase { public function testCreateProducesCorrectTypeOfObjects(): void diff --git a/tests/Unit/Settings/Service/ModuleSettingsTest.php b/tests/Unit/Settings/Service/ModuleSettingsTest.php index ea650e4..c423849 100644 --- a/tests/Unit/Settings/Service/ModuleSettingsTest.php +++ b/tests/Unit/Settings/Service/ModuleSettingsTest.php @@ -13,15 +13,14 @@ use OxidEsales\ModuleTemplate\Core\Module; use OxidEsales\ModuleTemplate\Settings\Service\ModuleSettingsService; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\String\UnicodeString; #[CoversClass(ModuleSettingsService::class)] final class ModuleSettingsTest extends TestCase { - /** - * @dataProvider getGreetingModeDataProvider - */ + #[DataProvider('getGreetingModeDataProvider')] public function testGetGreetingMode(string $value, string $expected): void { $mssMock = $this->createPartialMock(ModuleSettingService::class, ['getString']); @@ -55,9 +54,7 @@ public static function getGreetingModeDataProvider(): array ]; } - /** - * @dataProvider isPersonalGreetingModeDataProvider - */ + #[DataProvider('isPersonalGreetingModeDataProvider')] public function testIsPersonalGreetingMode(string $value, bool $expected): void { $mssMock = $this->createPartialMock(ModuleSettingService::class, ['getString']);