77
88namespace Magento \Sales \Test \Unit \Model \Order \Invoice \Plugin ;
99
10+ use Magento \Framework \App \Config \ScopeConfigInterface ;
1011use Magento \Sales \Model \Order ;
1112use Magento \Sales \Model \Order \Address ;
1213use Magento \Sales \Model \Order \Invoice ;
@@ -34,17 +35,27 @@ class AddressUpdateTest extends TestCase
3435 */
3536 private $ attributeMock ;
3637
38+ /**
39+ * @var MockObject
40+ */
41+ private $ globalConfigMock ;
42+
3743 protected function setUp (): void
3844 {
3945 $ this ->gripPoolMock = $ this ->createMock (GridPool::class);
4046 $ this ->attributeMock = $ this ->createMock (Attribute::class);
47+ $ this ->globalConfigMock = $ this ->createMock (ScopeConfigInterface::class);
4148 $ this ->model = new AddressUpdate (
4249 $ this ->gripPoolMock ,
43- $ this ->attributeMock
50+ $ this ->attributeMock ,
51+ $ this ->globalConfigMock
4452 );
4553 }
4654
47- public function testAfterProcess ()
55+ /**
56+ * @dataProvider dataProvider
57+ */
58+ public function testAfterProcess ($ asyncReindexEnabled , $ expectedReindexCalledCount )
4859 {
4960 $ billingId = 100 ;
5061 $ shippingId = 200 ;
@@ -69,7 +80,9 @@ public function testAfterProcess()
6980 $ orderMock ->expects ($ this ->once ())->method ('getBillingAddress ' )->willReturn ($ billingMock );
7081 $ orderMock ->expects ($ this ->once ())->method ('getShippingAddress ' )->willReturn ($ shippingMock );
7182 $ 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 );
7386
7487 $ invoiceMock ->expects ($ this ->once ())->method ('getBillingAddressId ' )->willReturn (null );
7588 $ invoiceMock ->expects ($ this ->once ())->method ('getShippingAddressId ' )->willReturn (null );
@@ -81,12 +94,34 @@ public function testAfterProcess()
8194 ->with ($ invoiceMock , ['billing_address_id ' , 'shipping_address_id ' ])
8295 ->willReturnSelf ();
8396
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 );
85106
86107 $ this ->model ->afterProcess (
87108 $ this ->createMock (\Magento \Sales \Model \ResourceModel \Order \Handler \Address::class),
88109 $ this ->createMock (\Magento \Sales \Model \ResourceModel \Order \Handler \Address::class),
89110 $ orderMock
90111 );
91112 }
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+ }
92127}
0 commit comments