@@ -442,10 +442,8 @@ private function getExpectedLabelRequestXml(
442442 */
443443 public function testCollectRates ()
444444 {
445- $ requestData = $ this ->getRequestData ();
446445 $ this ->setNextResponse (__DIR__ . '/../_files/dhl_quote_response.xml ' );
447- /** @var RateRequest $request */
448- $ request = Bootstrap::getObjectManager ()->create (RateRequest::class, $ requestData );
446+ $ request = $ this ->createRequest ();
449447 $ expectedRates = [
450448 ['carrier ' => 'dhl ' , 'carrier_title ' => 'DHL Title ' , 'cost ' => 45.85 , 'method ' => 'E ' , 'price ' => 45.85 ],
451449 ['carrier ' => 'dhl ' , 'carrier_title ' => 'DHL Title ' , 'cost ' => 35.26 , 'method ' => 'Q ' , 'price ' => 35.26 ],
@@ -480,11 +478,9 @@ public function testCollectRates()
480478 */
481479 public function testCollectRatesWithoutDimensions (?string $ size , ?string $ height , ?string $ width , ?string $ depth )
482480 {
483- $ requestData = $ this ->getRequestData ();
484481 $ this ->setDhlConfig (['size ' => $ size , 'height ' => $ height , 'width ' => $ width , 'depth ' => $ depth ]);
485482
486- /** @var RateRequest $request */
487- $ request = Bootstrap::getObjectManager ()->create (RateRequest::class, $ requestData );
483+ $ request = $ this ->createRequest ();
488484 $ this ->dhlCarrier = Bootstrap::getObjectManager ()->create (Carrier::class);
489485 $ this ->dhlCarrier ->collectRates ($ request )->getAllRates ();
490486
@@ -504,15 +500,13 @@ public function testCollectRatesWithoutDimensions(?string $size, ?string $height
504500 public function testGetRatesWithHttpException (): void
505501 {
506502 $ this ->setDhlConfig (['showmethod ' => 1 ]);
507- $ requestData = $ this ->getRequestData ();
508503 $ deferredResponse = $ this ->getMockBuilder (HttpResponseDeferredInterface::class)
509504 ->onlyMethods (['get ' ])
510505 ->getMockForAbstractClass ();
511506 $ exception = new HttpException ('Exception message ' );
512507 $ deferredResponse ->method ('get ' )->willThrowException ($ exception );
513508 $ this ->httpClient ->setDeferredResponseMock ($ deferredResponse );
514- /** @var RateRequest $request */
515- $ request = Bootstrap::getObjectManager ()->create (RateRequest::class, $ requestData );
509+ $ request = $ this ->createRequest ();
516510 $ this ->dhlCarrier = Bootstrap::getObjectManager ()->create (Carrier::class);
517511 $ resultRate = $ this ->dhlCarrier ->collectRates ($ request )->getAllRates ()[0 ];
518512 $ error = Bootstrap::getObjectManager ()->get (Error::class);
@@ -591,18 +585,15 @@ private function setDhlConfig(array $params)
591585 public function testCollectRatesWithFreeShipping (array $ addRequestData , bool $ freeShippingExpects ): void
592586 {
593587 $ 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 );
599589
600590 $ actualRates = $ this ->dhlCarrier ->collectRates ($ request )->getAllRates ();
601591 $ freeRateExists = false ;
602- foreach ($ actualRates as $ i => $ actualRate ) {
592+ foreach ($ actualRates as $ actualRate ) {
603593 $ actualRate = $ actualRate ->getData ();
604- if ($ actualRate ['method ' ] === 'P ' && $ actualRate ['price ' ] === 0.0 ) {
594+ if ($ actualRate ['method ' ] === 'P ' && ( float ) $ actualRate ['price ' ] === 0.0 ) {
605595 $ freeRateExists = true ;
596+ break ;
606597 }
607598 }
608599
@@ -616,15 +607,15 @@ public function collectRatesWithFreeShippingDataProvider(): array
616607 {
617608 return [
618609 [
619- ['base_subtotal_incl_tax ' => 25 , 'base_subtotal_with_discount_incl_tax ' => 22 ],
610+ ['package_value ' => 25 , 'package_value_with_discount ' => 22 ],
620611 false
621612 ],
622613 [
623- ['base_subtotal_incl_tax ' => 25 , 'base_subtotal_with_discount_incl_tax ' => 25 ],
614+ ['package_value ' => 25 , 'package_value_with_discount ' => 25 ],
624615 true
625616 ],
626617 [
627- ['base_subtotal_incl_tax ' => 28 , 'base_subtotal_with_discount_incl_tax ' => 25 ],
618+ ['package_value ' => 28 , 'package_value_with_discount ' => 25 ],
628619 true
629620 ],
630621 ];
@@ -638,47 +629,45 @@ public function collectRatesWithFreeShippingDataProvider(): array
638629 private function getRequestData (): array
639630 {
640631 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 ' => [],
682671 ];
683672 }
684673
@@ -700,4 +689,20 @@ private function setNextResponse(string $file): void
700689 array_fill (0 , Carrier::UNAVAILABLE_DATE_LOOK_FORWARD + 1 , $ response )
701690 );
702691 }
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+ }
703708}
0 commit comments