@@ -55,4 +55,104 @@ public function testExecuteWithAdapterErrorThrowsException()
55
55
56
56
$ model ->execute ();
57
57
}
58
+
59
+ public function testExecute ()
60
+ {
61
+ $ eavDecimalFactory = $ this ->getMock (
62
+ \Magento \Catalog \Model \ResourceModel \Product \Indexer \Eav \DecimalFactory::class,
63
+ ['create ' ],
64
+ [],
65
+ '' ,
66
+ false
67
+ );
68
+ $ eavSourceFactory = $ this ->getMock (
69
+ \Magento \Catalog \Model \ResourceModel \Product \Indexer \Eav \SourceFactory::class,
70
+ ['create ' ],
71
+ [],
72
+ '' ,
73
+ false
74
+ );
75
+
76
+ $ ids = [1 , 2 , 3 ];
77
+ $ connectionMock = $ this ->getMockBuilder (\Magento \Framework \DB \Adapter \AdapterInterface::class)
78
+ ->getMockForAbstractClass ();
79
+
80
+ $ connectionMock ->expects ($ this ->atLeastOnce ())->method ('describeTable ' )->willReturn (['id ' => []]);
81
+ $ eavSource = $ this ->getMockBuilder (\Magento \Catalog \Model \ResourceModel \Product \Indexer \Eav \Source::class)
82
+ ->disableOriginalConstructor ()
83
+ ->getMock ();
84
+
85
+ $ eavDecimal = $ this ->getMockBuilder (\Magento \Catalog \Model \ResourceModel \Product \Indexer \Eav \Decimal::class)
86
+ ->disableOriginalConstructor ()
87
+ ->getMock ();
88
+
89
+ $ eavSource ->expects ($ this ->once ())->method ('getRelationsByChild ' )->with ($ ids )->willReturn ([]);
90
+ $ eavSource ->expects ($ this ->never ())->method ('getRelationsByParent ' )->with ($ ids )->willReturn ([]);
91
+
92
+ $ eavDecimal ->expects ($ this ->once ())->method ('getRelationsByChild ' )->with ($ ids )->willReturn ([]);
93
+ $ eavDecimal ->expects ($ this ->never ())->method ('getRelationsByParent ' )->with ($ ids )->willReturn ([]);
94
+
95
+ $ eavSource ->expects ($ this ->atLeastOnce ())->method ('getConnection ' )->willReturn ($ connectionMock );
96
+ $ eavDecimal ->expects ($ this ->atLeastOnce ())->method ('getConnection ' )->willReturn ($ connectionMock );
97
+
98
+
99
+ $ eavDecimal ->expects ($ this ->once ())
100
+ ->method ('reindexEntities ' )
101
+ ->with ($ ids );
102
+
103
+ $ eavSource ->expects ($ this ->once ())
104
+ ->method ('reindexEntities ' )
105
+ ->with ($ ids );
106
+
107
+ $ eavDecimalFactory ->expects ($ this ->once ())
108
+ ->method ('create ' )
109
+ ->will ($ this ->returnValue ($ eavSource ));
110
+
111
+ $ eavSourceFactory ->expects ($ this ->once ())
112
+ ->method ('create ' )
113
+ ->will ($ this ->returnValue ($ eavDecimal ));
114
+
115
+ $ metadataMock = $ this ->getMock (\Magento \Framework \EntityManager \MetadataPool::class, [], [], '' , false );
116
+ $ entityMetadataMock = $ this ->getMockBuilder (\Magento \Framework \EntityManager \EntityMetadataInterface::class)
117
+ ->getMockForAbstractClass ();
118
+
119
+ $ metadataMock ->expects ($ this ->atLeastOnce ())
120
+ ->method ('getMetadata ' )
121
+ ->with (\Magento \Catalog \Api \Data \ProductInterface::class)
122
+ ->willReturn ($ entityMetadataMock );
123
+
124
+ $ batchProviderMock = $ this ->getMock (\Magento \Framework \Indexer \BatchProviderInterface::class);
125
+ $ batchProviderMock ->expects ($ this ->atLeastOnce ())
126
+ ->method ('getBatches ' )
127
+ ->willReturn ([['from ' =>10 , 'to ' => 100 ]]);
128
+ $ batchProviderMock ->expects ($ this ->atLeastOnce ())
129
+ ->method ('getBatchIds ' )
130
+ ->willReturn ($ ids );
131
+
132
+ $ batchManagementMock = $ this ->getMock (
133
+ \Magento \Catalog \Model \ResourceModel \Product \Indexer \Eav \BatchSizeCalculator::class,
134
+ [],
135
+ [],
136
+ '' ,
137
+ false
138
+ );
139
+ $ selectMock = $ this ->getMockBuilder (\Magento \Framework \DB \Select::class)
140
+ ->disableOriginalConstructor ()
141
+ ->getMock ();
142
+
143
+ $ connectionMock ->method ('select ' )->willReturn ($ selectMock );
144
+ $ selectMock ->expects ($ this ->atLeastOnce ())->method ('distinct ' )->willReturnSelf ();
145
+ $ selectMock ->expects ($ this ->atLeastOnce ())->method ('from ' )->willReturnSelf ();
146
+
147
+ $ model = new \Magento \Catalog \Model \Indexer \Product \Eav \Action \Full (
148
+ $ eavDecimalFactory ,
149
+ $ eavSourceFactory ,
150
+ $ metadataMock ,
151
+ $ batchProviderMock ,
152
+ $ batchManagementMock ,
153
+ []
154
+ );
155
+
156
+ $ model ->execute ();
157
+ }
58
158
}
0 commit comments