21 private $entityManagerMock;
26 private $operationFactoryMock;
31 private $operationMock;
40 $this->entityManagerMock = $this->createMock(\
Magento\Framework\EntityManager\EntityManager::class);
41 $this->metadataPoolMock = $this->createMock(\
Magento\Framework\EntityManager\MetadataPool::class);
42 $this->operationFactoryMock = $this->createPartialMock(
43 \
Magento\AsynchronousOperations\Api\Data\OperationInterfaceFactory::class,
46 $this->operationMock =
47 $this->createMock(\
Magento\AsynchronousOperations\Api\Data\OperationInterface::class);
48 $this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
49 $this->model = new \Magento\AsynchronousOperations\Model\OperationManagement(
50 $this->entityManagerMock,
51 $this->operationFactoryMock,
63 $this->operationFactoryMock->expects($this->once())->method(
'create')->willReturn($this->operationMock);
64 $this->entityManagerMock->expects($this->once())->method(
'load')->with($this->operationMock, $operationId);
65 $this->operationMock->expects($this->once())->method(
'setStatus')->with(
$status)->willReturnSelf();
66 $this->operationMock->expects($this->once())->method(
'setResultMessage')->with(
$message)->willReturnSelf();
67 $this->operationMock->expects($this->once())->method(
'setSerializedData')->with(
$data)->willReturnSelf();
68 $this->operationMock->expects($this->once())->method(
'setErrorCode')->with($errorCode)->willReturnSelf();
69 $this->entityManagerMock->expects($this->once())->method(
'save')->with($this->operationMock);
70 $this->assertTrue($this->model->changeOperationStatus($operationId,
$status, $errorCode,
$message,
$data));
80 $this->operationFactoryMock->expects($this->once())->method(
'create')->willReturn($this->operationMock);
81 $this->entityManagerMock->expects($this->once())->method(
'load')->with($this->operationMock, $operationId);
82 $this->operationMock->expects($this->once())->method(
'setStatus')->with(
$status)->willReturnSelf();
83 $this->operationMock->expects($this->once())->method(
'setResultMessage')->with(
$message)->willReturnSelf();
84 $this->operationMock->expects($this->once())->method(
'setSerializedData')->with(
$data)->willReturnSelf();
85 $this->operationMock->expects($this->once())->method(
'setErrorCode')->with($errorCode)->willReturnSelf();
86 $this->entityManagerMock->expects($this->once())->method(
'save')->willThrowException(
new \Exception());
87 $this->loggerMock->expects($this->once())->method(
'critical');
88 $this->assertFalse($this->model->changeOperationStatus($operationId,
$status, $errorCode,
$message,
$data));
testChangeOperationStatus()
testChangeOperationStatusIfExceptionWasThrown()