@@ -80,6 +80,46 @@ public function testProcessIpnRequestFullRefund()
8080 $ this ->assertEmpty ($ order ->getTotalOfflineRefunded ());
8181 }
8282
83+ /**
84+ * Refund full order amount by Paypal Express IPN message service with concurrent requests.
85+ *
86+ * @magentoDataFixture Magento/Paypal/_files/order_express_with_invoice_and_shipping.php
87+ * @magentoConfigFixture current_store payment/paypal_express/active 1
88+ * @magentoConfigFixture current_store paypal/general/merchant_country US
89+ */
90+ public function testProcessIpnRequestFullRefundConcurrent ()
91+ {
92+ $ ipnData = require __DIR__ . '/../_files/ipn_refund.php ' ;
93+ $ ipnFactory = $ this ->_objectManager ->create (IpnFactory::class);
94+ $ ipnModel = $ ipnFactory ->create (
95+ [
96+ 'data ' => $ ipnData ,
97+ 'curlFactory ' => $ this ->_createMockedHttpAdapter ()
98+ ]
99+ );
100+
101+ $ ipnModel ->processIpnRequest ();
102+ $ ipnModel ->processIpnRequest ();
103+
104+ $ order = $ this ->_objectManager ->create (Order::class);
105+ $ order ->loadByIncrementId ('100000001 ' );
106+
107+ $ creditmemoItems = $ order ->getCreditmemosCollection ()->getItems ();
108+ $ creditmemo = current ($ creditmemoItems );
109+
110+ $ this ->assertEquals (Order::STATE_CLOSED , $ order ->getState ()) ;
111+ $ this ->assertCount (1 , $ creditmemoItems );
112+ $ this ->assertEquals (Creditmemo::STATE_REFUNDED , $ creditmemo ->getState ());
113+ $ this ->assertEquals (10 , $ order ->getSubtotalRefunded ());
114+ $ this ->assertEquals (10 , $ order ->getBaseSubtotalRefunded ());
115+ $ this ->assertEquals (20 , $ order ->getShippingRefunded ());
116+ $ this ->assertEquals (20 , $ order ->getBaseShippingRefunded ());
117+ $ this ->assertEquals (30 , $ order ->getTotalRefunded ());
118+ $ this ->assertEquals (30 , $ order ->getBaseTotalRefunded ());
119+ $ this ->assertEquals (30 , $ order ->getTotalOnlineRefunded ());
120+ $ this ->assertEmpty ($ order ->getTotalOfflineRefunded ());
121+ }
122+
83123 /**
84124 * Partial refund of order amount by Paypal Express IPN message service.
85125 *
@@ -253,11 +293,11 @@ protected function _createMockedHttpAdapter()
253293 $ factory = $ this ->createPartialMock (\Magento \Framework \HTTP \Adapter \CurlFactory::class, ['create ' ]);
254294 $ adapter = $ this ->createPartialMock (\Magento \Framework \HTTP \Adapter \Curl::class, ['read ' , 'write ' ]);
255295
256- $ adapter ->expects ($ this ->once ())->method ('read ' )->with ()->willReturn ("\nVERIFIED " );
296+ $ adapter ->expects ($ this ->any ())->method ('read ' )->with ()->willReturn ("\nVERIFIED " );
257297
258- $ adapter ->expects ($ this ->once ())->method ('write ' );
298+ $ adapter ->expects ($ this ->any ())->method ('write ' );
259299
260- $ factory ->expects ($ this ->once ())->method ('create ' )->with ()->willReturn ($ adapter );
300+ $ factory ->expects ($ this ->any ())->method ('create ' )->with ()->willReturn ($ adapter );
261301 return $ factory ;
262302 }
263303
0 commit comments