@@ -283,6 +283,11 @@ public function testCollectRates()
283
283
$ this ->httpResponse ->method ('getBody ' )
284
284
->willReturn ($ responseXml );
285
285
286
+ $ this ->coreDateMock ->method ('date ' )
287
+ ->willReturnCallback (function () {
288
+ return date (\DATE_RFC3339 );
289
+ });
290
+
286
291
$ request = $ this ->objectManager ->getObject (RateRequest::class, $ requestData );
287
292
288
293
$ reflectionClass = new \ReflectionObject ($ this ->httpClient );
@@ -516,68 +521,104 @@ public function dhlProductsDataProvider() : array
516
521
}
517
522
518
523
/**
519
- * Tests that the built message reference string is of the appropriate format.
524
+ * Tests that the built MessageReference string is of the appropriate format.
520
525
*
521
- * @expectedException \Magento\Framework\Exception\LocalizedException
522
- * @expectedExceptionMessage Invalid service prefix
526
+ * @dataProvider buildMessageReferenceDataProvider
527
+ * @param $servicePrefix
523
528
* @throws \ReflectionException
524
529
*/
525
- public function testBuildMessageReference ()
530
+ public function testBuildMessageReference ($ servicePrefix )
526
531
{
527
532
$ method = new \ReflectionMethod ($ this ->model , 'buildMessageReference ' );
528
533
$ method ->setAccessible (true );
529
534
530
- $ constPrefixQuote = new \ReflectionClassConstant ($ this ->model , 'SERVICE_PREFIX_QUOTE ' );
531
- $ constPrefixShipval = new \ReflectionClassConstant ($ this ->model , 'SERVICE_PREFIX_SHIPVAL ' );
532
- $ constPrefixTracking = new \ReflectionClassConstant ($ this ->model , 'SERVICE_PREFIX_TRACKING ' );
533
-
534
- $ msgRefQuote = $ method ->invoke ($ this ->model , $ constPrefixQuote ->getValue ());
535
- self ::assertGreaterThanOrEqual (28 , strlen ($ msgRefQuote ));
536
- self ::assertLessThanOrEqual (32 , strlen ($ msgRefQuote ));
535
+ $ messageReference = $ method ->invoke ($ this ->model , $ servicePrefix );
536
+ $ this ->assertGreaterThanOrEqual (28 , strlen ($ messageReference ));
537
+ $ this ->assertLessThanOrEqual (32 , strlen ($ messageReference ));
538
+ }
537
539
538
- $ msgRefShip = $ method ->invoke ($ this ->model , $ constPrefixShipval ->getValue ());
539
- self ::assertGreaterThanOrEqual (28 , strlen ($ msgRefShip ));
540
- self ::assertLessThanOrEqual (32 , strlen ($ msgRefShip ));
540
+ /**
541
+ * @return array
542
+ */
543
+ public function buildMessageReferenceDataProvider ()
544
+ {
545
+ return [
546
+ 'quote_prefix ' => ['QUOT ' ],
547
+ 'shipval_prefix ' => ['SHIP ' ],
548
+ 'tracking_prefix ' => ['TRCK ' ]
549
+ ];
550
+ }
541
551
542
- $ msgRefTrack = $ method ->invoke ($ this ->model , $ constPrefixTracking ->getValue ());
543
- self ::assertGreaterThanOrEqual (28 , strlen ($ msgRefTrack ));
544
- self ::assertLessThanOrEqual (32 , strlen ($ msgRefTrack ));
552
+ /**
553
+ * Tests that an exception is thrown when an invalid service prefix is provided.
554
+ *
555
+ * @expectedException \Magento\Framework\Exception\LocalizedException
556
+ * @expectedExceptionMessage Invalid service prefix
557
+ */
558
+ public function testBuildMessageReferenceInvalidPrefix ()
559
+ {
560
+ $ method = new \ReflectionMethod ($ this ->model , 'buildMessageReference ' );
561
+ $ method ->setAccessible (true );
545
562
546
- $ method ->invoke ($ this ->model , 'TEST ' );
563
+ $ method ->invoke ($ this ->model , 'INVALID ' );
547
564
}
548
565
549
566
/**
550
567
* Tests that the built software name string is of the appropriate format.
551
568
*
569
+ * @dataProvider buildSoftwareNameDataProvider
570
+ * @param $productName
552
571
* @throws \ReflectionException
553
572
*/
554
- public function testBuildSoftwareName ()
573
+ public function testBuildSoftwareName ($ productName )
555
574
{
556
575
$ method = new \ReflectionMethod ($ this ->model , 'buildSoftwareName ' );
557
576
$ method ->setAccessible (true );
558
577
559
- $ name = $ method ->invoke ($ this ->model );
560
- self ::assertLessThanOrEqual (30 , $ name );
578
+ $ this ->productMetadataMock ->method ('getName ' )->willReturn ($ productName );
561
579
562
- $ nameExceedsLength = $ method ->invoke ($ this ->model );
563
- self ::assertLessThanOrEqual (30 , $ nameExceedsLength );
580
+ $ softwareName = $ method ->invoke ($ this ->model );
581
+ $ this ->assertLessThanOrEqual (30 , strlen ($ softwareName ));
582
+ }
583
+
584
+ /**
585
+ * @return array
586
+ */
587
+ public function buildSoftwareNameDataProvider ()
588
+ {
589
+ return [
590
+ 'valid_length ' => ['Magento ' ],
591
+ 'exceeds_length ' => ['Product_Name_Longer_Than_30_Char ' ]
592
+ ];
564
593
}
565
594
566
595
/**
567
596
* Tests that the built software version string is of the appropriate format.
568
597
*
598
+ * @dataProvider buildSoftwareVersionProvider
599
+ * @param $productVersion
569
600
* @throws \ReflectionException
570
601
*/
571
- public function testBuildSoftwareVersion ()
602
+ public function testBuildSoftwareVersion ($ productVersion )
572
603
{
573
604
$ method = new \ReflectionMethod ($ this ->model , 'buildSoftwareVersion ' );
574
605
$ method ->setAccessible (true );
575
606
576
- $ version = $ method ->invoke ($ this ->model );
577
- self ::assertLessThanOrEqual (10 , strlen ($ version ));
607
+ $ this ->productMetadataMock ->method ('getVersion ' )->willReturn ($ productVersion );
578
608
579
- $ versionExceedsLength = $ method ->invoke ($ this ->model );
580
- self ::assertLessThanOrEqual (10 , strlen ($ versionExceedsLength ));
609
+ $ softwareVersion = $ method ->invoke ($ this ->model );
610
+ $ this ->assertLessThanOrEqual (10 , strlen ($ softwareVersion ));
611
+ }
612
+
613
+ /**
614
+ * @return array
615
+ */
616
+ public function buildSoftwareVersionProvider ()
617
+ {
618
+ return [
619
+ 'valid_length ' => ['2.3.1 ' ],
620
+ 'exceeds_length ' => ['dev-MC-1000 ' ]
621
+ ];
581
622
}
582
623
583
624
/**
@@ -725,21 +766,6 @@ private function getCarrierHelper(): CarrierHelper
725
766
return $ carrierHelper ;
726
767
}
727
768
728
- /**
729
- * @return MockObject
730
- */
731
- private function getCoreDate (): MockObject
732
- {
733
- $ coreDate = $ this ->getMockBuilder (\Magento \Framework \Stdlib \DateTime \DateTime::class)
734
- ->disableOriginalConstructor ()
735
- ->getMock ();
736
- $ coreDate ->method ('date ' )->willReturnCallback (function () {
737
- return date (\DATE_RFC3339 );
738
- });
739
-
740
- return $ coreDate ;
741
- }
742
-
743
769
/**
744
770
* @return MockObject
745
771
*/
@@ -762,24 +788,4 @@ private function getHttpClientFactory(): MockObject
762
788
763
789
return $ httpClientFactory ;
764
790
}
765
-
766
- /**
767
- * @return MockObject
768
- */
769
- private function getProductMetadata (): MockObject
770
- {
771
- $ productMetadata = $ this ->createMock (\Magento \Framework \App \ProductMetadata::class);
772
-
773
- $ productMetadata ->method ('getName ' )->willReturnOnConsecutiveCalls (
774
- 'Magento ' ,
775
- str_pad ('Magento ' , 24 , '_ ' )
776
- );
777
-
778
- $ productMetadata ->method ('getVersion ' )->willReturnOnConsecutiveCalls (
779
- '2.3.1 ' ,
780
- 'dev-MC-1000 '
781
- );
782
-
783
- return $ productMetadata ;
784
- }
785
791
}
0 commit comments