12
12
class MediaTest extends \PHPUnit_Framework_TestCase
13
13
{
14
14
/** @var array */
15
- protected $ mediaGallery ;
15
+ private $ mediaGallery ;
16
16
17
17
/** @var \Magento\Swatches\Helper\Data|\PHPUnit_Framework_MockObject_MockObject */
18
- protected $ swatchHelperMock ;
18
+ private $ swatchHelperMock ;
19
19
20
20
/** @var \Magento\Catalog\Model\ProductFactory|\PHPUnit_Framework_MockObject_MockObject */
21
- protected $ productModelFactoryMock ;
21
+ private $ productModelFactoryMock ;
22
22
23
23
/** @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 ;
28
25
29
26
/** @var \Magento\Framework\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject */
30
- protected $ contextMock ;
27
+ private $ contextMock ;
31
28
32
29
/** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
33
- protected $ requestMock ;
30
+ private $ requestMock ;
34
31
35
32
/** @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject */
36
- protected $ resultFactory ;
33
+ private $ resultFactory ;
37
34
38
35
/** @var \Magento\Framework\Controller\Result\Json|\PHPUnit_Framework_MockObject_MockObject */
39
- protected $ jsonMock ;
36
+ private $ jsonMock ;
40
37
41
38
/** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */
42
- protected $ objectManager ;
39
+ private $ objectManager ;
43
40
44
41
/** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager|\Magento\Swatches\Controller\Ajax\Media */
45
- protected $ controller ;
42
+ private $ controller ;
46
43
47
44
protected function setUp ()
48
45
{
@@ -64,25 +61,9 @@ protected function setUp()
64
61
false
65
62
);
66
63
$ 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
- );
74
64
$ this ->contextMock = $ this ->getMock (\Magento \Framework \App \Action \Context::class, [], [], '' , false );
75
65
76
66
$ 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
- );
86
67
$ this ->contextMock ->method ('getRequest ' )->willReturn ($ this ->requestMock );
87
68
$ this ->resultFactory = $ this ->getMock (
88
69
\Magento \Framework \Controller \ResultFactory::class,
@@ -108,54 +89,7 @@ protected function setUp()
108
89
109
90
public function testExecute ()
110
91
{
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 );
159
93
$ this ->productMock
160
94
->expects ($ this ->once ())
161
95
->method ('load ' )
@@ -167,18 +101,6 @@ public function testExecuteNullProduct()
167
101
->method ('create ' )
168
102
->willReturn ($ this ->productMock );
169
103
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
-
182
104
$ this ->swatchHelperMock
183
105
->expects ($ this ->once ())
184
106
->method ('getProductMediaGallery ' )
0 commit comments