10
10
use Codeception \PHPUnit \TestCase ;
11
11
use Magento \Bundle \Model \ResourceModel \Selection as ResourceSelection ;
12
12
use Magento \Bundle \Model \Selection ;
13
+ use Magento \Framework \App \ResourceConnection ;
13
14
use Magento \Framework \DB \Adapter \AdapterInterface ;
15
+ use Magento \Framework \EntityManager \MetadataPool ;
16
+ use Magento \Framework \Model \ResourceModel \Db \Context ;
14
17
15
- /**
16
- * Class to test Selection Resource Model
17
- */
18
18
class SelectionTest extends TestCase
19
19
{
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
+
20
41
public function testSaveSelectionPrice ()
21
42
{
22
43
$ item = $ this ->getMockBuilder (Selection::class)
@@ -43,27 +64,29 @@ public function testSaveSelectionPrice()
43
64
$ item ->expects ($ this ->once ())->method ('getSelectionPriceValue ' )->willReturn ($ values ['selection_price_value ' ]);
44
65
$ item ->expects ($ this ->once ())->method ('getParentProductId ' )->willReturn ($ values ['parent_product_id ' ]);
45
66
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
-
55
67
$ connection = $ this ->createMock (AdapterInterface::class);
56
68
$ connection ->expects ($ this ->once ())
57
69
->method ('insertOnDuplicate ' )
58
70
->with (
59
- $ selection -> getTable ( 'catalog_product_bundle_selection_price ' ) ,
71
+ 'catalog_product_bundle_selection_price ' ,
60
72
$ this ->callback (function ($ insertValues ) {
61
73
return $ insertValues ['selection_price_type ' ] === 0 && $ insertValues ['selection_price_value ' ] === 0 ;
62
74
}),
63
75
['selection_price_type ' , 'selection_price_value ' ]
64
76
);
65
77
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
+
67
90
$ selection ->saveSelectionPrice ($ item );
68
91
}
69
92
}
0 commit comments