From 6000c3ff6eb1bc0a2aa9b9d1fa4efbb86c27db54 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Fri, 7 Jun 2024 16:11:55 +0200 Subject: [PATCH] [TASK] Move test to abstract class testing Relates: #508 --- ...onfigurationFromTypoScriptServiceTest.php} | 20 ++-- .../Service/TaxClassServiceTest.php | 19 ++-- shell.nix | 95 +++++++++++++++++++ 3 files changed, 111 insertions(+), 23 deletions(-) rename Tests/Functional/Service/{PaymentMethodsFromTypoScriptServiceTest.php => AbstractConfigurationFromTypoScriptServiceTest.php} (91%) create mode 100644 shell.nix diff --git a/Tests/Functional/Service/PaymentMethodsFromTypoScriptServiceTest.php b/Tests/Functional/Service/AbstractConfigurationFromTypoScriptServiceTest.php similarity index 91% rename from Tests/Functional/Service/PaymentMethodsFromTypoScriptServiceTest.php rename to Tests/Functional/Service/AbstractConfigurationFromTypoScriptServiceTest.php index 1b98376a..aeadfc44 100644 --- a/Tests/Functional/Service/PaymentMethodsFromTypoScriptServiceTest.php +++ b/Tests/Functional/Service/AbstractConfigurationFromTypoScriptServiceTest.php @@ -9,14 +9,16 @@ * LICENSE file that was distributed with this source code. */ -use Extcode\Cart\Domain\Model\Cart\Cart; use Extcode\Cart\Domain\Model\Cart\ServiceFactory; -use Extcode\Cart\Service\PaymentMethodsFromTypoScriptService; +use Extcode\Cart\Service\AbstractConfigurationFromTypoScriptService; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManager; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class PaymentMethodsFromTypoScriptServiceTest extends FunctionalTestCase +#[CoversClass(AbstractConfigurationFromTypoScriptService::class)] +class AbstractConfigurationFromTypoScriptServiceTest extends FunctionalTestCase { public function setUp(): void { @@ -25,9 +27,7 @@ public function setUp(): void parent::setUp(); } - /** - * @test - */ + #[Test] public function getTypePluginSettingsReturnsTypeCountrySettings() { $type = 'payments'; @@ -88,7 +88,7 @@ public function getTypePluginSettingsReturnsTypeCountrySettings() $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class); - $paymentMethodsService = new PaymentMethodsFromTypoScriptService($configurationManager, new ServiceFactory()); + $paymentMethodsService = new class ($configurationManager, new ServiceFactory()) extends AbstractConfigurationFromTypoScriptService {}; $reflection = new \ReflectionClass($paymentMethodsService); $reflection_property = $reflection->getProperty('configurations'); @@ -112,9 +112,7 @@ public function getTypePluginSettingsReturnsTypeCountrySettings() ); } - /** - * @test - */ + #[Test] public function getTypeZonePluginSettingsReturnsTypeZoneSettings() { $type = 'payments'; @@ -178,7 +176,7 @@ public function getTypeZonePluginSettingsReturnsTypeZoneSettings() $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class); - $paymentMethodsService = new PaymentMethodsFromTypoScriptService($configurationManager, new ServiceFactory()); + $paymentMethodsService = new class ($configurationManager, new ServiceFactory()) extends AbstractConfigurationFromTypoScriptService {}; $reflection = new \ReflectionClass($paymentMethodsService); $reflection_property = $reflection->getProperty('configurations'); diff --git a/Tests/Functional/Service/TaxClassServiceTest.php b/Tests/Functional/Service/TaxClassServiceTest.php index 93d6747a..b6bdb0d3 100644 --- a/Tests/Functional/Service/TaxClassServiceTest.php +++ b/Tests/Functional/Service/TaxClassServiceTest.php @@ -11,9 +11,12 @@ use Extcode\Cart\Domain\Model\Cart\TaxClass; use Extcode\Cart\Service\TaxClassService; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; +#[CoversClass(FunctionalTestCase::class)] class TaxClassServiceTest extends FunctionalTestCase { protected TaxClassService $taxClassService; @@ -29,9 +32,7 @@ public function setUp(): void ); } - /** - * @test - */ + #[Test] public function parsingTaxClassesFromTypoScriptWithoutCountryCodeReturnsDirectlyConfiguredArrayOfTaxClasses() { $settings = [ @@ -84,9 +85,7 @@ public function parsingTaxClassesFromTypoScriptWithoutCountryCodeReturnsDirectly ); } - /** - * @test - */ + #[Test] public function parsingTaxClassesFromTypoScriptWithCountryCodeReturnsCountrySpecificArrayOfTaxClasses() { $settings = [ @@ -158,9 +157,7 @@ public function parsingTaxClassesFromTypoScriptWithCountryCodeReturnsCountrySpec ); } - /** - * @test - */ + #[Test] public function parsingTaxClassesFromTypoScriptWithNotConfiguredCountryCodeReturnsFallbackArrayOfTaxClasses() { $settings = [ @@ -249,9 +246,7 @@ public function parsingTaxClassesFromTypoScriptWithNotConfiguredCountryCodeRetur ); } - /** - * @test - */ + #[Test] public function parsingTaxClassesFromTypoScriptWithIntegerZeroAsCalcIsValid() { $settings = [ diff --git a/shell.nix b/shell.nix new file mode 100644 index 00000000..bf524116 --- /dev/null +++ b/shell.nix @@ -0,0 +1,95 @@ +{ + pkgs ? import { } + ,phpVersion ? "php81" +}: + +let + php = pkgs.${phpVersion}.buildEnv { + extensions = { enabled, all }: enabled ++ (with all; [ + xdebug + ]); + + extraConfig = '' + xdebug.mode = debug + memory_limit = 4G + ''; + }; + inherit(pkgs."${phpVersion}Packages") composer; + + projectInstall = pkgs.writeShellApplication { + name = "project-install"; + runtimeInputs = [ + php + composer + ]; + text = '' + composer update --prefer-dist --no-progress + ''; + }; + + projectCgl = pkgs.writeShellApplication { + name = "project-cgl"; + + runtimeInputs = [ + php + ]; + + text = '' + ./.build/bin/php-cs-fixer fix --config=Build/.php-cs-fixer.dist.php -v --dry-run --diff + ''; + }; + + projectCglFix = pkgs.writeShellApplication { + name = "project-cgl-fix"; + + runtimeInputs = [ + php + ]; + + text = '' + ./.build/bin/php-cs-fixer fix --config=Build/.php-cs-fixer.dist.php + ''; + }; + + projectTestUnit = pkgs.writeShellApplication { + name = "project-test-unit"; + runtimeInputs = [ + php + projectInstall + ]; + text = '' + project-install + .build/bin/phpunit -c Build/UnitTests.xml + ''; + }; + + projectTestFunctional = pkgs.writeShellApplication { + name = "project-test-functional"; + runtimeInputs = [ + php + projectInstall + ]; + text = '' + project-install + .build/bin/phpunit -c Build/FunctionalTests.xml + ''; + }; + +in pkgs.mkShell { + name = "TYPO3 Extension cart"; + buildInputs = [ + php + composer + projectInstall + projectCgl + projectCglFix + projectTestUnit + projectTestFunctional + ]; + + shellHook = '' + export PROJECT_ROOT="$(pwd)" + + export typo3DatabaseDriver=pdo_sqlite + ''; +}