25 private $bulkCollectionFactory;
30 private $operationCollectionFactory;
35 private $operationMock;
45 private $resourceConnectionMock;
50 private $calculatedStatusSqlMock;
55 private $metadataPoolMock;
60 private $bulkDetailedFactory;
65 private $bulkShortFactory;
70 private $entityMetadataMock;
75 private $entityManager;
80 private $connectionMock;
84 $this->bulkCollectionFactory = $this->createPartialMock(
88 $this->operationCollectionFactory = $this->createPartialMock(
92 $this->operationMock = $this->createMock(\
Magento\AsynchronousOperations\Api\Data\OperationInterface::class);
93 $this->bulkMock = $this->createMock(\
Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface::class);
94 $this->resourceConnectionMock = $this->createMock(\
Magento\Framework\
App\ResourceConnection::class);
95 $this->calculatedStatusSqlMock = $this->createMock(
96 \
Magento\AsynchronousOperations\Model\BulkStatus\CalculatedStatusSql::class
98 $this->metadataPoolMock = $this->createMock(\
Magento\Framework\EntityManager\MetadataPool::class);
99 $this->bulkDetailedFactory = $this->createPartialMock(
100 \
Magento\AsynchronousOperations\Api\Data\DetailedBulkOperationsStatusInterfaceFactory ::class,
103 $this->bulkShortFactory = $this->createPartialMock(
104 \
Magento\AsynchronousOperations\Api\Data\BulkOperationsStatusInterfaceFactory::class,
107 $this->entityManager = $this->createMock(\
Magento\Framework\EntityManager\EntityManager::class);
109 $this->entityMetadataMock = $this->createMock(\
Magento\Framework\EntityManager\EntityMetadataInterface::class);
110 $this->connectionMock = $this->createMock(\
Magento\Framework\DB\Adapter\AdapterInterface::class);
112 $this->model = new \Magento\AsynchronousOperations\Model\BulkStatus(
113 $this->bulkCollectionFactory,
114 $this->operationCollectionFactory,
115 $this->resourceConnectionMock,
116 $this->calculatedStatusSqlMock,
117 $this->metadataPoolMock,
118 $this->bulkDetailedFactory,
119 $this->bulkShortFactory,
131 $bulkUuid =
'bulk-1';
132 $operationCollection = $this->createMock(
135 $this->operationCollectionFactory->expects($this->once())->method(
'create')->willReturn($operationCollection);
137 ->expects($this->at(0))
138 ->method(
'addFieldToFilter')
139 ->with(
'bulk_uuid', $bulkUuid)
142 ->expects($this->at(1))
143 ->method(
'addFieldToFilter')
144 ->with(
'status', $failureCodes)
146 $operationCollection->expects($this->once())->method(
'getItems')->willReturn([$this->operationMock]);
147 $this->assertEquals([$this->operationMock], $this->model->getFailedOperationsByBulkId($bulkUuid, $failureType));
152 $bulkUuid =
'bulk-1';
156 $operationCollection = $this->createMock(
159 $this->operationCollectionFactory->expects($this->once())->method(
'create')->willReturn($operationCollection);
161 ->expects($this->at(0))
162 ->method(
'addFieldToFilter')
163 ->with(
'bulk_uuid', $bulkUuid)
166 ->expects($this->at(1))
167 ->method(
'addFieldToFilter')
171 ->expects($this->once())
174 $this->assertEquals($size, $this->model->getOperationsCountByBulkIdAndStatus($bulkUuid,
$status));
197 $selectMock = $this->createMock(\
Magento\Framework\DB\Select::class);
198 $bulkCollection = $this->createMock(\
Magento\AsynchronousOperations\Model\
ResourceModel\Bulk\Collection::class);
199 $bulkCollection->expects($this->once())->method(
'getSelect')->willReturn($selectMock);
200 $selectMock->expects($this->once())->method(
'columns')->willReturnSelf();
201 $selectMock->expects($this->once())->method(
'order')->willReturnSelf();
202 $this->bulkCollectionFactory->expects($this->once())->method(
'create')->willReturn($bulkCollection);
203 $bulkCollection->expects($this->once())->method(
'addFieldToFilter')->with(
'user_id', $userId)->willReturnSelf();
204 $bulkCollection->expects($this->once())->method(
'getItems')->willReturn([$this->bulkMock]);
205 $this->assertEquals([$this->bulkMock], $this->model->getBulksByUser($userId));
210 $bulkUuid =
'bulk-1';
211 $allProcessedOperationCollection = $this->createMock(
215 $completeOperationCollection = $this->createMock(
219 $connectionName =
'connection_name';
220 $entityType = \Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface::class;
221 $this->metadataPoolMock
222 ->expects($this->once())
223 ->method(
'getMetadata')
225 ->willReturn($this->entityMetadataMock);
226 $this->entityMetadataMock
227 ->expects($this->once())
228 ->method(
'getEntityConnectionName')
229 ->willReturn($connectionName);
230 $this->resourceConnectionMock
231 ->expects($this->once())
232 ->method(
'getConnectionByName')
233 ->with($connectionName)
234 ->willReturn($this->connectionMock);
236 $selectMock = $this->createMock(\
Magento\Framework\DB\Select::class);
237 $selectMock->expects($this->once())->method(
'from')->willReturnSelf();
238 $selectMock->expects($this->once())->method(
'where')->with(
'uuid = ?', $bulkUuid)->willReturnSelf();
239 $this->connectionMock->expects($this->once())->method(
'select')->willReturn($selectMock);
240 $this->connectionMock->expects($this->once())->method(
'fetchOne')->with($selectMock)->willReturn(10);
242 $this->operationCollectionFactory
243 ->expects($this->at(0))
245 ->willReturn($allProcessedOperationCollection);
246 $this->operationCollectionFactory
247 ->expects($this->at(1))
249 ->willReturn($completeOperationCollection);
250 $allProcessedOperationCollection
251 ->expects($this->once())
252 ->method(
'addFieldToFilter')
253 ->with(
'bulk_uuid', $bulkUuid)
255 $allProcessedOperationCollection->expects($this->once())->method(
'getSize')->willReturn(5);
257 $completeOperationCollection
258 ->expects($this->at(0))
259 ->method(
'addFieldToFilter')
260 ->with(
'bulk_uuid', $bulkUuid)
262 $completeOperationCollection
263 ->expects($this->at(1))
264 ->method(
'addFieldToFilter')
267 $completeOperationCollection->expects($this->any())->method(
'getSize')->willReturn(5);
getFailedOperationsByBulkIdDataProvider()
const STATUS_TYPE_NOT_RETRIABLY_FAILED
const STATUS_TYPE_RETRIABLY_FAILED
const STATUS_TYPE_COMPLETE
testGetFailedOperationsByBulkId($failureType, $failureCodes)
testGetOperationsCountByBulkIdAndStatus()