88namespace Magento \ConfigurableProduct \Test \Unit \Model \Product ;
99
1010use Magento \Catalog \Model \Product ;
11+ use Magento \Catalog \Model \ProductRepository ;
1112use Magento \ConfigurableProduct \Api \Data \OptionInterface ;
1213use Magento \ConfigurableProduct \Model \OptionRepository ;
1314use Magento \ConfigurableProduct \Model \Product \SaveHandler ;
1415use Magento \ConfigurableProduct \Model \Product \Type \Configurable as ConfigurableModel ;
1516use Magento \ConfigurableProduct \Model \Product \Type \Configurable \Attribute ;
1617use Magento \ConfigurableProduct \Model \ResourceModel \Product \Type \Configurable ;
1718use Magento \ConfigurableProduct \Model \ResourceModel \Product \Type \ConfigurableFactory ;
19+ use Magento \Catalog \Api \ProductRepositoryInterface ;
1820use PHPUnit \Framework \MockObject \MockObject ;
1921use PHPUnit \Framework \TestCase ;
2022
@@ -38,6 +40,11 @@ class SaveHandlerTest extends TestCase
3840 */
3941 private $ configurable ;
4042
43+ /**
44+ * @var ProductRepositoryInterface|MockObject
45+ */
46+ protected $ productRepository ;
47+
4148 /**
4249 * @var SaveHandler
4350 */
@@ -55,9 +62,15 @@ protected function setUp(): void
5562
5663 $ this ->initConfigurableFactoryMock ();
5764
65+ $ this ->productRepository = $ this ->getMockBuilder (ProductRepository::class)
66+ ->disableOriginalConstructor ()
67+ ->onlyMethods (['get ' ])
68+ ->getMock ();
69+
5870 $ this ->saveHandler = new SaveHandler (
5971 $ this ->configurable ,
60- $ this ->optionRepository
72+ $ this ->optionRepository ,
73+ $ this ->productRepository
6174 );
6275 }
6376
@@ -97,7 +110,7 @@ public function testExecuteWithEmptyExtensionAttributes()
97110 $ product ->expects (static ::once ())
98111 ->method ('getTypeId ' )
99112 ->willReturn (ConfigurableModel::TYPE_CODE );
100- $ product ->expects (static ::exactly (1 ))
113+ $ product ->expects (static ::exactly (2 ))
101114 ->method ('getSku ' )
102115 ->willReturn ($ sku );
103116
@@ -147,7 +160,7 @@ public function testExecute()
147160 $ product ->expects (static ::once ())
148161 ->method ('getTypeId ' )
149162 ->willReturn (ConfigurableModel::TYPE_CODE );
150- $ product ->expects (static ::exactly (4 ))
163+ $ product ->expects (static ::exactly (5 ))
151164 ->method ('getSku ' )
152165 ->willReturn ($ sku );
153166
@@ -160,6 +173,9 @@ public function testExecute()
160173 ->method ('getExtensionAttributes ' )
161174 ->willReturn ($ extensionAttributes );
162175
176+ $ this ->productRepository ->expects ($ this ->once ())
177+ ->method ('get ' )->with ($ sku , false , null , true );
178+
163179 $ attributeNew = $ this ->getMockBuilder (Attribute::class)
164180 ->disableOriginalConstructor ()
165181 ->setMethods (['getAttributeId ' , 'loadByProductAndAttribute ' , 'setId ' , 'getId ' ])
0 commit comments