Skip to content

Commit ca778da

Browse files
committed
MAGETWO-67010: [Performance] Swatches real server side optimization
1 parent 2fcb2bb commit ca778da

File tree

1 file changed

+11
-89
lines changed

1 file changed

+11
-89
lines changed

app/code/Magento/Swatches/Test/Unit/Controller/Ajax/MediaTest.php

Lines changed: 11 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,34 @@
1212
class MediaTest extends \PHPUnit_Framework_TestCase
1313
{
1414
/** @var array */
15-
protected $mediaGallery;
15+
private $mediaGallery;
1616

1717
/** @var \Magento\Swatches\Helper\Data|\PHPUnit_Framework_MockObject_MockObject */
18-
protected $swatchHelperMock;
18+
private $swatchHelperMock;
1919

2020
/** @var \Magento\Catalog\Model\ProductFactory|\PHPUnit_Framework_MockObject_MockObject */
21-
protected $productModelFactoryMock;
21+
private $productModelFactoryMock;
2222

2323
/** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject */
24-
protected $productMock;
25-
26-
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute|\PHPUnit_Framework_MockObject_MockObject */
27-
protected $attributeMock;
24+
private $productMock;
2825

2926
/** @var \Magento\Framework\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject */
30-
protected $contextMock;
27+
private $contextMock;
3128

3229
/** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
33-
protected $requestMock;
30+
private $requestMock;
3431

3532
/** @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject */
36-
protected $resultFactory;
33+
private $resultFactory;
3734

3835
/** @var \Magento\Framework\Controller\Result\Json|\PHPUnit_Framework_MockObject_MockObject */
39-
protected $jsonMock;
36+
private $jsonMock;
4037

4138
/** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */
42-
protected $objectManager;
39+
private $objectManager;
4340

4441
/** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager|\Magento\Swatches\Controller\Ajax\Media */
45-
protected $controller;
42+
private $controller;
4643

4744
protected function setUp()
4845
{
@@ -64,25 +61,9 @@ protected function setUp()
6461
false
6562
);
6663
$this->productMock = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
67-
$this->attributeMock = $this->getMock(
68-
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class,
69-
[],
70-
[],
71-
'',
72-
false
73-
);
7464
$this->contextMock = $this->getMock(\Magento\Framework\App\Action\Context::class, [], [], '', false);
7565

7666
$this->requestMock = $this->getMock(\Magento\Framework\App\RequestInterface::class);
77-
$this->requestMock->expects($this->any())->method('getParam')->withConsecutive(
78-
['product_id'],
79-
['attributes'],
80-
['additional']
81-
)->willReturnOnConsecutiveCalls(
82-
59,
83-
['size' => 454],
84-
['color' => 43]
85-
);
8667
$this->contextMock->method('getRequest')->willReturn($this->requestMock);
8768
$this->resultFactory = $this->getMock(
8869
\Magento\Framework\Controller\ResultFactory::class,
@@ -108,54 +89,7 @@ protected function setUp()
10889

10990
public function testExecute()
11091
{
111-
$this->attributeMock
112-
->expects($this->any())
113-
->method('offsetGet')
114-
->with('attribute_code')
115-
->willReturn('color');
116-
117-
$this->productMock
118-
->expects($this->once())
119-
->method('load')
120-
->with(59)
121-
->willReturn($this->productMock);
122-
123-
$this->productModelFactoryMock
124-
->expects($this->once())
125-
->method('create')
126-
->willReturn($this->productMock);
127-
128-
$this->swatchHelperMock
129-
->expects($this->once())
130-
->method('getAttributesFromConfigurable')
131-
->with($this->productMock)
132-
->willReturn([$this->attributeMock]);
133-
134-
$this->swatchHelperMock
135-
->expects($this->once())
136-
->method('loadVariationByFallback')
137-
->with($this->productMock, ['size' => 454, 'color' => 43])
138-
->willReturn($this->productMock);
139-
140-
$this->swatchHelperMock
141-
->expects($this->once())
142-
->method('getProductMediaGallery')
143-
->with($this->productMock)
144-
->willReturn($this->mediaGallery);
145-
146-
$this->jsonMock
147-
->expects($this->once())
148-
->method('setData')
149-
->with($this->mediaGallery)
150-
->will($this->returnSelf());
151-
152-
$result = $this->controller->execute();
153-
154-
$this->assertInstanceOf(\Magento\Framework\Controller\Result\Json::class, $result);
155-
}
156-
157-
public function testExecuteNullProduct()
158-
{
92+
$this->requestMock->expects($this->any())->method('getParam')->with('product_id')->willReturn(59);
15993
$this->productMock
16094
->expects($this->once())
16195
->method('load')
@@ -167,18 +101,6 @@ public function testExecuteNullProduct()
167101
->method('create')
168102
->willReturn($this->productMock);
169103

170-
$this->swatchHelperMock
171-
->expects($this->once())
172-
->method('getAttributesFromConfigurable')
173-
->with($this->productMock)
174-
->willReturn([$this->attributeMock]);
175-
176-
$this->swatchHelperMock
177-
->expects($this->once())
178-
->method('loadVariationByFallback')
179-
->with($this->productMock, ['size' => 454])
180-
->willReturn(null);
181-
182104
$this->swatchHelperMock
183105
->expects($this->once())
184106
->method('getProductMediaGallery')

0 commit comments

Comments
 (0)