Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 04ca7af

Browse files
committed
MAGETWO-70985: Deprecate Repository generation logic and Materialize Repositories being generated now
- Marked repository generator as deprecated - Implemented auto-generated repositories - Marked methods as deprecated for AbstractMethod class
1 parent d2880ba commit 04ca7af

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

Model/CommentsHistoryUpdater.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Signifyd\Model;
77

88
use Magento\Framework\Phrase;
9+
use Magento\Sales\Api\OrderStatusHistoryRepositoryInterface;
910
use Magento\Sales\Model\Order\Status\HistoryFactory;
1011
use Magento\Signifyd\Api\Data\CaseInterface;
1112

@@ -19,14 +20,24 @@ class CommentsHistoryUpdater
1920
*/
2021
private $historyFactory;
2122

23+
/**
24+
* @var OrderStatusHistoryRepositoryInterface
25+
* @since 2.2.0
26+
*/
27+
private $historyRepository;
28+
2229
/**
2330
* CommentsHistoryUpdater constructor.
2431
*
2532
* @param HistoryFactory $historyFactory
33+
* @param OrderStatusHistoryRepositoryInterface $historyRepository
2634
*/
27-
public function __construct(HistoryFactory $historyFactory)
28-
{
35+
public function __construct(
36+
HistoryFactory $historyFactory,
37+
OrderStatusHistoryRepositoryInterface $historyRepository
38+
) {
2939
$this->historyFactory = $historyFactory;
40+
$this->historyRepository = $historyRepository;
3041
}
3142

3243
/**
@@ -49,7 +60,7 @@ public function addComment(CaseInterface $case, Phrase $message, $status = '')
4960
$history->setParentId($case->getOrderId())
5061
->setComment($message)
5162
->setEntityName('order')
52-
->setStatus($status)
53-
->save();
63+
->setStatus($status);
64+
$this->historyRepository->save($history);
5465
}
5566
}

Test/Unit/Model/CommentsHistoryUpdaterTest.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Signifyd\Api\Data\CaseInterface;
1212
use Magento\Signifyd\Model\CommentsHistoryUpdater;
1313
use PHPUnit_Framework_MockObject_MockObject as MockObject;
14+
use Magento\Sales\Api\OrderStatusHistoryRepositoryInterface;
1415

1516
/**
1617
* Contains tests for comments history updater class.
@@ -52,6 +53,11 @@ class CommentsHistoryUpdaterTest extends \PHPUnit\Framework\TestCase
5253
*/
5354
private $historyEntity;
5455

56+
/**
57+
* @var OrderStatusHistoryRepositoryInterface|MockObject
58+
*/
59+
private $historyRepository;
60+
5561
/**
5662
* @inheritdoc
5763
*/
@@ -64,6 +70,9 @@ protected function setUp()
6470
->setMethods(['create', 'save'])
6571
->getMock();
6672

73+
$this->historyRepository = $this->getMockBuilder(OrderStatusHistoryRepositoryInterface::class)
74+
->getMockForAbstractClass();
75+
6776
$this->caseEntity = $this->getMockBuilder(CaseInterface::class)
6877
->disableOriginalConstructor()
6978
->setMethods(['getOrderId'])
@@ -72,7 +81,8 @@ protected function setUp()
7281
$this->initCommentMock();
7382

7483
$this->updater = $objectManager->getObject(CommentsHistoryUpdater::class, [
75-
'historyFactory' => $this->historyFactory
84+
'historyFactory' => $this->historyFactory,
85+
'historyRepository' => $this->historyRepository
7686
]);
7787
}
7888

@@ -88,12 +98,12 @@ public function testAddCommentWithException()
8898
->method('getOrderId')
8999
->willReturn(self::$orderId);
90100

91-
$this->historyEntity->expects(self::any())
92-
->method('setStatus')
101+
$this->historyEntity->method('setStatus')
93102
->with('')
94103
->willReturnSelf();
95-
$this->historyEntity->expects(self::once())
104+
$this->historyRepository->expects(self::once())
96105
->method('save')
106+
->with($this->historyEntity)
97107
->willThrowException(new \Exception('Cannot save comment message.'));
98108

99109
$this->updater->addComment($this->caseEntity, __(self::$message));
@@ -110,12 +120,12 @@ public function testAddComment()
110120
->method('getOrderId')
111121
->willReturn(self::$orderId);
112122

113-
$this->historyEntity->expects(self::any())
114-
->method('setStatus')
123+
$this->historyEntity->method('setStatus')
115124
->with(self::$status)
116125
->willReturnSelf();
117-
$this->historyEntity->expects(self::once())
126+
$this->historyRepository->expects(self::once())
118127
->method('save')
128+
->with($this->historyEntity)
119129
->willReturnSelf();
120130

121131
$this->updater->addComment($this->caseEntity, __(self::$message), self::$status);
@@ -150,20 +160,16 @@ private function initCommentMock()
150160
->setMethods(['setParentId', 'setComment', 'setEntityName', 'save'])
151161
->getMockForAbstractClass();
152162

153-
$this->historyFactory->expects(self::any())
154-
->method('create')
163+
$this->historyFactory->method('create')
155164
->willReturn($this->historyEntity);
156165

157-
$this->historyEntity->expects(self::any())
158-
->method('setParentId')
166+
$this->historyEntity->method('setParentId')
159167
->with(self::$orderId)
160168
->willReturnSelf();
161-
$this->historyEntity->expects(self::any())
162-
->method('setComment')
169+
$this->historyEntity->method('setComment')
163170
->with(self::$message)
164171
->willReturnSelf();
165-
$this->historyEntity->expects(self::any())
166-
->method('setEntityName')
172+
$this->historyEntity->method('setEntityName')
167173
->with('order')
168174
->willReturnSelf();
169175
}

0 commit comments

Comments
 (0)