8
8
namespace Magento \ConfigurableProduct \Test \Unit \Model \Product ;
9
9
10
10
use Magento \Catalog \Model \Product ;
11
+ use Magento \Catalog \Model \ProductRepository ;
11
12
use Magento \ConfigurableProduct \Api \Data \OptionInterface ;
12
13
use Magento \ConfigurableProduct \Model \OptionRepository ;
13
14
use Magento \ConfigurableProduct \Model \Product \SaveHandler ;
14
15
use Magento \ConfigurableProduct \Model \Product \Type \Configurable as ConfigurableModel ;
15
16
use Magento \ConfigurableProduct \Model \Product \Type \Configurable \Attribute ;
16
17
use Magento \ConfigurableProduct \Model \ResourceModel \Product \Type \Configurable ;
17
18
use Magento \ConfigurableProduct \Model \ResourceModel \Product \Type \ConfigurableFactory ;
19
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
18
20
use PHPUnit \Framework \MockObject \MockObject ;
19
21
use PHPUnit \Framework \TestCase ;
20
22
@@ -38,6 +40,11 @@ class SaveHandlerTest extends TestCase
38
40
*/
39
41
private $ configurable ;
40
42
43
+ /**
44
+ * @var ProductRepositoryInterface|MockObject
45
+ */
46
+ protected $ productRepository ;
47
+
41
48
/**
42
49
* @var SaveHandler
43
50
*/
@@ -55,9 +62,15 @@ protected function setUp(): void
55
62
56
63
$ this ->initConfigurableFactoryMock ();
57
64
65
+ $ this ->productRepository = $ this ->getMockBuilder (ProductRepository::class)
66
+ ->disableOriginalConstructor ()
67
+ ->onlyMethods (['get ' ])
68
+ ->getMock ();
69
+
58
70
$ this ->saveHandler = new SaveHandler (
59
71
$ this ->configurable ,
60
- $ this ->optionRepository
72
+ $ this ->optionRepository ,
73
+ $ this ->productRepository
61
74
);
62
75
}
63
76
@@ -97,7 +110,7 @@ public function testExecuteWithEmptyExtensionAttributes()
97
110
$ product ->expects (static ::once ())
98
111
->method ('getTypeId ' )
99
112
->willReturn (ConfigurableModel::TYPE_CODE );
100
- $ product ->expects (static ::exactly (1 ))
113
+ $ product ->expects (static ::exactly (2 ))
101
114
->method ('getSku ' )
102
115
->willReturn ($ sku );
103
116
@@ -147,7 +160,7 @@ public function testExecute()
147
160
$ product ->expects (static ::once ())
148
161
->method ('getTypeId ' )
149
162
->willReturn (ConfigurableModel::TYPE_CODE );
150
- $ product ->expects (static ::exactly (4 ))
163
+ $ product ->expects (static ::exactly (5 ))
151
164
->method ('getSku ' )
152
165
->willReturn ($ sku );
153
166
@@ -160,6 +173,9 @@ public function testExecute()
160
173
->method ('getExtensionAttributes ' )
161
174
->willReturn ($ extensionAttributes );
162
175
176
+ $ this ->productRepository ->expects ($ this ->once ())
177
+ ->method ('get ' )->with ($ sku , false , null , true );
178
+
163
179
$ attributeNew = $ this ->getMockBuilder (Attribute::class)
164
180
->disableOriginalConstructor ()
165
181
->setMethods (['getAttributeId ' , 'loadByProductAndAttribute ' , 'setId ' , 'getId ' ])
0 commit comments