Skip to content

Commit 5a01fe1

Browse files
committed
Merge remote-tracking branch 'epam/MAGETWO-54708-PR' into PRS
2 parents 9c1568e + 23488cf commit 5a01fe1

File tree

4 files changed

+124
-46
lines changed

4 files changed

+124
-46
lines changed

setup/src/Magento/Setup/Fixtures/EavVariationsFixture.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,17 @@ public function introduceParamLabels()
114114
*/
115115
private function generateAttribute($optionCount)
116116
{
117-
$stores = $this->storeManager->getStores();
118-
$storeViewsCount = count($stores);
117+
$storeIds = array_keys($this->storeManager->getStores(true));
119118
$options = [];
120119

121120
for ($option = 1; $option <= $optionCount; $option++) {
122121
$options['order']['option_' . $option] = $option;
123-
$options['value']['option_' . $option] = array_fill(0, $storeViewsCount + 1, 'option ' . $option);
122+
$options['value']['option_' . $option] = array_fill_keys($storeIds, 'option ' . $option);
124123
$options['delete']['option_' . $option] = '';
125124
}
126125

127126
$data = [
128-
'frontend_label' => array_fill(0, $storeViewsCount + 1, 'configurable variations'),
127+
'frontend_label' => array_fill_keys($storeIds, 'configurable variations'),
129128
'frontend_input' => 'select',
130129
'is_required' => '0',
131130
'option' => $options,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Setup\Model\FixtureGenerator;
8+
9+
/**
10+
* Class provides information about MySQL auto_increment configuration setting.
11+
*/
12+
class AutoIncrement
13+
{
14+
/**
15+
* @var \Magento\Framework\App\ResourceConnection
16+
*/
17+
private $resource;
18+
19+
/**
20+
* @var int
21+
*/
22+
private $incrementValue;
23+
24+
/**
25+
* @param \Magento\Framework\App\ResourceConnection $resource
26+
*/
27+
public function __construct(\Magento\Framework\App\ResourceConnection $resource)
28+
{
29+
$this->resource = $resource;
30+
}
31+
32+
/**
33+
* Get value of auto_increment_increment variable.
34+
*
35+
* @return int
36+
*/
37+
public function getIncrement()
38+
{
39+
if ($this->incrementValue === null) {
40+
$increment = $this->resource->getConnection()->fetchRow('SHOW VARIABLES LIKE "auto_increment_increment"');
41+
$this->incrementValue = !empty($increment['Value']) ? (int)$increment['Value'] : 1;
42+
}
43+
return $this->incrementValue;
44+
}
45+
}

setup/src/Magento/Setup/Model/FixtureGenerator/ConfigurableProductGenerator.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,22 @@ class ConfigurableProductGenerator
2727
*/
2828
private $productGeneratorFactory;
2929

30+
/**
31+
* @var AutoIncrement
32+
*/
33+
private $autoIncrement;
34+
3035
/**
3136
* @param ProductGeneratorFactory $productGeneratorFactory
37+
* @param AutoIncrement $autoIncrement
3238
*/
33-
public function __construct(ProductGeneratorFactory $productGeneratorFactory)
34-
{
39+
public function __construct(
40+
ProductGeneratorFactory $productGeneratorFactory,
41+
AutoIncrement $autoIncrement
42+
) {
3543
$this->productGeneratorFactory = $productGeneratorFactory;
44+
$this->autoIncrement = $autoIncrement;
45+
3646
}
3747

3848
/**
@@ -101,7 +111,8 @@ public function generate($products, $fixtureMap)
101111
*/
102112
private function generateSuperAttributeId($superAttributeId, $entityNumber, array $fixture)
103113
{
104-
return $superAttributeId + $entityNumber * $fixture['_attributes_count'] + $fixture['_attributes_count'];
114+
return $superAttributeId + ($entityNumber + 1) * $fixture['_attributes_count']
115+
* $this->autoIncrement->getIncrement();
105116
}
106117

107118
/**

setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php

Lines changed: 62 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
use Magento\Setup\Fixtures\FixtureModel;
1616
use Magento\Store\Model\StoreManager;
1717

18+
/**
19+
* Unit test for \Magento\Setup\Fixtures\EavVariationsFixture.
20+
*/
1821
class EavVariationsFixtureTest extends \PHPUnit_Framework_TestCase
1922
{
2023
/**
21-
* @var \PHPUnit_Framework_MockObject_MockObject|FixtureModel
24+
* @var FixtureModel|\PHPUnit_Framework_MockObject_MockObject
2225
*/
2326
private $fixtureModelMock;
2427

@@ -28,22 +31,22 @@ class EavVariationsFixtureTest extends \PHPUnit_Framework_TestCase
2831
private $model;
2932

3033
/**
31-
* @var \PHPUnit_Framework_MockObject_MockObject
34+
* @var StoreManager|\PHPUnit_Framework_MockObject_MockObject
3235
*/
3336
private $storeManagerMock;
3437

3538
/**
36-
* @var \PHPUnit_Framework_MockObject_MockObject
39+
* @var Set|\PHPUnit_Framework_MockObject_MockObject
3740
*/
3841
private $attributeSetMock;
3942

4043
/**
41-
* @var \PHPUnit_Framework_MockObject_MockObject
44+
* @var CacheInterface|\PHPUnit_Framework_MockObject_MockObject
4245
*/
4346
private $cacheMock;
4447

4548
/**
46-
* @var \PHPUnit_Framework_MockObject_MockObject
49+
* @var Config|\PHPUnit_Framework_MockObject_MockObject
4750
*/
4851
private $eavConfigMock;
4952

@@ -52,14 +55,24 @@ class EavVariationsFixtureTest extends \PHPUnit_Framework_TestCase
5255
*/
5356
private $attributeFactoryMock;
5457

58+
/**
59+
* @inheritdoc
60+
*/
5561
public function setUp()
5662
{
57-
$this->fixtureModelMock = $this->getMock(FixtureModel::class, [], [], '', false);
58-
$this->eavConfigMock = $this->getMock(Config::class, [], [], '', false);
59-
$this->storeManagerMock = $this->getMock(StoreManager::class, [], [], '', false);
60-
$this->attributeSetMock = $this->getMock(Set::class, [], [], '', false);
61-
$this->cacheMock = $this->getMock(CacheInterface::class, [], [], '', false);
62-
$this->attributeFactoryMock = $this->getMock(AttributeFactory::class, ['create'], [], '', false);
63+
$this->fixtureModelMock = $this->getMockBuilder(FixtureModel::class)
64+
->disableOriginalConstructor()->getMock();
65+
$this->eavConfigMock = $this->getMockBuilder(Config::class)
66+
->disableOriginalConstructor()->getMock();
67+
$this->storeManagerMock = $this->getMockBuilder(StoreManager::class)
68+
->disableOriginalConstructor()->getMock();
69+
$this->attributeSetMock = $this->getMockBuilder(Set::class)
70+
->disableOriginalConstructor()->getMock();
71+
$this->cacheMock = $this->getMockBuilder(CacheInterface::class)
72+
->disableOriginalConstructor()->getMock();
73+
$this->attributeFactoryMock = $this->getMockBuilder(AttributeFactory::class)
74+
->setMethods(['create'])
75+
->disableOriginalConstructor()->getMock();
6376

6477
$this->model = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject(
6578
EavVariationsFixture::class,
@@ -74,24 +87,32 @@ public function setUp()
7487
);
7588
}
7689

77-
public function testDoNotExecuteWhenAttributeAleadyExist()
90+
/**
91+
* Test for execute method when attribute already exists.
92+
*
93+
* @return void
94+
*/
95+
public function testDoNotExecuteWhenAttributeAlreadyExist()
7896
{
79-
$this->fixtureModelMock
80-
->expects($this->any())
81-
->method('getValue')
82-
->with('configurable_products', [])
83-
->willReturn(10);
97+
$this->fixtureModelMock->expects($this->once())
98+
->method('getValue')->with('configurable_products', [])->willReturn(10);
8499
$this->eavConfigMock->expects($this->once())->method('getEntityAttributeCodes')
85100
->willReturn(['configurable_variation']);
86101
$this->attributeFactoryMock->expects($this->never())->method('create');
87102

88103
$this->model->execute();
89104
}
90105

106+
/**
107+
* Test for execute method.
108+
*
109+
* @return void
110+
*/
91111
public function testExecute()
92112
{
93-
$this->eavConfigMock->expects($this->once())->method('getEntityAttributeCodes')
94-
->willReturn(['attr1', 'attr2']);
113+
$storeId = 5;
114+
$this->eavConfigMock->expects($this->once())
115+
->method('getEntityAttributeCodes')->willReturn(['attr1', 'attr2']);
95116
$this->fixtureModelMock
96117
->expects($this->any())
97118
->method('getValue')
@@ -100,42 +121,33 @@ public function testExecute()
100121
['configurable_products_variation', 3, 1],
101122
]);
102123

103-
$storeMock = $this->getMock(\Magento\Store\Model\Store::class, [], [], '', false);
104-
$this->storeManagerMock->expects($this->once())
105-
->method('getStores')
106-
->will($this->returnValue([$storeMock]));
107-
124+
$storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
125+
->disableOriginalConstructor()->getMock();
126+
$this->storeManagerMock->expects($this->once())->method('getStores')->willReturn([$storeId => $storeMock]);
108127
$this->attributeSetMock->expects($this->once())->method('load')->willReturnSelf();
109-
$this->attributeSetMock->expects($this->once())
110-
->method('getDefaultGroupId')
111-
->will($this->returnValue(2));
128+
$this->attributeSetMock->expects($this->once())->method('getDefaultGroupId')->willReturn(2);
112129

113130
$attributeMock = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class)
114131
->setMethods([
115132
'setAttributeSetId',
116133
'setAttributeGroupId',
117134
'save',
118-
])->disableOriginalConstructor()
119-
->getMock();
120-
$attributeMock->expects($this->exactly(2))
121-
->method('setAttributeSetId')
122-
->willReturnSelf();
123-
$attributeMock->expects($this->once())
124-
->method('setAttributeGroupId')
125-
->willReturnSelf();
135+
])
136+
->disableOriginalConstructor()->getMock();
137+
$attributeMock->expects($this->exactly(2))->method('setAttributeSetId')->willReturnSelf();
138+
$attributeMock->expects($this->once())->method('setAttributeGroupId')->willReturnSelf();
126139
$this->attributeFactoryMock->expects($this->once())->method('create')
127140
->with(
128141
[
129142
'data' => [
130143
'frontend_label' => [
131-
'configurable variations',
132-
'configurable variations',
144+
$storeId => 'configurable variations',
133145
],
134146
'frontend_input' => 'select',
135147
'is_required' => '0',
136148
'option' => [
137149
'order' => ['option_1' => 1],
138-
'value' => ['option_1' => ['option 1', 'option 1']],
150+
'value' => ['option_1' => [$storeId => 'option 1']],
139151
'delete' => ['option_1' => ''],
140152
],
141153
'default' => ['option_0'],
@@ -172,16 +184,27 @@ public function testExecute()
172184
]
173185
]
174186
)->willReturn($attributeMock);
175-
$this->cacheMock->expects($this->once())->method('remove')->with(Config::ATTRIBUTES_CACHE_ID . Product::ENTITY);
187+
$this->cacheMock->expects($this->once())
188+
->method('remove')->with(Config::ATTRIBUTES_CACHE_ID . Product::ENTITY);
176189

177190
$this->model->execute();
178191
}
179192

193+
/**
194+
* Test for getActionTitle method.
195+
*
196+
* @return void
197+
*/
180198
public function testGetActionTitle()
181199
{
182200
$this->assertSame('Generating configurable EAV variations', $this->model->getActionTitle());
183201
}
184202

203+
/**
204+
* Test for introduceParamLabels method.
205+
*
206+
* @return void
207+
*/
185208
public function testIntroduceParamLabels()
186209
{
187210
$this->assertSame([], $this->model->introduceParamLabels());

0 commit comments

Comments
 (0)