|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace EasyPost\Test; |
| 4 | + |
| 5 | +use EasyPost\EasyPostClient; |
| 6 | +use EasyPost\Exception\General\EndOfPaginationException; |
| 7 | +use Exception; |
| 8 | + |
| 9 | +class SmartRateTest extends \PHPUnit\Framework\TestCase |
| 10 | +{ |
| 11 | + private static EasyPostClient $client; |
| 12 | + |
| 13 | + /** |
| 14 | + * Setup the testing environment for this file. |
| 15 | + */ |
| 16 | + public static function setUpBeforeClass(): void |
| 17 | + { |
| 18 | + TestUtil::setupVcrTests(); |
| 19 | + self::$client = new EasyPostClient(getenv('EASYPOST_TEST_API_KEY')); |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * Cleanup the testing environment once finished. |
| 24 | + */ |
| 25 | + public static function tearDownAfterClass(): void |
| 26 | + { |
| 27 | + TestUtil::teardownVcrTests(); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Test that we retrieve SmartRates when provided a from/to zip and planned ship date. |
| 32 | + */ |
| 33 | + public function testRetrieveRecommendDate(): void |
| 34 | + { |
| 35 | + TestUtil::setupCassette('smartrate/recommendShipDate.yml'); |
| 36 | + |
| 37 | + $params = [ |
| 38 | + 'from_zip' => Fixture::caAddress1()['zip'], |
| 39 | + 'to_zip' => Fixture::caAddress2()['zip'], |
| 40 | + 'desired_delivery_date' => Fixture::desiredDeliveryDate(), |
| 41 | + 'carriers' => [Fixture::usps()], |
| 42 | + ]; |
| 43 | + |
| 44 | + $rates = self::$client->smartRate->recommendShipDate($params); |
| 45 | + |
| 46 | + foreach ($rates['results'] as $entry) { |
| 47 | + $this->assertTrue( |
| 48 | + isset($entry['easypost_time_in_transit_data']), |
| 49 | + 'Assertion failed: easypost_time_in_transit_data is not set.' |
| 50 | + ); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Test that we retrieve SmartRates when provided a from/to zip and planned ship date. |
| 56 | + */ |
| 57 | + public function testRetrieveEstimatedDeliveryDate(): void |
| 58 | + { |
| 59 | + TestUtil::setupCassette('smartrate/estimatedDeliveryDate.yml'); |
| 60 | + |
| 61 | + $params = [ |
| 62 | + 'from_zip' => Fixture::caAddress1()['zip'], |
| 63 | + 'to_zip' => Fixture::caAddress2()['zip'], |
| 64 | + 'planned_ship_date' => Fixture::plannedShipDate(), |
| 65 | + 'carriers' => [Fixture::usps()], |
| 66 | + ]; |
| 67 | + |
| 68 | + $rates = self::$client->smartRate->estimateDeliveryDate($params); |
| 69 | + |
| 70 | + foreach ($rates['results'] as $entry) { |
| 71 | + $this->assertTrue( |
| 72 | + isset($entry['easypost_time_in_transit_data']), |
| 73 | + 'Assertion failed: easypost_time_in_transit_data is not set.' |
| 74 | + ); |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments