@@ -442,10 +442,8 @@ private function getExpectedLabelRequestXml(
442
442
*/
443
443
public function testCollectRates ()
444
444
{
445
- $ requestData = $ this ->getRequestData ();
446
445
$ this ->setNextResponse (__DIR__ . '/../_files/dhl_quote_response.xml ' );
447
- /** @var RateRequest $request */
448
- $ request = Bootstrap::getObjectManager ()->create (RateRequest::class, $ requestData );
446
+ $ request = $ this ->createRequest ();
449
447
$ expectedRates = [
450
448
['carrier ' => 'dhl ' , 'carrier_title ' => 'DHL Title ' , 'cost ' => 45.85 , 'method ' => 'E ' , 'price ' => 45.85 ],
451
449
['carrier ' => 'dhl ' , 'carrier_title ' => 'DHL Title ' , 'cost ' => 35.26 , 'method ' => 'Q ' , 'price ' => 35.26 ],
@@ -480,11 +478,9 @@ public function testCollectRates()
480
478
*/
481
479
public function testCollectRatesWithoutDimensions (?string $ size , ?string $ height , ?string $ width , ?string $ depth )
482
480
{
483
- $ requestData = $ this ->getRequestData ();
484
481
$ this ->setDhlConfig (['size ' => $ size , 'height ' => $ height , 'width ' => $ width , 'depth ' => $ depth ]);
485
482
486
- /** @var RateRequest $request */
487
- $ request = Bootstrap::getObjectManager ()->create (RateRequest::class, $ requestData );
483
+ $ request = $ this ->createRequest ();
488
484
$ this ->dhlCarrier = Bootstrap::getObjectManager ()->create (Carrier::class);
489
485
$ this ->dhlCarrier ->collectRates ($ request )->getAllRates ();
490
486
@@ -504,15 +500,13 @@ public function testCollectRatesWithoutDimensions(?string $size, ?string $height
504
500
public function testGetRatesWithHttpException (): void
505
501
{
506
502
$ this ->setDhlConfig (['showmethod ' => 1 ]);
507
- $ requestData = $ this ->getRequestData ();
508
503
$ deferredResponse = $ this ->getMockBuilder (HttpResponseDeferredInterface::class)
509
504
->onlyMethods (['get ' ])
510
505
->getMockForAbstractClass ();
511
506
$ exception = new HttpException ('Exception message ' );
512
507
$ deferredResponse ->method ('get ' )->willThrowException ($ exception );
513
508
$ this ->httpClient ->setDeferredResponseMock ($ deferredResponse );
514
- /** @var RateRequest $request */
515
- $ request = Bootstrap::getObjectManager ()->create (RateRequest::class, $ requestData );
509
+ $ request = $ this ->createRequest ();
516
510
$ this ->dhlCarrier = Bootstrap::getObjectManager ()->create (Carrier::class);
517
511
$ resultRate = $ this ->dhlCarrier ->collectRates ($ request )->getAllRates ()[0 ];
518
512
$ error = Bootstrap::getObjectManager ()->get (Error::class);
@@ -591,18 +585,15 @@ private function setDhlConfig(array $params)
591
585
public function testCollectRatesWithFreeShipping (array $ addRequestData , bool $ freeShippingExpects ): void
592
586
{
593
587
$ this ->setNextResponse (__DIR__ . '/../_files/dhl_quote_response.xml ' );
594
-
595
- $ requestData = $ this ->getRequestData ();
596
- $ requestData ['data ' ] += $ addRequestData ;
597
- /** @var RateRequest $request */
598
- $ request = Bootstrap::getObjectManager ()->create (RateRequest::class, $ requestData );
588
+ $ request = $ this ->createRequest ($ addRequestData );
599
589
600
590
$ actualRates = $ this ->dhlCarrier ->collectRates ($ request )->getAllRates ();
601
591
$ freeRateExists = false ;
602
- foreach ($ actualRates as $ i => $ actualRate ) {
592
+ foreach ($ actualRates as $ actualRate ) {
603
593
$ actualRate = $ actualRate ->getData ();
604
- if ($ actualRate ['method ' ] === 'P ' && $ actualRate ['price ' ] === 0.0 ) {
594
+ if ($ actualRate ['method ' ] === 'P ' && ( float ) $ actualRate ['price ' ] === 0.0 ) {
605
595
$ freeRateExists = true ;
596
+ break ;
606
597
}
607
598
}
608
599
@@ -616,15 +607,15 @@ public function collectRatesWithFreeShippingDataProvider(): array
616
607
{
617
608
return [
618
609
[
619
- ['base_subtotal_incl_tax ' => 25 , 'base_subtotal_with_discount_incl_tax ' => 22 ],
610
+ ['package_value ' => 25 , 'package_value_with_discount ' => 22 ],
620
611
false
621
612
],
622
613
[
623
- ['base_subtotal_incl_tax ' => 25 , 'base_subtotal_with_discount_incl_tax ' => 25 ],
614
+ ['package_value ' => 25 , 'package_value_with_discount ' => 25 ],
624
615
true
625
616
],
626
617
[
627
- ['base_subtotal_incl_tax ' => 28 , 'base_subtotal_with_discount_incl_tax ' => 25 ],
618
+ ['package_value ' => 28 , 'package_value_with_discount ' => 25 ],
628
619
true
629
620
],
630
621
];
@@ -638,47 +629,45 @@ public function collectRatesWithFreeShippingDataProvider(): array
638
629
private function getRequestData (): array
639
630
{
640
631
return [
641
- 'data ' => [
642
- 'dest_country_id ' => 'DE ' ,
643
- 'dest_region_id ' => '82 ' ,
644
- 'dest_region_code ' => 'BER ' ,
645
- 'dest_street ' => 'Turmstraße 17 ' ,
646
- 'dest_city ' => 'Berlin ' ,
647
- 'dest_postcode ' => '10559 ' ,
648
- 'dest_postal ' => '10559 ' ,
649
- 'package_value ' => '5 ' ,
650
- 'package_value_with_discount ' => '5 ' ,
651
- 'package_weight ' => '8.2657 ' ,
652
- 'package_qty ' => '1 ' ,
653
- 'package_physical_value ' => '5 ' ,
654
- 'free_method_weight ' => '5 ' ,
655
- 'store_id ' => '1 ' ,
656
- 'website_id ' => '1 ' ,
657
- 'free_shipping ' => '0 ' ,
658
- 'limit_carrier ' => null ,
659
- 'base_subtotal_incl_tax ' => '5 ' ,
660
- 'orig_country_id ' => 'US ' ,
661
- 'orig_region_id ' => '12 ' ,
662
- 'orig_city ' => 'Fremont ' ,
663
- 'orig_postcode ' => '94538 ' ,
664
- 'dhl_id ' => 'MAGEN_8501 ' ,
665
- 'dhl_password ' => 'QR2GO1U74X ' ,
666
- 'dhl_account ' => '799909537 ' ,
667
- 'dhl_shipping_intl_key ' => '54233F2B2C4E5C4B4C5E5A59565530554B405641475D5659 ' ,
668
- 'girth ' => null ,
669
- 'height ' => null ,
670
- 'length ' => null ,
671
- 'width ' => null ,
672
- 'weight ' => 1 ,
673
- 'dhl_shipment_type ' => 'P ' ,
674
- 'dhl_duitable ' => 0 ,
675
- 'dhl_duty_payment_type ' => 'R ' ,
676
- 'dhl_content_desc ' => 'Big Box ' ,
677
- 'limit_method ' => 'IE ' ,
678
- 'ship_date ' => '2014-01-09 ' ,
679
- 'action ' => 'RateEstimate ' ,
680
- 'all_items ' => [],
681
- ]
632
+ 'dest_country_id ' => 'DE ' ,
633
+ 'dest_region_id ' => '82 ' ,
634
+ 'dest_region_code ' => 'BER ' ,
635
+ 'dest_street ' => 'Turmstraße 17 ' ,
636
+ 'dest_city ' => 'Berlin ' ,
637
+ 'dest_postcode ' => '10559 ' ,
638
+ 'dest_postal ' => '10559 ' ,
639
+ 'package_value ' => '5 ' ,
640
+ 'package_value_with_discount ' => '5 ' ,
641
+ 'package_weight ' => '8.2657 ' ,
642
+ 'package_qty ' => '1 ' ,
643
+ 'package_physical_value ' => '5 ' ,
644
+ 'free_method_weight ' => '5 ' ,
645
+ 'store_id ' => '1 ' ,
646
+ 'website_id ' => '1 ' ,
647
+ 'free_shipping ' => '0 ' ,
648
+ 'limit_carrier ' => null ,
649
+ 'base_subtotal_incl_tax ' => '5 ' ,
650
+ 'orig_country_id ' => 'US ' ,
651
+ 'orig_region_id ' => '12 ' ,
652
+ 'orig_city ' => 'Fremont ' ,
653
+ 'orig_postcode ' => '94538 ' ,
654
+ 'dhl_id ' => 'MAGEN_8501 ' ,
655
+ 'dhl_password ' => 'QR2GO1U74X ' ,
656
+ 'dhl_account ' => '799909537 ' ,
657
+ 'dhl_shipping_intl_key ' => '54233F2B2C4E5C4B4C5E5A59565530554B405641475D5659 ' ,
658
+ 'girth ' => null ,
659
+ 'height ' => null ,
660
+ 'length ' => null ,
661
+ 'width ' => null ,
662
+ 'weight ' => 1 ,
663
+ 'dhl_shipment_type ' => 'P ' ,
664
+ 'dhl_duitable ' => 0 ,
665
+ 'dhl_duty_payment_type ' => 'R ' ,
666
+ 'dhl_content_desc ' => 'Big Box ' ,
667
+ 'limit_method ' => 'IE ' ,
668
+ 'ship_date ' => '2014-01-09 ' ,
669
+ 'action ' => 'RateEstimate ' ,
670
+ 'all_items ' => [],
682
671
];
683
672
}
684
673
@@ -700,4 +689,20 @@ private function setNextResponse(string $file): void
700
689
array_fill (0 , Carrier::UNAVAILABLE_DATE_LOOK_FORWARD + 1 , $ response )
701
690
);
702
691
}
692
+
693
+ /**
694
+ * Create Rate Request
695
+ *
696
+ * @param array $addRequestData
697
+ * @return RateRequest
698
+ */
699
+ private function createRequest (array $ addRequestData = []): RateRequest
700
+ {
701
+ $ requestData = $ this ->getRequestData ();
702
+ if (!empty ($ addRequestData )) {
703
+ $ requestData = array_merge ($ requestData , $ addRequestData );
704
+ }
705
+
706
+ return Bootstrap::getObjectManager ()->create (RateRequest::class, ['data ' => $ requestData ]);
707
+ }
703
708
}
0 commit comments