Skip to content

Commit

Permalink
[TASK] Move test to abstract class testing
Browse files Browse the repository at this point in the history
Relates: #508
  • Loading branch information
extcode committed Jun 7, 2024
1 parent 5044241 commit 6000c3f
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -25,9 +27,7 @@ public function setUp(): void
parent::setUp();
}

/**
* @test
*/
#[Test]
public function getTypePluginSettingsReturnsTypeCountrySettings()
{
$type = 'payments';
Expand Down Expand Up @@ -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');
Expand All @@ -112,9 +112,7 @@ public function getTypePluginSettingsReturnsTypeCountrySettings()
);
}

/**
* @test
*/
#[Test]
public function getTypeZonePluginSettingsReturnsTypeZoneSettings()
{
$type = 'payments';
Expand Down Expand Up @@ -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');
Expand Down
19 changes: 7 additions & 12 deletions Tests/Functional/Service/TaxClassServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,9 +32,7 @@ public function setUp(): void
);
}

/**
* @test
*/
#[Test]
public function parsingTaxClassesFromTypoScriptWithoutCountryCodeReturnsDirectlyConfiguredArrayOfTaxClasses()
{
$settings = [
Expand Down Expand Up @@ -84,9 +85,7 @@ public function parsingTaxClassesFromTypoScriptWithoutCountryCodeReturnsDirectly
);
}

/**
* @test
*/
#[Test]
public function parsingTaxClassesFromTypoScriptWithCountryCodeReturnsCountrySpecificArrayOfTaxClasses()
{
$settings = [
Expand Down Expand Up @@ -158,9 +157,7 @@ public function parsingTaxClassesFromTypoScriptWithCountryCodeReturnsCountrySpec
);
}

/**
* @test
*/
#[Test]
public function parsingTaxClassesFromTypoScriptWithNotConfiguredCountryCodeReturnsFallbackArrayOfTaxClasses()
{
$settings = [
Expand Down Expand Up @@ -249,9 +246,7 @@ public function parsingTaxClassesFromTypoScriptWithNotConfiguredCountryCodeRetur
);
}

/**
* @test
*/
#[Test]
public function parsingTaxClassesFromTypoScriptWithIntegerZeroAsCalcIsValid()
{
$settings = [
Expand Down
95 changes: 95 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
pkgs ? import <nixpkgs> { }
,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
'';
}

0 comments on commit 6000c3f

Please sign in to comment.