Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
OperationManagementTest.php
Go to the documentation of this file.
1 <?php
7 
11 class OperationManagementTest extends \PHPUnit\Framework\TestCase
12 {
16  private $model;
17 
21  private $entityManagerMock;
22 
26  private $operationFactoryMock;
27 
31  private $operationMock;
32 
36  private $loggerMock;
37 
38  protected function setUp()
39  {
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,
44  ['create']
45  );
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,
52  $this->loggerMock
53  );
54  }
55 
56  public function testChangeOperationStatus()
57  {
58  $operationId = 1;
59  $status = 1;
60  $message = 'Message';
61  $data = 'data';
62  $errorCode = 101;
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));
71  }
72 
74  {
75  $operationId = 1;
76  $status = 1;
77  $message = 'Message';
78  $data = 'data';
79  $errorCode = 101;
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));
89  }
90 }
$message
$status
Definition: order_status.php:8