36 $this->tableName =
'some_table_name';
38 $this->adapter = $this->getMockBuilder(\
Magento\Framework\DB\Adapter\AdapterInterface::class)
39 ->disableOriginalConstructor()
40 ->getMockForAbstractClass();
43 ->disableOriginalConstructor()
46 ->method(
'getConnection')
47 ->willReturn($this->adapter);
49 ->method(
'getTableName')
50 ->willReturn($this->tableName);
52 $this->config = $this->getMockBuilder(\
Magento\Framework\
App\DeploymentConfig::class)
53 ->disableOriginalConstructor()
57 \
Magento\Framework\
Search\Adapter\Mysql\TemporaryStorage::class,
58 [
'resource' =>
$resource,
'config' => $this->config]
62 public function testStoreDocumentsFromSelect()
64 $sql =
'some SQL query';
67 $select = $this->getMockBuilder(\
Magento\Framework\DB\Select::class)
68 ->disableOriginalConstructor()
71 $table = $this->createTemporaryTable();
73 $table->expects($this->any())
75 ->willReturn($this->tableName);
77 $this->adapter->expects($this->once())
78 ->method(
'insertFromSelect')
79 ->with(
$select, $this->tableName)
81 $this->adapter->expects($this->once())
93 $documentValue = 1.235123;
95 $attributeValue = $this->getMockBuilder(\
Magento\Framework\Api\AttributeValue::class)
96 ->disableOriginalConstructor()
98 $attributeValue->expects($this->once())
100 ->willReturn($documentValue);
102 $document = $this->getMockBuilder(\
Magento\Framework\Api\
Search\Document::class)
103 ->disableOriginalConstructor()
105 $document->expects($this->once())
107 ->willReturn($documentId);
108 $document->expects($this->once())
109 ->method(
'getCustomAttribute')
111 ->willReturn($attributeValue);
113 $table = $this->createTemporaryTable();
115 $result = $this->model->storeDocuments([$document]);
122 $documentId = 312432;
123 $documentValue = 1.235123;
125 $attributeValue = $this->getMockBuilder(\
Magento\Framework\Api\AttributeValue::class)
126 ->disableOriginalConstructor()
128 $attributeValue->expects($this->once())
130 ->willReturn($documentValue);
132 $document = $this->getMockBuilder(\
Magento\Framework\Api\
Search\Document::class)
133 ->disableOriginalConstructor()
135 $document->expects($this->once())
137 ->willReturn($documentId);
138 $document->expects($this->once())
139 ->method(
'getCustomAttribute')
141 ->willReturn($attributeValue);
143 $table = $this->createTemporaryTable();
145 $result = $this->model->storeApiDocuments([$document]);
152 $this->createTemporaryTable(
false);
154 $this->adapter->expects($this->never())
155 ->method(
'dropTemporaryTable');
158 $this->model->storeApiDocuments([]);
164 private function createTemporaryTable($persistentConnection =
true)
166 $this->config->expects($this->any())
168 ->with(
'db/connection/indexer/persistent')
169 ->willReturn($persistentConnection);
171 $table = $this->getMockBuilder(\
Magento\Framework\DB\Ddl\Table::class)
172 ->disableOriginalConstructor()
175 $tableInteractionCount = 0;
176 if ($persistentConnection) {
177 $this->adapter->expects($this->once())
178 ->method(
'dropTemporaryTable');
179 $tableInteractionCount += 1;
181 $table->expects($this->at($tableInteractionCount))
182 ->method(
'addColumn')
187 [
'unsigned' =>
true,
'nullable' =>
false,
'primary' =>
true],
190 $tableInteractionCount += 1;
191 $table->expects($this->at($tableInteractionCount))
192 ->method(
'addColumn')
197 [
'unsigned' =>
true,
'nullable' =>
false],
200 $table->expects($this->once())
201 ->method(
'setOption')
202 ->with(
'type',
'memory');
204 $this->adapter->expects($this->once())
206 ->with($this->tableName)
208 $this->adapter->expects($this->once())
209 ->method(
'createTemporaryTable')
testNoDropIfNotPersistent()