File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,8 @@ public function __construct(
8787 public function cancel ($ id )
8888 {
8989 $ order = $ this ->orderRepository ->get ($ id );
90- if ((bool )$ order ->cancel ()) {
90+ if ($ order ->canCancel ()) {
91+ $ order ->cancel ();
9192 $ this ->orderRepository ->save ($ order );
9293 return true ;
9394 }
Original file line number Diff line number Diff line change @@ -163,9 +163,30 @@ public function testCancel()
163163 $ this ->orderMock ->expects ($ this ->once ())
164164 ->method ('cancel ' )
165165 ->willReturn ($ this ->orderMock );
166+ $ this ->orderMock ->expects ($ this ->once ())
167+ ->method ('canCancel ' )
168+ ->willReturn (true );
166169 $ this ->assertTrue ($ this ->orderService ->cancel (123 ));
167170 }
168171
172+ /**
173+ * test for Order::cancel() fail case
174+ */
175+ public function testCancelFailed ()
176+ {
177+ $ this ->orderRepositoryMock ->expects ($ this ->once ())
178+ ->method ('get ' )
179+ ->with (123 )
180+ ->willReturn ($ this ->orderMock );
181+ $ this ->orderMock ->expects ($ this ->never ())
182+ ->method ('cancel ' )
183+ ->willReturn ($ this ->orderMock );
184+ $ this ->orderMock ->expects ($ this ->once ())
185+ ->method ('canCancel ' )
186+ ->willReturn (false );
187+ $ this ->assertFalse ($ this ->orderService ->cancel (123 ));
188+ }
189+
169190 public function testGetCommentsList ()
170191 {
171192 $ this ->filterBuilderMock ->expects ($ this ->once ())
You can’t perform that action at this time.
0 commit comments