11
11
use Magento \Signifyd \Api \Data \CaseInterface ;
12
12
use Magento \Signifyd \Model \CommentsHistoryUpdater ;
13
13
use PHPUnit_Framework_MockObject_MockObject as MockObject ;
14
+ use Magento \Sales \Api \OrderStatusHistoryRepositoryInterface ;
14
15
15
16
/**
16
17
* Contains tests for comments history updater class.
@@ -52,6 +53,11 @@ class CommentsHistoryUpdaterTest extends \PHPUnit\Framework\TestCase
52
53
*/
53
54
private $ historyEntity ;
54
55
56
+ /**
57
+ * @var OrderStatusHistoryRepositoryInterface|MockObject
58
+ */
59
+ private $ historyRepository ;
60
+
55
61
/**
56
62
* @inheritdoc
57
63
*/
@@ -64,6 +70,9 @@ protected function setUp()
64
70
->setMethods (['create ' , 'save ' ])
65
71
->getMock ();
66
72
73
+ $ this ->historyRepository = $ this ->getMockBuilder (OrderStatusHistoryRepositoryInterface::class)
74
+ ->getMockForAbstractClass ();
75
+
67
76
$ this ->caseEntity = $ this ->getMockBuilder (CaseInterface::class)
68
77
->disableOriginalConstructor ()
69
78
->setMethods (['getOrderId ' ])
@@ -72,7 +81,8 @@ protected function setUp()
72
81
$ this ->initCommentMock ();
73
82
74
83
$ this ->updater = $ objectManager ->getObject (CommentsHistoryUpdater::class, [
75
- 'historyFactory ' => $ this ->historyFactory
84
+ 'historyFactory ' => $ this ->historyFactory ,
85
+ 'historyRepository ' => $ this ->historyRepository
76
86
]);
77
87
}
78
88
@@ -88,12 +98,12 @@ public function testAddCommentWithException()
88
98
->method ('getOrderId ' )
89
99
->willReturn (self ::$ orderId );
90
100
91
- $ this ->historyEntity ->expects (self ::any ())
92
- ->method ('setStatus ' )
101
+ $ this ->historyEntity ->method ('setStatus ' )
93
102
->with ('' )
94
103
->willReturnSelf ();
95
- $ this ->historyEntity ->expects (self ::once ())
104
+ $ this ->historyRepository ->expects (self ::once ())
96
105
->method ('save ' )
106
+ ->with ($ this ->historyEntity )
97
107
->willThrowException (new \Exception ('Cannot save comment message. ' ));
98
108
99
109
$ this ->updater ->addComment ($ this ->caseEntity , __ (self ::$ message ));
@@ -110,12 +120,12 @@ public function testAddComment()
110
120
->method ('getOrderId ' )
111
121
->willReturn (self ::$ orderId );
112
122
113
- $ this ->historyEntity ->expects (self ::any ())
114
- ->method ('setStatus ' )
123
+ $ this ->historyEntity ->method ('setStatus ' )
115
124
->with (self ::$ status )
116
125
->willReturnSelf ();
117
- $ this ->historyEntity ->expects (self ::once ())
126
+ $ this ->historyRepository ->expects (self ::once ())
118
127
->method ('save ' )
128
+ ->with ($ this ->historyEntity )
119
129
->willReturnSelf ();
120
130
121
131
$ this ->updater ->addComment ($ this ->caseEntity , __ (self ::$ message ), self ::$ status );
@@ -150,20 +160,16 @@ private function initCommentMock()
150
160
->setMethods (['setParentId ' , 'setComment ' , 'setEntityName ' , 'save ' ])
151
161
->getMockForAbstractClass ();
152
162
153
- $ this ->historyFactory ->expects (self ::any ())
154
- ->method ('create ' )
163
+ $ this ->historyFactory ->method ('create ' )
155
164
->willReturn ($ this ->historyEntity );
156
165
157
- $ this ->historyEntity ->expects (self ::any ())
158
- ->method ('setParentId ' )
166
+ $ this ->historyEntity ->method ('setParentId ' )
159
167
->with (self ::$ orderId )
160
168
->willReturnSelf ();
161
- $ this ->historyEntity ->expects (self ::any ())
162
- ->method ('setComment ' )
169
+ $ this ->historyEntity ->method ('setComment ' )
163
170
->with (self ::$ message )
164
171
->willReturnSelf ();
165
- $ this ->historyEntity ->expects (self ::any ())
166
- ->method ('setEntityName ' )
172
+ $ this ->historyEntity ->method ('setEntityName ' )
167
173
->with ('order ' )
168
174
->willReturnSelf ();
169
175
}
0 commit comments