1010use Codeception \PHPUnit \TestCase ;
1111use Magento \Bundle \Model \ResourceModel \Selection as ResourceSelection ;
1212use Magento \Bundle \Model \Selection ;
13+ use Magento \Framework \App \ResourceConnection ;
1314use Magento \Framework \DB \Adapter \AdapterInterface ;
15+ use Magento \Framework \EntityManager \MetadataPool ;
16+ use Magento \Framework \Model \ResourceModel \Db \Context ;
1417
15- /**
16- * Class to test Selection Resource Model
17- */
1818class SelectionTest extends TestCase
1919{
20+ /**
21+ * @var Context|Context&\PHPUnit\Framework\MockObject\MockObject|\PHPUnit\Framework\MockObject\MockObject
22+ */
23+ private Context $ context ;
24+
25+ /**
26+ * @var MetadataPool|MetadataPool&\PHPUnit\Framework\MockObject\MockObject|\PHPUnit\Framework\MockObject\MockObject
27+ */
28+ private MetadataPool $ metadataPool ;
29+
30+ /**
31+ * @inheritdoc
32+ */
33+ protected function setUp (): void
34+ {
35+ parent ::setUp ();
36+
37+ $ this ->context = $ this ->createMock (Context::class);
38+ $ this ->metadataPool = $ this ->createMock (MetadataPool::class);
39+ }
40+
2041 public function testSaveSelectionPrice ()
2142 {
2243 $ item = $ this ->getMockBuilder (Selection::class)
@@ -43,27 +64,29 @@ public function testSaveSelectionPrice()
4364 $ item ->expects ($ this ->once ())->method ('getSelectionPriceValue ' )->willReturn ($ values ['selection_price_value ' ]);
4465 $ item ->expects ($ this ->once ())->method ('getParentProductId ' )->willReturn ($ values ['parent_product_id ' ]);
4566
46- $ selection = $ this ->getMockBuilder (ResourceSelection::class)
47- ->disableOriginalConstructor ()
48- ->onlyMethods (['getConnection ' , 'getTable ' ])
49- ->getMock ();
50- $ selection ->expects ($ this ->any ())
51- ->method ('getTable ' )
52- ->with ('catalog_product_bundle_selection_price ' )
53- ->willReturn ('catalog_product_bundle_selection_price ' );
54-
5567 $ connection = $ this ->createMock (AdapterInterface::class);
5668 $ connection ->expects ($ this ->once ())
5769 ->method ('insertOnDuplicate ' )
5870 ->with (
59- $ selection -> getTable ( 'catalog_product_bundle_selection_price ' ) ,
71+ 'catalog_product_bundle_selection_price ' ,
6072 $ this ->callback (function ($ insertValues ) {
6173 return $ insertValues ['selection_price_type ' ] === 0 && $ insertValues ['selection_price_value ' ] === 0 ;
6274 }),
6375 ['selection_price_type ' , 'selection_price_value ' ]
6476 );
6577
66- $ selection ->expects ($ this ->once ())->method ('getConnection ' )->willReturn ($ connection );
78+ $ parentResources = $ this ->createMock (ResourceConnection::class);
79+ $ parentResources ->expects ($ this ->once ())->method ('getConnection ' )->willReturn ($ connection );
80+ $ parentResources ->expects ($ this ->once ())->method ('getTableName ' )
81+ ->with ('catalog_product_bundle_selection_price ' , 'test_connection_name ' )
82+ ->willReturn ('catalog_product_bundle_selection_price ' );
83+
84+ $ selection = new ResourceSelection ($ this ->context , $ this ->metadataPool , 'test_connection_name ' );
85+ $ reflect = new \ReflectionClass ($ selection );
86+ $ property = $ reflect ->getProperty ('_resources ' );
87+ $ property ->setAccessible (true );
88+ $ property ->setValue ($ selection , $ parentResources );
89+
6790 $ selection ->saveSelectionPrice ($ item );
6891 }
6992}
0 commit comments