7
7
8
8
namespace Magento \Sales \Test \Unit \Model \Order \Invoice \Plugin ;
9
9
10
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
10
11
use Magento \Sales \Model \Order ;
11
12
use Magento \Sales \Model \Order \Address ;
12
13
use Magento \Sales \Model \Order \Invoice ;
@@ -34,17 +35,27 @@ class AddressUpdateTest extends TestCase
34
35
*/
35
36
private $ attributeMock ;
36
37
38
+ /**
39
+ * @var MockObject
40
+ */
41
+ private $ globalConfigMock ;
42
+
37
43
protected function setUp (): void
38
44
{
39
45
$ this ->gripPoolMock = $ this ->createMock (GridPool::class);
40
46
$ this ->attributeMock = $ this ->createMock (Attribute::class);
47
+ $ this ->globalConfigMock = $ this ->createMock (ScopeConfigInterface::class);
41
48
$ this ->model = new AddressUpdate (
42
49
$ this ->gripPoolMock ,
43
- $ this ->attributeMock
50
+ $ this ->attributeMock ,
51
+ $ this ->globalConfigMock
44
52
);
45
53
}
46
54
47
- public function testAfterProcess ()
55
+ /**
56
+ * @dataProvider dataProvider
57
+ */
58
+ public function testAfterProcess ($ asyncReindexEnabled , $ expectedReindexCalledCount )
48
59
{
49
60
$ billingId = 100 ;
50
61
$ shippingId = 200 ;
@@ -69,7 +80,9 @@ public function testAfterProcess()
69
80
$ orderMock ->expects ($ this ->once ())->method ('getBillingAddress ' )->willReturn ($ billingMock );
70
81
$ orderMock ->expects ($ this ->once ())->method ('getShippingAddress ' )->willReturn ($ shippingMock );
71
82
$ orderMock ->expects ($ this ->once ())->method ('getInvoiceCollection ' )->willReturn ($ invoiceCollectionMock );
72
- $ orderMock ->expects ($ this ->once ())->method ('getId ' )->willReturn ($ orderId );
83
+ $ orderMock ->expects ($ this ->exactly ($ expectedReindexCalledCount ))
84
+ ->method ('getId ' )
85
+ ->willReturn ($ orderId );
73
86
74
87
$ invoiceMock ->expects ($ this ->once ())->method ('getBillingAddressId ' )->willReturn (null );
75
88
$ invoiceMock ->expects ($ this ->once ())->method ('getShippingAddressId ' )->willReturn (null );
@@ -81,12 +94,34 @@ public function testAfterProcess()
81
94
->with ($ invoiceMock , ['billing_address_id ' , 'shipping_address_id ' ])
82
95
->willReturnSelf ();
83
96
84
- $ this ->gripPoolMock ->expects ($ this ->once ())->method ('refreshByOrderId ' )->with ($ orderId )->willReturnSelf ();
97
+ $ this ->gripPoolMock ->expects ($ this ->exactly ($ expectedReindexCalledCount ))
98
+ ->method ('refreshByOrderId ' )
99
+ ->with ($ orderId )
100
+ ->willReturnSelf ();
101
+
102
+ $ this ->globalConfigMock ->expects ($ this ->once ())
103
+ ->method ('getValue ' )
104
+ ->with ('dev/grid/async_indexing ' )
105
+ ->willReturn ($ asyncReindexEnabled );
85
106
86
107
$ this ->model ->afterProcess (
87
108
$ this ->createMock (\Magento \Sales \Model \ResourceModel \Order \Handler \Address::class),
88
109
$ this ->createMock (\Magento \Sales \Model \ResourceModel \Order \Handler \Address::class),
89
110
$ orderMock
90
111
);
91
112
}
113
+
114
+ public function dataProvider ()
115
+ {
116
+ return [
117
+ 'Do not reindex when async is enabled ' => [
118
+ true ,
119
+ 0
120
+ ],
121
+ 'Reindex when async is disabled ' => [
122
+ false ,
123
+ 1
124
+ ],
125
+ ];
126
+ }
92
127
}
0 commit comments