77namespace Magento \BundleImportExport \Test \Unit \Model \Import \Product \Type \Bundle ;
88
99use Magento \BundleImportExport \Model \Import \Product \Type \Bundle \RelationsDataSaver ;
10+ use Magento \Catalog \Model \ResourceModel \Product \Relation ;
1011use Magento \Framework \App \ResourceConnection ;
1112use Magento \Framework \DB \Adapter \AdapterInterface ;
1213
@@ -30,6 +31,11 @@ class RelationsDataSaverTest extends \PHPUnit\Framework\TestCase
3031 */
3132 private $ connectionMock ;
3233
34+ /**
35+ * @var Relation|\PHPUnit_Framework_MockObject_MockObject
36+ */
37+ private $ productRelationMock ;
38+
3339 protected function setUp ()
3440 {
3541 $ helper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
@@ -39,12 +45,16 @@ protected function setUp()
3945 $ this ->connectionMock = $ this ->getMockBuilder (AdapterInterface::class)
4046 ->disableOriginalConstructor ()
4147 ->getMock ();
42- $ this ->resourceMock ->expects ($ this ->once ())->method ('getConnection ' )->willReturn ($ this ->connectionMock );
48+
49+ $ this ->productRelationMock = $ this ->getMockBuilder (Relation::class)
50+ ->disableOriginalConstructor ()
51+ ->getMock ();
4352
4453 $ this ->relationsDataSaver = $ helper ->getObject (
4554 RelationsDataSaver::class,
4655 [
47- 'resource ' => $ this ->resourceMock
56+ 'resource ' => $ this ->resourceMock ,
57+ 'productRelation ' => $ this ->productRelationMock
4858 ]
4959 );
5060 }
@@ -53,7 +63,7 @@ public function testSaveOptions()
5363 {
5464 $ options = [1 , 2 ];
5565 $ table_name = 'catalog_product_bundle_option ' ;
56-
66+ $ this -> resourceMock -> expects ( $ this -> once ())-> method ( ' getConnection ' )-> willReturn ( $ this -> connectionMock );
5767 $ this ->resourceMock ->expects ($ this ->once ())
5868 ->method ('getTableName ' )
5969 ->with ('catalog_product_bundle_option ' )
@@ -78,6 +88,7 @@ public function testSaveOptionValues()
7888 $ optionsValues = [1 , 2 ];
7989 $ table_name = 'catalog_product_bundle_option_value ' ;
8090
91+ $ this ->resourceMock ->expects ($ this ->once ())->method ('getConnection ' )->willReturn ($ this ->connectionMock );
8192 $ this ->resourceMock ->expects ($ this ->once ())
8293 ->method ('getTableName ' )
8394 ->with ('catalog_product_bundle_option_value ' )
@@ -98,6 +109,7 @@ public function testSaveSelections()
98109 $ selections = [1 , 2 ];
99110 $ table_name = 'catalog_product_bundle_selection ' ;
100111
112+ $ this ->resourceMock ->expects ($ this ->once ())->method ('getConnection ' )->willReturn ($ this ->connectionMock );
101113 $ this ->resourceMock ->expects ($ this ->once ())
102114 ->method ('getTableName ' )
103115 ->with ('catalog_product_bundle_selection ' )
@@ -121,4 +133,16 @@ public function testSaveSelections()
121133
122134 $ this ->relationsDataSaver ->saveSelections ($ selections );
123135 }
136+
137+ public function testSaveProductRelations ()
138+ {
139+ $ parentId = 1 ;
140+ $ children = [2 , 3 ];
141+
142+ $ this ->productRelationMock ->expects ($ this ->once ())
143+ ->method ('processRelations ' )
144+ ->with ($ parentId , $ children );
145+
146+ $ this ->relationsDataSaver ->saveProductRelations ($ parentId , $ children );
147+ }
124148}
0 commit comments