20
20
use Magento \Payment \Model \IframeConfigProvider ;
21
21
use Magento \Quote \Api \CartManagementInterface ;
22
22
use Magento \Quote \Model \Quote ;
23
+ use Magento \Framework \Exception \LocalizedException ;
23
24
24
25
/**
25
26
* Class PlaceTest
@@ -94,6 +95,11 @@ class PlaceTest extends \PHPUnit_Framework_TestCase
94
95
*/
95
96
protected $ quoteMock ;
96
97
98
+ /**
99
+ * @var \PHPUnit_Framework_MockObject_MockObject
100
+ */
101
+ private $ loggerMock ;
102
+
97
103
/**
98
104
* @var CheckoutSession|\PHPUnit_Framework_MockObject_MockObject
99
105
*/
@@ -152,6 +158,9 @@ protected function setUp()
152
158
->getMockBuilder (\Magento \Framework \App \Response \Http::class)
153
159
->disableOriginalConstructor ()
154
160
->getMockForAbstractClass ();
161
+ $ this ->loggerMock = $ this
162
+ ->getMockBuilder (\Psr \Log \LoggerInterface::class)
163
+ ->getMock ();
155
164
156
165
$ this ->objectManager = new ObjectManager ($ this );
157
166
$ this ->placeOrderController = $ this ->objectManager ->getObject (
@@ -165,6 +174,7 @@ protected function setUp()
165
174
'cartManagement ' => $ this ->cartManagementMock ,
166
175
'onepageCheckout ' => $ this ->onepageCheckout ,
167
176
'jsonHelper ' => $ this ->jsonHelperMock ,
177
+ 'logger ' => $ this ->loggerMock ,
168
178
]
169
179
);
170
180
}
@@ -214,13 +224,15 @@ public function testExecute(
214
224
* @param $controller
215
225
* @param $quoteId
216
226
* @param $result
227
+ * @param \Exception $exception Exception to check
217
228
* @dataProvider textExecuteFailedPlaceOrderDataProvider
218
229
*/
219
230
public function testExecuteFailedPlaceOrder (
220
231
$ paymentMethod ,
221
232
$ controller ,
222
233
$ quoteId ,
223
- $ result
234
+ $ result ,
235
+ $ exception
224
236
) {
225
237
$ this ->requestMock ->expects ($ this ->at (0 ))
226
238
->method ('getParam ' )
@@ -238,7 +250,11 @@ public function testExecuteFailedPlaceOrder(
238
250
239
251
$ this ->cartManagementMock ->expects ($ this ->once ())
240
252
->method ('placeOrder ' )
241
- ->willThrowException (new \Exception ());
253
+ ->willThrowException ($ exception );
254
+
255
+ $ this ->loggerMock ->expects ($ this ->once ())
256
+ ->method ('critical ' )
257
+ ->with ($ exception );
242
258
243
259
$ this ->jsonHelperMock ->expects ($ this ->any ())
244
260
->method ('jsonEncode ' )
@@ -278,19 +294,35 @@ public function textExecuteDataProvider()
278
294
*/
279
295
public function textExecuteFailedPlaceOrderDataProvider ()
280
296
{
281
- $ objectFailed = new \Magento \Framework \DataObject ();
282
- $ objectFailed ->setData ('error ' , true );
283
- $ objectFailed ->setData (
284
- 'error_messages ' ,
285
- __ ('An error occurred on the server. Please try to place the order again. ' )
297
+ $ objectFailed1 = new \Magento \Framework \DataObject (
298
+ [
299
+ 'error ' => true ,
300
+ 'error_messages ' => __ ('An error occurred on the server. Please try to place the order again. ' )
301
+ ]
302
+ );
303
+ $ generalException = new \Exception ('Exception logging will save the world! ' );
304
+ $ localizedException = new LocalizedException (__ ('Electronic payments save the trees. ' ));
305
+ $ objectFailed2 = new \Magento \Framework \DataObject (
306
+ [
307
+ 'error ' => true ,
308
+ 'error_messages ' => $ localizedException ->getMessage ()
309
+ ]
286
310
);
287
311
288
312
return [
289
313
[
290
314
['method ' => 'authorizenet_directpost ' ],
291
315
IframeConfigProvider::CHECKOUT_IDENTIFIER ,
292
316
1 ,
293
- $ objectFailed
317
+ $ objectFailed1 ,
318
+ $ generalException ,
319
+ ],
320
+ [
321
+ ['method ' => 'authorizenet_directpost ' ],
322
+ IframeConfigProvider::CHECKOUT_IDENTIFIER ,
323
+ 1 ,
324
+ $ objectFailed2 ,
325
+ $ localizedException ,
294
326
],
295
327
];
296
328
}
0 commit comments