10 use Magento\Sales\Model\Order\Status\HistoryFactory;
13 use PHPUnit_Framework_MockObject_MockObject as MockObject;
24 private static $orderId = 123;
29 private static $message =
'Case is created.';
34 private static $status =
'On Hold';
44 private $historyFactory;
54 private $historyEntity;
59 private $historyRepository;
68 $this->historyFactory = $this->getMockBuilder(HistoryFactory::class)
69 ->disableOriginalConstructor()
70 ->setMethods([
'create',
'save'])
73 $this->historyRepository = $this->getMockBuilder(OrderStatusHistoryRepositoryInterface::class)
74 ->getMockForAbstractClass();
76 $this->caseEntity = $this->getMockBuilder(CaseInterface::class)
77 ->disableOriginalConstructor()
78 ->setMethods([
'getOrderId'])
79 ->getMockForAbstractClass();
81 $this->initCommentMock();
83 $this->updater =
$objectManager->getObject(CommentsHistoryUpdater::class, [
84 'historyFactory' => $this->historyFactory,
85 'historyRepository' => $this->historyRepository
97 $this->caseEntity->expects(self::once())
98 ->method(
'getOrderId')
99 ->willReturn(self::$orderId);
101 $this->historyEntity->method(
'setStatus')
104 $this->historyRepository->expects(self::once())
106 ->with($this->historyEntity)
107 ->willThrowException(
new \Exception(
'Cannot save comment message.'));
119 $this->caseEntity->expects(self::once())
120 ->method(
'getOrderId')
121 ->willReturn(self::$orderId);
123 $this->historyEntity->method(
'setStatus')
126 $this->historyRepository->expects(self::once())
128 ->with($this->historyEntity)
141 $this->caseEntity->expects(self::never())
142 ->method(
'getOrderId');
144 $this->historyFactory->expects(self::never())
148 $this->updater->addComment($this->caseEntity,
__($phrase));
156 private function initCommentMock()
158 $this->historyEntity = $this->getMockBuilder(OrderStatusHistoryInterface::class)
159 ->disableOriginalConstructor()
160 ->setMethods([
'setParentId',
'setComment',
'setEntityName',
'save'])
161 ->getMockForAbstractClass();
163 $this->historyFactory->method(
'create')
164 ->willReturn($this->historyEntity);
166 $this->historyEntity->method(
'setParentId')
167 ->with(self::$orderId)
169 $this->historyEntity->method(
'setComment')
172 $this->historyEntity->method(
'setEntityName')