From 30967b7d3f0e697fea939a5f4a7268892476b71e Mon Sep 17 00:00:00 2001 From: Sergey Semenov Date: Wed, 3 May 2017 15:53:58 +0300 Subject: [PATCH] MAGETWO-47017: [Github] Add Configurable Product To Cart from Category Page #2574 #5850 #5882 #6572 #5558 #4184 --- .../Block/Product/View/Type/Configurable.php | 1 + .../Product/View/Type/ConfigurableTest.php | 89 +++++++++++++------ 2 files changed, 61 insertions(+), 29 deletions(-) diff --git a/app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php b/app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php index 03e4215212724..30ab875a353be 100644 --- a/app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php @@ -77,6 +77,7 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView * @param ConfigurableAttributeData $configurableAttributeData * @param array $data * @param Format|null $localeFormat + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( \Magento\Catalog\Block\Product\Context $context, diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Block/Product/View/Type/ConfigurableTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Block/Product/View/Type/ConfigurableTest.php index 3d027eb90d912..c89400a0e5d6e 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Block/Product/View/Type/ConfigurableTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Block/Product/View/Type/ConfigurableTest.php @@ -5,6 +5,9 @@ */ namespace Magento\ConfigurableProduct\Test\Unit\Block\Product\View\Type; +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class ConfigurableTestTest extends \PHPUnit_Framework_TestCase { /** @@ -128,18 +131,7 @@ public function testGetJsonConfig() $priceQty = 1; $percentage = 10; - $amountMock = $this->getMockBuilder(\Magento\Framework\Pricing\Amount\AmountInterface::class) - ->setMethods([ - 'getValue', - 'getBaseAmount', - ]) - ->getMockForAbstractClass(); - $amountMock->expects($this->any()) - ->method('getValue') - ->willReturn($amount); - $amountMock->expects($this->any()) - ->method('getBaseAmount') - ->willReturn($amount); + $amountMock = $this->getAmountMock($amount); $priceMock = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class) ->setMethods([ @@ -150,23 +142,7 @@ public function testGetJsonConfig() ->method('getAmount') ->willReturn($amountMock); - $tierPrice = [ - 'price_qty' => $priceQty, - 'price' => $amountMock, - ]; - - $tierPriceMock = $this->getMockBuilder(\Magento\Catalog\Pricing\Price\TierPriceInterface::class) - ->setMethods([ - 'getTierPriceList', - 'getSavePercent', - ]) - ->getMockForAbstractClass(); - $tierPriceMock->expects($this->any()) - ->method('getTierPriceList') - ->willReturn([$tierPrice]); - $tierPriceMock->expects($this->any()) - ->method('getSavePercent') - ->willReturn($percentage); + $tierPriceMock = $this->getTierPriceMock($amountMock, $priceQty, $percentage); $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) ->disableOriginalConstructor() @@ -368,4 +344,59 @@ protected function mockContextObject() ->method('getRegistry') ->willReturn($this->registry); } + + /** + * Retrieve mock of \Magento\Framework\Pricing\Amount\AmountInterface object + * + * @param float $amount + * @return \PHPUnit_Framework_MockObject_MockObject + */ + protected function getAmountMock($amount): \PHPUnit_Framework_MockObject_MockObject + { + $amountMock = $this->getMockBuilder(\Magento\Framework\Pricing\Amount\AmountInterface::class) + ->setMethods([ + 'getValue', + 'getBaseAmount', + ]) + ->getMockForAbstractClass(); + $amountMock->expects($this->any()) + ->method('getValue') + ->willReturn($amount); + $amountMock->expects($this->any()) + ->method('getBaseAmount') + ->willReturn($amount); + + return $amountMock; + } + + /** + * Retrieve mock of \Magento\Catalog\Pricing\Price\TierPriceInterface object + * + * @param \PHPUnit_Framework_MockObject_MockObject $amountMock + * @param float $priceQty + * @param int $percentage + * @return \PHPUnit_Framework_MockObject_MockObject + */ + protected function getTierPriceMock(\PHPUnit_Framework_MockObject_MockObject $amountMock, $priceQty, $percentage) + { + $tierPrice = [ + 'price_qty' => $priceQty, + 'price' => $amountMock, + ]; + + $tierPriceMock = $this->getMockBuilder(\Magento\Catalog\Pricing\Price\TierPriceInterface::class) + ->setMethods([ + 'getTierPriceList', + 'getSavePercent', + ]) + ->getMockForAbstractClass(); + $tierPriceMock->expects($this->any()) + ->method('getTierPriceList') + ->willReturn([$tierPrice]); + $tierPriceMock->expects($this->any()) + ->method('getSavePercent') + ->willReturn($percentage); + + return $tierPriceMock; + } }