@@ -26,6 +26,11 @@ class CleanExpiredOrdersTest extends \PHPUnit\Framework\TestCase
26
26
*/
27
27
protected $ orderCollectionMock ;
28
28
29
+ /**
30
+ * @var \PHPUnit_Framework_MockObject_MockObject
31
+ */
32
+ private $ orderManagementMock ;
33
+
29
34
/**
30
35
* @var ObjectManager
31
36
*/
@@ -44,10 +49,12 @@ protected function setUp()
44
49
['create ' ]
45
50
);
46
51
$ this ->orderCollectionMock = $ this ->createMock (\Magento \Sales \Model \ResourceModel \Order \Collection::class);
52
+ $ this ->orderManagementMock = $ this ->createMock (\Magento \Sales \Api \OrderManagementInterface::class);
47
53
48
54
$ this ->model = new CleanExpiredOrders (
49
55
$ this ->storesConfigMock ,
50
- $ this ->collectionFactoryMock
56
+ $ this ->collectionFactoryMock ,
57
+ $ this ->orderManagementMock
51
58
);
52
59
}
53
60
@@ -64,8 +71,11 @@ public function testExecute()
64
71
$ this ->collectionFactoryMock ->expects ($ this ->exactly (2 ))
65
72
->method ('create ' )
66
73
->willReturn ($ this ->orderCollectionMock );
74
+ $ this ->orderCollectionMock ->expects ($ this ->exactly (2 ))
75
+ ->method ('getAllIds ' )
76
+ ->willReturn ([1 , 2 ]);
67
77
$ this ->orderCollectionMock ->expects ($ this ->exactly (4 ))->method ('addFieldToFilter ' );
68
- $ this ->orderCollectionMock ->expects ($ this ->exactly (4 ))->method ('walk ' );
78
+ $ this ->orderManagementMock ->expects ($ this ->exactly (4 ))->method ('cancel ' );
69
79
70
80
$ selectMock = $ this ->createMock (\Magento \Framework \DB \Select::class);
71
81
$ selectMock ->expects ($ this ->exactly (2 ))->method ('where ' )->willReturnSelf ();
@@ -92,14 +102,18 @@ public function testExecuteWithException()
92
102
$ this ->collectionFactoryMock ->expects ($ this ->once ())
93
103
->method ('create ' )
94
104
->willReturn ($ this ->orderCollectionMock );
105
+ $ this ->orderCollectionMock ->expects ($ this ->once ())
106
+ ->method ('getAllIds ' )
107
+ ->willReturn ([1 ]);
95
108
$ this ->orderCollectionMock ->expects ($ this ->exactly (2 ))->method ('addFieldToFilter ' );
109
+ $ this ->orderManagementMock ->expects ($ this ->once ())->method ('cancel ' );
96
110
97
111
$ selectMock = $ this ->createMock (\Magento \Framework \DB \Select::class);
98
112
$ selectMock ->expects ($ this ->once ())->method ('where ' )->willReturnSelf ();
99
113
$ this ->orderCollectionMock ->expects ($ this ->once ())->method ('getSelect ' )->willReturn ($ selectMock );
100
114
101
- $ this ->orderCollectionMock ->expects ($ this ->once ())
102
- ->method ('walk ' )
115
+ $ this ->orderManagementMock ->expects ($ this ->once ())
116
+ ->method ('cancel ' )
103
117
->willThrowException (new \Exception ($ exceptionMessage ));
104
118
105
119
$ this ->model ->execute ();
0 commit comments