diff --git a/app/code/Magento/Swatches/Test/Unit/Block/Product/Renderer/ConfigurableTest.php b/app/code/Magento/Swatches/Test/Unit/Block/Product/Renderer/ConfigurableTest.php index 025e6fba24504..7bd34ee5905e8 100644 --- a/app/code/Magento/Swatches/Test/Unit/Block/Product/Renderer/ConfigurableTest.php +++ b/app/code/Magento/Swatches/Test/Unit/Block/Product/Renderer/ConfigurableTest.php @@ -7,9 +7,12 @@ use Magento\Swatches\Block\Product\Renderer\Configurable; use Magento\Swatches\Model\Swatch; +use Magento\Swatches\Model\SwatchAttributesProvider; +use Magento\Framework\Locale\Format; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.TooManyFields) */ class ConfigurableTest extends \PHPUnit_Framework_TestCase { @@ -58,6 +61,12 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject */ private $urlBuilder; + /** @var \Magento\Framework\Locale\Format|\PHPUnit_Framework_MockObject_MockObject */ + private $localeFormat; + + /** @var \Magento\Swatches\Model\SwatchAttributesProvider |\PHPUnit_Framework_MockObject_MockObject */ + private $swatchAttributesProvider; + protected function setUp() { $this->arrayUtils = $this->getMock('\Magento\Framework\Stdlib\ArrayUtils', [], [], '', false); @@ -68,6 +77,8 @@ protected function setUp() $this->catalogProduct = $this->getMock('\Magento\Catalog\Helper\Product', [], [], '', false); $this->currentCustomer = $this->getMock('\Magento\Customer\Helper\Session\CurrentCustomer', [], [], '', false); $this->priceCurrency = $this->getMock('\Magento\Framework\Pricing\PriceCurrencyInterface', [], [], '', false); + $this->swatchAttributesProvider = $this->getMock(SwatchAttributesProvider::class, [], [], '', false); + $this->localeFormat = $this->getMock(Format::class, [], [], '', false); $this->configurableAttributeData = $this->getMock( 'Magento\ConfigurableProduct\Model\ConfigurableAttributeData', [], @@ -98,6 +109,8 @@ protected function setUp() 'priceCurrency' => $this->priceCurrency, 'configurableAttributeData' => $this->configurableAttributeData, 'data' => [], + 'swatchAttributesProvider' => $this->swatchAttributesProvider, + 'format' => $this->localeFormat ] ); } @@ -154,9 +167,11 @@ public function testSetIsProductListingContext() private function prepareGetJsonSwatchConfig() { $product1 = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $product1->expects($this->atLeastOnce())->method('isSaleable')->willReturn(true); $product1->expects($this->atLeastOnce())->method('getData')->with('code')->willReturn(1); $product2 = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $product2->expects($this->atLeastOnce())->method('isSaleable')->willReturn(true); $product2->expects($this->atLeastOnce())->method('getData')->with('code')->willReturn(3); $simpleProducts = [$product1, $product2]; @@ -167,7 +182,7 @@ private function prepareGetJsonSwatchConfig() '', false ); - $configurableType->expects($this->atLeastOnce())->method('getSalableUsedProducts')->with($this->product, null) + $configurableType->expects($this->atLeastOnce())->method('getUsedProducts')->with($this->product, null) ->willReturn($simpleProducts); $this->product->expects($this->any())->method('getTypeInstance')->willReturn($configurableType); diff --git a/app/code/Magento/Swatches/Test/Unit/Block/Product/Renderer/Listing/ConfigurableTest.php b/app/code/Magento/Swatches/Test/Unit/Block/Product/Renderer/Listing/ConfigurableTest.php index 8a8580b74467d..2f55ca5d2537d 100644 --- a/app/code/Magento/Swatches/Test/Unit/Block/Product/Renderer/Listing/ConfigurableTest.php +++ b/app/code/Magento/Swatches/Test/Unit/Block/Product/Renderer/Listing/ConfigurableTest.php @@ -117,7 +117,10 @@ public function setUp() '', false ); - $this->product = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false); + $this->product = self::getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods(['getTypeInstance', 'getUsedProducts', 'isSaleable']) + ->disableOriginalConstructor() + ->getMock(); $this->typeInstance = $this->getMock( \Magento\Catalog\Model\Product\Type\AbstractType::class, [], @@ -203,7 +206,7 @@ public function setUp() } /** - * @covers Magento\Swatches\Block\Product\Renderer\Listing\Configurable::getSwatchAttributesData + * @covers \Magento\Swatches\Block\Product\Renderer\Listing\Configurable::getSwatchAttributesData */ public function testGetJsonSwatchConfigWithoutSwatches() { @@ -219,7 +222,7 @@ public function testGetJsonSwatchConfigWithoutSwatches() } /** - * @covers Magento\Swatches\Block\Product\Renderer\Listing\Configurable::getSwatchAttributesData + * @covers \Magento\Swatches\Block\Product\Renderer\Listing\Configurable::getSwatchAttributesData */ public function testGetJsonSwatchNotUsedInProductListing() { @@ -242,7 +245,7 @@ public function testGetJsonSwatchNotUsedInProductListing() } /** - * @covers Magento\Swatches\Block\Product\Renderer\Listing\Configurable::getSwatchAttributesData + * @covers \Magento\Swatches\Block\Product\Renderer\Listing\Configurable::getSwatchAttributesData */ public function testGetJsonSwatchUsedInProductListing() { @@ -277,15 +280,14 @@ public function testGetJsonSwatchUsedInProductListing() $this->configurable->getJsonSwatchConfig(); } - /** - * @return void - */ private function prepareGetJsonSwatchConfig() { $product1 = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false); + $product1->expects($this->atLeastOnce())->method('isSaleable')->willReturn(true); $product1->expects($this->any())->method('getData')->with('code')->willReturn(1); $product2 = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false); + $product2->expects($this->atLeastOnce())->method('isSaleable')->willReturn(true); $product2->expects($this->any())->method('getData')->with('code')->willReturn(3); $simpleProducts = [$product1, $product2]; @@ -296,10 +298,23 @@ private function prepareGetJsonSwatchConfig() '', false ); - $configurableType->expects($this->atLeastOnce())->method('getSalableUsedProducts') + $configurableType->expects($this->any())->method('getSalableUsedProducts') ->with($this->product, null) ->willReturn($simpleProducts); - $this->product->expects($this->any())->method('getTypeInstance')->willReturn($configurableType); + $productCollection = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Collection::class) + ->disableOriginalConstructor() + ->setMethods(['getIterator']) + ->getMock(); + + $configurableType->expects($this->any())->method('getUsedProducts') + ->with($this->product, null) + ->willReturn($productCollection); + + $productCollection->expects($this->once())->method('getIterator') + ->willReturn(new \ArrayIterator($simpleProducts)); + + $this->product->expects($this->any())->method('getTypeInstance') + ->willReturn($configurableType); $productAttribute1 = $this->getMock( \Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class,