@@ -26,6 +26,11 @@ class TemporaryStorageTest extends \PHPUnit\Framework\TestCase
26
26
*/
27
27
private $ model ;
28
28
29
+ /**
30
+ * @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject
31
+ */
32
+ private $ config ;
33
+
29
34
protected function setUp ()
30
35
{
31
36
$ this ->tableName = 'some_table_name ' ;
@@ -44,9 +49,13 @@ protected function setUp()
44
49
->method ('getTableName ' )
45
50
->willReturn ($ this ->tableName );
46
51
52
+ $ this ->config = $ this ->getMockBuilder (\Magento \Framework \App \DeploymentConfig::class)
53
+ ->disableOriginalConstructor ()
54
+ ->getMock ();
55
+
47
56
$ this ->model = (new ObjectManager ($ this ))->getObject (
48
57
\Magento \Framework \Search \Adapter \Mysql \TemporaryStorage::class,
49
- ['resource ' => $ resource ]
58
+ ['resource ' => $ resource, ' config ' => $ this -> config ]
50
59
);
51
60
}
52
61
@@ -138,15 +147,38 @@ public function testStoreApiDocuments()
138
147
$ this ->assertEquals ($ result , $ table );
139
148
}
140
149
150
+ public function testNoDropIfNotPersistent ()
151
+ {
152
+ $ this ->createTemporaryTable (false );
153
+
154
+ $ this ->adapter ->expects ($ this ->never ())
155
+ ->method ('dropTemporaryTable ' );
156
+
157
+ // model->createTemporaryTable() is a private method; this will call it
158
+ $ this ->model ->storeApiDocuments ([]);
159
+ }
160
+
141
161
/**
142
162
* @return \Magento\Framework\DB\Ddl\Table|\PHPUnit_Framework_MockObject_MockObject
143
163
*/
144
- private function createTemporaryTable ()
164
+ private function createTemporaryTable ($ persistentConnection = true )
145
165
{
166
+ $ this ->config ->expects ($ this ->any ())
167
+ ->method ('get ' )
168
+ ->with ('db/connection/indexer/persistent ' )
169
+ ->willReturn ($ persistentConnection );
170
+
146
171
$ table = $ this ->getMockBuilder (\Magento \Framework \DB \Ddl \Table::class)
147
172
->disableOriginalConstructor ()
148
173
->getMock ();
149
- $ table ->expects ($ this ->at (1 ))
174
+
175
+ $ tableInteractionCount = 0 ;
176
+ if ($ persistentConnection ) {
177
+ $ this ->adapter ->expects ($ this ->once ())
178
+ ->method ('dropTemporaryTable ' );
179
+ $ tableInteractionCount += 1 ;
180
+ }
181
+ $ table ->expects ($ this ->at ($ tableInteractionCount ))
150
182
->method ('addColumn ' )
151
183
->with (
152
184
TemporaryStorage::FIELD_ENTITY_ID ,
@@ -155,7 +187,8 @@ private function createTemporaryTable()
155
187
['unsigned ' => true , 'nullable ' => false , 'primary ' => true ],
156
188
'Entity ID '
157
189
);
158
- $ table ->expects ($ this ->at (2 ))
190
+ $ tableInteractionCount += 1 ;
191
+ $ table ->expects ($ this ->at ($ tableInteractionCount ))
159
192
->method ('addColumn ' )
160
193
->with (
161
194
'score ' ,
@@ -172,8 +205,6 @@ private function createTemporaryTable()
172
205
->method ('newTable ' )
173
206
->with ($ this ->tableName )
174
207
->willReturn ($ table );
175
- $ this ->adapter ->expects ($ this ->once ())
176
- ->method ('dropTemporaryTable ' );
177
208
$ this ->adapter ->expects ($ this ->once ())
178
209
->method ('createTemporaryTable ' )
179
210
->with ($ table );
0 commit comments