From 095bd53223ee9e9d50990ac2b9ef61daa9551048 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Tue, 4 Mar 2025 14:06:10 +0100 Subject: [PATCH] [TASK] Move currency translation to a service Currency conversion is currently very strongly linked to the cart model and the way in which the currency conversion factor is loaded from TypoScript. In order to be able to obtain the conversion factor from other sources, the calculation is carried out by the `CurrencyTranslationService`. This service is instantiated via the `CurrencyTranslationServiceInterface` interface so that a corresponding exchange via DI is possible. The implementation should only be a start and does not yet offer a stable API because the behaviour must remain the same within the published versions. For this reason, the `CurrencyTranslationServiceInterface` is marked as `@internal`. Use is at your own risk! Changes to the service interface must be observed independently in the event of updates! Resolves: #638 --- Classes/Domain/Model/Cart/Cart.php | 14 +++- .../Service/CurrencyTranslationService.php | 24 ++++++ .../CurrencyTranslationServiceInterface.php | 20 +++++ Configuration/Services.yaml | 4 + ...-638-MoveCurrencyTranslationToAService.rst | 31 ++++++++ Documentation/Changelog/11.1/Index.rst | 20 +++++ Documentation/Changelog/Index.rst | 1 + Documentation/guides.xml | 4 +- .../Domain/Model/Cart/CartCouponFixTest.php | 37 +++++---- .../Model/Cart/CartCouponPercentageTest.php | 62 +++++++-------- Tests/Unit/Domain/Model/Cart/CartTest.php | 44 +++++++++-- Tests/Unit/Domain/Model/Cart/ServiceTest.php | 77 +++++++------------ ext_emconf.php | 2 +- 13 files changed, 227 insertions(+), 113 deletions(-) create mode 100644 Classes/Service/CurrencyTranslationService.php create mode 100644 Classes/Service/CurrencyTranslationServiceInterface.php create mode 100644 Documentation/Changelog/11.1/Feature-638-MoveCurrencyTranslationToAService.rst create mode 100644 Documentation/Changelog/11.1/Index.rst diff --git a/Classes/Domain/Model/Cart/Cart.php b/Classes/Domain/Model/Cart/Cart.php index 6efe1f0e..baeb300c 100644 --- a/Classes/Domain/Model/Cart/Cart.php +++ b/Classes/Domain/Model/Cart/Cart.php @@ -11,10 +11,15 @@ * LICENSE file that was distributed with this source code. */ +use Extcode\Cart\Service\CurrencyTranslationServiceInterface; +use TYPO3\CMS\Core\Utility\GeneralUtility; + class Cart implements AdditionalDataInterface { use AdditionalDataTrait; + private ?CurrencyTranslationServiceInterface $currencyTranslationService = null; + protected float $net; protected float $gross; @@ -73,6 +78,8 @@ public function __construct( protected string $currencySign = '€', protected float $currencyTranslation = 1.00 ) { + $this->currencyTranslationService = GeneralUtility::makeInstance(CurrencyTranslationServiceInterface::class); + $this->net = 0.0; $this->gross = 0.0; $this->count = 0; @@ -1078,11 +1085,10 @@ public function setCurrencySign(string $currencySign): void public function translatePrice(?float $price = null): ?float { - if ($price !== null) { - $price /= $this->getCurrencyTranslation(); - return round($price * 100.0) / 100.0; + if (is_null($this->currencyTranslationService)) { + $this->currencyTranslationService = GeneralUtility::makeInstance(CurrencyTranslationServiceInterface::class); } - return null; + return $this->currencyTranslationService->translatePrice($this->getCurrencyTranslation(), $price); } } diff --git a/Classes/Service/CurrencyTranslationService.php b/Classes/Service/CurrencyTranslationService.php new file mode 100644 index 00000000..526392f6 --- /dev/null +++ b/Classes/Service/CurrencyTranslationService.php @@ -0,0 +1,24 @@ +`__ + +Description +=========== + +Currency conversion is currently very strongly linked to the cart model and the +way in which the currency conversion factor is loaded from TypoScript. + +In order to be able to obtain the conversion factor from other sources, the +calculation is carried out by the `CurrencyTranslationService`. This service is +instantiated via the `CurrencyTranslationServiceInterface` interface so that a +corresponding exchange via DI is possible. + +The implementation should only be a start and does not yet offer a stable API +because the behaviour must remain the same within the published versions. For +this reason, the `CurrencyTranslationServiceInterface` is marked as `@internal`. +Use is at your own risk! Changes to the service interface must be observed +independently in the event of updates! + +Impact +====== + +No direct impact. + +.. index:: API diff --git a/Documentation/Changelog/11.1/Index.rst b/Documentation/Changelog/11.1/Index.rst new file mode 100644 index 00000000..c74d42f7 --- /dev/null +++ b/Documentation/Changelog/11.1/Index.rst @@ -0,0 +1,20 @@ +.. include:: ../../Includes.rst.txt + +10.1 Changes +============ + +**Table of contents** + +.. contents:: + :local: + :depth: 1 + +Features +-------- + +.. toctree:: + :maxdepth: 1 + :titlesonly: + :glob: + + Feature-* diff --git a/Documentation/Changelog/Index.rst b/Documentation/Changelog/Index.rst index 02eb050f..23bb0dbf 100644 --- a/Documentation/Changelog/Index.rst +++ b/Documentation/Changelog/Index.rst @@ -10,6 +10,7 @@ ChangeLog :maxdepth: 5 :titlesonly: + 11.1/Index 11.0/Index 10.0/Index 9.4/Index diff --git a/Documentation/guides.xml b/Documentation/guides.xml index 5a663500..0d1fc770 100644 --- a/Documentation/guides.xml +++ b/Documentation/guides.xml @@ -11,8 +11,8 @@ interlink-shortcode="extcode/cart" /> diff --git a/Tests/Unit/Domain/Model/Cart/CartCouponFixTest.php b/Tests/Unit/Domain/Model/Cart/CartCouponFixTest.php index 4b11811d..f8b570a7 100644 --- a/Tests/Unit/Domain/Model/Cart/CartCouponFixTest.php +++ b/Tests/Unit/Domain/Model/Cart/CartCouponFixTest.php @@ -12,8 +12,12 @@ use Extcode\Cart\Domain\Model\Cart\Cart; use Extcode\Cart\Domain\Model\Cart\CartCouponFix; use Extcode\Cart\Domain\Model\Cart\TaxClass; +use Extcode\Cart\Service\CurrencyTranslationService; +use Extcode\Cart\Service\CurrencyTranslationServiceInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\MockObject\MockObject; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; #[CoversClass(CartCouponFix::class)] @@ -178,10 +182,7 @@ public function getGrossReturnsTranslatedDiscount(): void { $currencyTranslation = 2.0; - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getCurrencyTranslation']) - ->setConstructorArgs([[$this->taxClass]]) - ->getMock(); + $cart = $this->createCartMock(['getGross', 'getCurrencyTranslation']); $cart->method('getCurrencyTranslation')->willReturn($currencyTranslation); $this->coupon->setCart($cart); @@ -238,10 +239,7 @@ public function isUsableReturnsTrueIfCartMinPriceIsLessToGivenPrice(): void $discount = 5.00; $cartMinPrice = 9.99; - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([[$this->taxClass]]) - ->getMock(); + $cart = $this->createCartMock(); $cart->method('getGross')->willReturn($gross); $coupon = new CartCouponFix( @@ -267,10 +265,7 @@ public function isUsableReturnsTrueIfCartMinPriceIsEqualToGivenPrice(): void $discount = 5.00; $cartMinPrice = 10.00; - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([[$this->taxClass]]) - ->getMock(); + $cart = $this->createCartMock(); $cart->method('getGross')->willReturn($gross); $coupon = new CartCouponFix( @@ -296,10 +291,7 @@ public function isUsableReturnsFalseIfCartMinPriceIsGreaterToGivenPrice(): void $discount = 5.00; $cartMinPrice = 10.01; - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([[$this->taxClass]]) - ->getMock(); + $cart = $this->createCartMock(); $cart->method('getGross')->willReturn($gross); $coupon = new CartCouponFix( @@ -317,4 +309,17 @@ public function isUsableReturnsFalseIfCartMinPriceIsGreaterToGivenPrice(): void $coupon->isUseable() ); } + + private function createCartMock(array $methods = ['getGross']): Cart|MockObject + { + GeneralUtility::addInstance( + CurrencyTranslationServiceInterface::class, + new CurrencyTranslationService() + ); + + return $this->getMockBuilder(Cart::class) + ->onlyMethods($methods) + ->setConstructorArgs([[$this->taxClass]]) + ->getMock(); + } } diff --git a/Tests/Unit/Domain/Model/Cart/CartCouponPercentageTest.php b/Tests/Unit/Domain/Model/Cart/CartCouponPercentageTest.php index 6b248b5d..1c5dfea7 100644 --- a/Tests/Unit/Domain/Model/Cart/CartCouponPercentageTest.php +++ b/Tests/Unit/Domain/Model/Cart/CartCouponPercentageTest.php @@ -12,8 +12,12 @@ use Extcode\Cart\Domain\Model\Cart\Cart; use Extcode\Cart\Domain\Model\Cart\CartCouponPercentage; use Extcode\Cart\Domain\Model\Cart\TaxClass; +use Extcode\Cart\Service\CurrencyTranslationService; +use Extcode\Cart\Service\CurrencyTranslationServiceInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\MockObject\MockObject; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; #[CoversClass(CartCouponPercentage::class)] @@ -151,10 +155,7 @@ public function getGrossInitiallyReturnsGrossSetDirectlyByConstructor(): void { $taxClass = new TaxClass(1, '19 %', 0.19, 'normal'); - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([[$taxClass]]) - ->getMock(); + $cart = $this->createCartMock(); $cart->method('getGross')->willReturn(0.0); $this->coupon->setCart($cart); @@ -171,10 +172,7 @@ public function getGrossReturnsTranslatedDiscount(): void $taxClass = new TaxClass(1, '19 %', 0.19, 'normal'); $currencyTranslation = 1.0; - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross', 'getCurrencyTranslation']) - ->setConstructorArgs([[$taxClass]]) - ->getMock(); + $cart = $this->createCartMock(['getGross', 'getCurrencyTranslation']); $cart->method('getGross')->willReturn(100.0); $cart->method('getCurrencyTranslation')->willReturn($currencyTranslation); @@ -191,10 +189,7 @@ public function getNetInitiallyReturnsNetSetIndirectlyByConstructor(): void { $taxClass = new TaxClass(1, '19 %', 0.19, 'normal'); - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([[$taxClass]]) - ->getMock(); + $cart = $this->createCartMock(); $cart->method('getGross')->willReturn(0.0); $this->coupon->setCart($cart); @@ -204,10 +199,7 @@ public function getNetInitiallyReturnsNetSetIndirectlyByConstructor(): void $this->coupon->getNet() ); - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross', 'getTaxes']) - ->setConstructorArgs([[$taxClass]]) - ->getMock(); + $cart = $this->createCartMock(['getGross', 'getTaxes']); $cart->method('getGross')->willReturn(100.0); $cart->method('getTaxes')->willReturn([$taxClass->getId() => 19.0]); @@ -242,10 +234,7 @@ public function getTaxesInitiallyReturnsTaxesSetIndirectlyByConstructor(): void { $taxClass = new TaxClass(1, '19 %', 0.19, 'normal'); - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([[$taxClass]]) - ->getMock(); + $cart = $this->createCartMock(); $cart->method('getGross')->willReturn(0.0); $this->coupon->setCart($cart); @@ -255,10 +244,7 @@ public function getTaxesInitiallyReturnsTaxesSetIndirectlyByConstructor(): void $this->coupon->getTaxes() ); - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross', 'getTaxes']) - ->setConstructorArgs([[$taxClass]]) - ->getMock(); + $cart = $this->createCartMock(['getGross', 'getTaxes']); $cart->method('getGross')->willReturn(100.0); $cart->method('getTaxes')->willReturn([$taxClass->getId() => 19.0]); @@ -286,10 +272,7 @@ public function isUsableReturnsTrueIfCartMinPriceIsLessToGivenPrice(): void $discount = 5.00; $cartMinPrice = 9.99; - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([[$this->taxClass]]) - ->getMock(); + $cart = $this->createCartMock(); $cart->method('getGross')->willReturn($gross); $coupon = new CartCouponPercentage( @@ -314,10 +297,7 @@ public function isUsableReturnsTrueIfCartMinPriceIsEqualToGivenPrice(): void $discount = 5.00; $cartMinPrice = 10.00; - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([[$this->taxClass]]) - ->getMock(); + $cart = $this->createCartMock(); $cart->method('getGross')->willReturn($gross); $coupon = new CartCouponPercentage( @@ -342,10 +322,7 @@ public function isUsableReturnsFalseIfCartMinPriceIsGreaterToGivenPrice(): void $discount = 5.00; $cartMinPrice = 10.01; - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([[$this->taxClass]]) - ->getMock(); + $cart = $this->createCartMock(); $cart->method('getGross')->willReturn($gross); $coupon = new CartCouponPercentage( @@ -362,4 +339,17 @@ public function isUsableReturnsFalseIfCartMinPriceIsGreaterToGivenPrice(): void $coupon->isUseable() ); } + + private function createCartMock(array $methods = ['getGross']): Cart|MockObject + { + GeneralUtility::addInstance( + CurrencyTranslationServiceInterface::class, + new CurrencyTranslationService() + ); + + return $this->getMockBuilder(Cart::class) + ->onlyMethods($methods) + ->setConstructorArgs([[$this->taxClass]]) + ->getMock(); + } } diff --git a/Tests/Unit/Domain/Model/Cart/CartTest.php b/Tests/Unit/Domain/Model/Cart/CartTest.php index d9d5c1da..eccb7fdd 100644 --- a/Tests/Unit/Domain/Model/Cart/CartTest.php +++ b/Tests/Unit/Domain/Model/Cart/CartTest.php @@ -14,6 +14,8 @@ use Extcode\Cart\Domain\Model\Cart\ProductFactory; use Extcode\Cart\Domain\Model\Cart\ProductFactoryInterface; use Extcode\Cart\Domain\Model\Cart\TaxClass; +use Extcode\Cart\Service\CurrencyTranslationService; +use Extcode\Cart\Service\CurrencyTranslationServiceInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -52,8 +54,8 @@ public function setUp(): void 3 => $this->freeTaxClass, ]; - $this->grossCart = new Cart($this->taxClasses, false); - $this->netCart = new Cart($this->taxClasses, true); + $this->grossCart = $this->createCart(false); + $this->netCart = $this->createCart(true); } public function tearDown(): void @@ -1335,6 +1337,10 @@ public function getSubtotalGrossReturnsSubtotalGross(): void $price = 100.00; $couponGross = 10.00; + GeneralUtility::addInstance( + CurrencyTranslationServiceInterface::class, + new CurrencyTranslationService() + ); $cart = $this->getMockBuilder(Cart::class) ->onlyMethods(['getCouponGross', 'getCurrencyTranslation']) ->setConstructorArgs([$this->taxClasses]) @@ -1368,6 +1374,10 @@ public function getSubtotalNetReturnsSubtotalNet(): void $couponGross = 10.00; $couponNet = $couponGross / 1.19; + GeneralUtility::addInstance( + CurrencyTranslationServiceInterface::class, + new CurrencyTranslationService() + ); $cart = $this->getMockBuilder(Cart::class) ->onlyMethods(['getCouponNet', 'getCurrencyTranslation']) ->setConstructorArgs([$this->taxClasses]) @@ -1412,7 +1422,11 @@ public function getCurrencyCodeInitiallyReturnsString(): void #[Test] public function constructorSetsCurrencyCode(): void { - $this->grossCart = new Cart( + GeneralUtility::addInstance( + CurrencyTranslationServiceInterface::class, + new CurrencyTranslationService() + ); + $cart = new Cart( $this->taxClasses, false, 'USD', @@ -1422,7 +1436,7 @@ public function constructorSetsCurrencyCode(): void self::assertSame( 'USD', - $this->grossCart->getCurrencyCode() + $cart->getCurrencyCode() ); } @@ -1461,7 +1475,11 @@ public function getCurrencySignInitiallyReturnsString(): void #[Test] public function constructorSetsCurrencySign(): void { - $this->grossCart = new Cart( + GeneralUtility::addInstance( + CurrencyTranslationServiceInterface::class, + new CurrencyTranslationService() + ); + $cart = new Cart( $this->taxClasses, false, 'USD', @@ -1471,7 +1489,7 @@ public function constructorSetsCurrencySign(): void self::assertSame( '$', - $this->grossCart->getCurrencySign() + $cart->getCurrencySign() ); } @@ -1510,6 +1528,10 @@ public function getCurrencyTranslationInitiallyReturnsFloat(): void #[Test] public function constructorSetsCurrencyTranslation(): void { + GeneralUtility::addInstance( + CurrencyTranslationServiceInterface::class, + new CurrencyTranslationService() + ); $cart = new Cart( $this->taxClasses, false, @@ -1581,4 +1603,14 @@ public function translatePriceReturnsCorrectPrice(): void $this->netCart->translatePrice(5.0) ); } + + private function createCart(bool $isNetCart): Cart + { + GeneralUtility::addInstance( + CurrencyTranslationServiceInterface::class, + new CurrencyTranslationService() + ); + + return new Cart($this->taxClasses, $isNetCart); + } } diff --git a/Tests/Unit/Domain/Model/Cart/ServiceTest.php b/Tests/Unit/Domain/Model/Cart/ServiceTest.php index 07601cea..2b8751db 100644 --- a/Tests/Unit/Domain/Model/Cart/ServiceTest.php +++ b/Tests/Unit/Domain/Model/Cart/ServiceTest.php @@ -13,8 +13,12 @@ use Extcode\Cart\Domain\Model\Cart\Product; use Extcode\Cart\Domain\Model\Cart\Service; use Extcode\Cart\Domain\Model\Cart\TaxClass; +use Extcode\Cart\Service\CurrencyTranslationService; +use Extcode\Cart\Service\CurrencyTranslationServiceInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\MockObject\MockObject; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; #[CoversClass(Service::class)] @@ -106,30 +110,21 @@ public function isAvailableWithCartGrossInRangeReturnsTrue(): void $config ); - $cart1 = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([$this->taxClasses]) - ->getMock(); + $cart1 = $this->createCartMock(); $cart1->method('getGross')->willReturn(20.00); $service->setCart($cart1); self::assertTrue( $service->isAvailable() ); - $cart2 = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([$this->taxClasses]) - ->getMock(); + $cart2 = $this->createCartMock(); $cart2->method('getGross')->willReturn(50.00); $service->setCart($cart2); self::assertTrue( $service->isAvailable() ); - $cart3 = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([$this->taxClasses]) - ->getMock(); + $cart3 = $this->createCartMock(); $cart3->method('getGross')->willReturn(100.00); $service->setCart($cart3); self::assertTrue( @@ -156,10 +151,7 @@ public function isAvailableWithCartGrossBelowRangeReturnsFalse(): void $config ); - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([$this->taxClasses]) - ->getMock(); + $cart = $this->createCartMock(); $cart->method('getGross')->willReturn(19.99); $service->setCart($cart); @@ -188,10 +180,7 @@ public function isAvailableWithCartGrossAboveRangeReturnsFalse(): void $config ); - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([$this->taxClasses]) - ->getMock(); + $cart = $this->createCartMock(); $cart->method('getGross')->willReturn(100.01); $service->setCart($cart); @@ -280,30 +269,21 @@ public function isFreeWithCartGrossInRangeReturnsTrue(): void $config ); - $cart1 = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([$this->taxClasses]) - ->getMock(); + $cart1 = $this->createCartMock(); $cart1->method('getGross')->willReturn(20.00); $service->setCart($cart1); self::assertTrue( $service->isFree() ); - $cart2 = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([$this->taxClasses]) - ->getMock(); + $cart2 = $this->createCartMock(); $cart2->method('getGross')->willReturn(50.00); $service->setCart($cart2); self::assertTrue( $service->isFree() ); - $cart3 = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([$this->taxClasses]) - ->getMock(); + $cart3 = $this->createCartMock(); $cart3->method('getGross')->willReturn(100.00); $service->setCart($cart3); self::assertTrue( @@ -330,10 +310,7 @@ public function isFreeWithCartGrossBelowRangeReturnsFalse(): void $config ); - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([$this->taxClasses]) - ->getMock(); + $cart = $this->createCartMock(); $cart->method('getGross')->willReturn(19.99); $service->setCart($cart); @@ -362,10 +339,7 @@ public function isFreeWithCartGrossAboveRangeReturnsFalse(): void $config ); - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([$this->taxClasses]) - ->getMock(); + $cart = $this->createCartMock(); $cart->method('getGross')->willReturn(100.01); $service->setCart($cart); @@ -377,10 +351,7 @@ public function isFreeWithCartGrossAboveRangeReturnsFalse(): void #[Test] public function taxClassIdsGreaterZeroReturnsTaxClass(): void { - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([$this->taxClasses]) - ->getMock(); + $cart = $this->createCartMock(); $cart->method('getGross')->willReturn(20.00); $config = [ @@ -431,10 +402,7 @@ public function forTaxClassIdMinusOneTheHighestUsedTaxRateWillBeUsed(): void $config ); - $cart = $this->getMockBuilder(Cart::class) - ->onlyMethods(['getGross']) - ->setConstructorArgs([$this->taxClasses]) - ->getMock(); + $cart = $this->createCartMock(); $cart->method('getGross')->willReturn(100.00); $firstCartProductPrice = 10.00; @@ -496,4 +464,17 @@ public function forTaxClassIdMinusTwoReturnsPseudoTaxClassWithIdMinusTwo(): void $service->getTaxClass()->getId() ); } + + private function createCartMock(array $methods = ['getGross']): Cart|MockObject + { + GeneralUtility::addInstance( + CurrencyTranslationServiceInterface::class, + new CurrencyTranslationService() + ); + + return $this->getMockBuilder(Cart::class) + ->onlyMethods($methods) + ->setConstructorArgs([$this->taxClasses]) + ->getMock(); + } } diff --git a/ext_emconf.php b/ext_emconf.php index cc05e046..6a89ba44 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -4,7 +4,7 @@ 'title' => 'Cart', 'description' => 'Shopping Cart(s) for TYPO3', 'category' => 'plugin', - 'version' => '11.0.1', + 'version' => '11.1.0', 'state' => 'stable', 'author' => 'Daniel Gohlke', 'author_email' => 'ext@extco.de',