Skip to content

Commit 4ee6c76

Browse files
committed
MAGETWO-48489: Fix Unit tests
- Fixed unit tests for Configurable Product
1 parent b93b095 commit 4ee6c76

File tree

14 files changed

+584
-120
lines changed

14 files changed

+584
-120
lines changed

app/code/Magento/ConfigurableProduct/Model/Plugin/AroundProductRepositorySave.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function aroundSave(
7272
$configurableLinks = (array) $extensionAttributes->getConfigurableProductLinks();
7373
$configurableOptions = (array) $extensionAttributes->getConfigurableProductOptions();
7474

75-
if (empty($configurableLinks) && empty($extensionAttributes)) {
75+
if (empty($configurableLinks) && empty($configurableOptions)) {
7676
return $result;
7777
}
7878

@@ -111,7 +111,7 @@ private function validateProductLinks(array $attributeCodes, array $linkIds)
111111
}
112112
if (isset($valueMap[$valueKey])) {
113113
throw new InputException(
114-
__('Products "%1" and %2 have the same set of attribute values.', $productId, $valueMap[$valueKey])
114+
__('Products "%1" and "%2" have the same set of attribute values.', $productId, $valueMap[$valueKey])
115115
);
116116
}
117117
$valueMap[$valueKey] = $productId;

app/code/Magento/ConfigurableProduct/Model/Product/SaveHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public function __construct(
4343
OptionRepositoryInterface $optionRepository,
4444
ProductAttributeRepositoryInterface $productAttributeRepository
4545
) {
46+
$this->resourceModel = $resourceModel;
4647
$this->optionRepository = $optionRepository;
4748
$this->productAttributeRepository = $productAttributeRepository;
48-
$this->resourceModel = $resourceModel;
4949
}
5050

5151
/**

app/code/Magento/ConfigurableProduct/Test/Unit/Controller/Adminhtml/Product/Initialization/Helper/Plugin/ConfigurableTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\ConfigurableProduct\Helper\Product\Options\Factory;
1212
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableProduct;
1313
use Magento\ConfigurableProduct\Model\Product\VariationHandler;
14-
use Magento\ConfigurableProduct\Test\Unit\Model\Product\PaymentExtensionAttributes;
14+
use Magento\ConfigurableProduct\Test\Unit\Model\Product\ProductExtensionAttributes;
1515
use Magento\Framework\App\Request\Http;
1616
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1717

@@ -123,7 +123,7 @@ public function testAfterInitializeWithAttributesAndVariations()
123123
->method('getParam')
124124
->willReturnMap($paramValueMap);
125125

126-
$extensionAttributes = $this->getMockBuilder(PaymentExtensionAttributes::class)
126+
$extensionAttributes = $this->getMockBuilder(ProductExtensionAttributes::class)
127127
->disableOriginalConstructor()
128128
->setMethods(['setConfigurableProductOptions', 'setConfigurableProductLinks'])
129129
->getMockForAbstractClass();
@@ -188,7 +188,7 @@ public function testAfterInitializeWithAttributesAndWithoutVariations()
188188
->method('getParam')
189189
->willReturnMap($paramValueMap);
190190

191-
$extensionAttributes = $this->getMockBuilder(PaymentExtensionAttributes::class)
191+
$extensionAttributes = $this->getMockBuilder(ProductExtensionAttributes::class)
192192
->disableOriginalConstructor()
193193
->setMethods(['setConfigurableProductOptions', 'setConfigurableProductLinks'])
194194
->getMockForAbstractClass();
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ConfigurableProduct\Test\Unit\Helper\Product\Options;
7+
8+
use Magento\Catalog\Model\Product;
9+
use Magento\ConfigurableProduct\Api\Data\OptionValueInterface;
10+
use Magento\ConfigurableProduct\Api\Data\OptionValueInterfaceFactory;
11+
use Magento\ConfigurableProduct\Helper\Product\Options\Loader;
12+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
13+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute;
14+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
15+
16+
/**
17+
* Class LoaderTest
18+
*/
19+
class LoaderTest extends \PHPUnit_Framework_TestCase
20+
{
21+
/**
22+
* @var OptionValueInterfaceFactory|MockObject
23+
*/
24+
private $optionValueFactory;
25+
26+
/**
27+
* @var Product|MockObject
28+
*/
29+
private $product;
30+
31+
/**
32+
* @var Configurable|MockObject
33+
*/
34+
private $configurable;
35+
36+
/**
37+
* @var Loader
38+
*/
39+
private $loader;
40+
41+
protected function setUp()
42+
{
43+
$this->optionValueFactory = $this->getMockBuilder(OptionValueInterfaceFactory::class)
44+
->disableOriginalConstructor()
45+
->setMethods(['create'])
46+
->getMock();
47+
48+
$this->product = $this->getMockBuilder(Product::class)
49+
->disableOriginalConstructor()
50+
->setMethods(['getTypeInstance'])
51+
->getMock();
52+
53+
$this->configurable = $this->getMockBuilder(Configurable::class)
54+
->disableOriginalConstructor()
55+
->setMethods(['getConfigurableAttributes'])
56+
->getMock();
57+
58+
$this->loader = new Loader($this->optionValueFactory);
59+
}
60+
61+
/**
62+
* @covers \Magento\ConfigurableProduct\Helper\Product\Options\Loader::load
63+
*/
64+
public function testLoad()
65+
{
66+
$option = [
67+
'value_index' => 23
68+
];
69+
70+
$this->product->expects(static::once())
71+
->method('getTypeInstance')
72+
->willReturn($this->configurable);
73+
74+
$attribute = $this->getMockBuilder(Attribute::class)
75+
->disableOriginalConstructor()
76+
->setMethods(['getOptions', 'setValues'])
77+
->getMock();
78+
$attributes = [$attribute];
79+
80+
$this->configurable->expects(static::once())
81+
->method('getConfigurableAttributes')
82+
->with($this->product)
83+
->willReturn($attributes);
84+
85+
$attribute->expects(static::once())
86+
->method('getOptions')
87+
->willReturn([$option]);
88+
89+
$optionValue = $this->getMockForAbstractClass(OptionValueInterface::class);
90+
$this->optionValueFactory->expects(static::once())
91+
->method('create')
92+
->willReturn($optionValue);
93+
$optionValue->expects(static::once())
94+
->method('setValueIndex')
95+
->with($option['value_index']);
96+
97+
$attribute->expects(static::once())
98+
->method('setValues')
99+
->with([$optionValue]);
100+
101+
$options = $this->loader->load($this->product);
102+
static::assertSame([$attribute], $options);
103+
}
104+
}

app/code/Magento/ConfigurableProduct/Test/Unit/Model/OptionRepositoryTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ public function testDeleteCantSaveProducts()
203203
public function testDeleteCantDeleteOption()
204204
{
205205
$entityId = 3;
206-
$optionMock = $this->getMock(OptionInterface::class);
206+
$optionMock = $this->getMockBuilder(Attribute::class)
207+
->disableOriginalConstructor()
208+
->getMock();
207209

208210
$optionMock->expects(self::once())
209211
->method('getId')
@@ -227,7 +229,7 @@ public function testDeleteCantDeleteOption()
227229
->method('saveProducts')
228230
->with($this->productMock);
229231

230-
$this->optionResource->expects(self::never())
232+
$this->optionResource->expects(self::once())
231233
->method('delete')
232234
->with($optionMock)
233235
->willThrowException(new \Exception());

0 commit comments

Comments
 (0)