Migrating code to PSR2. Adding optional support for live API calls in unit tests. Adding rounding error bug fix. Adding more tests to get to 85% coverage. Adding phpstorm project. Bumping master for v1.0.x target.
parent
01ddc321ce
commit
ccf447f755
@ -1,4 +1,9 @@
|
||||
vendor/
|
||||
.idea/
|
||||
vendor
|
||||
composer.lock
|
||||
|
||||
coverage_report
|
||||
.idea/*.iws
|
||||
.idea/*.iml
|
||||
.idea/workspace.xml
|
||||
.idea/tasks.xml
|
||||
.DS_Store
|
||||
live_phpunit.sh
|
||||
|
@ -0,0 +1 @@
|
||||
shipping
|
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
|
||||
</project>
|
||||
|
@ -0,0 +1,10 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0" is_locked="false">
|
||||
<option name="myName" value="Project Default" />
|
||||
<option name="myLocal" value="false" />
|
||||
<inspection_tool class="PhpCSValidationInspection" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="CODING_STANDARD" value="PSR2" />
|
||||
<option name="WARNING_HIGHLIGHT_LEVEL_NAME" value="ERROR" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
@ -0,0 +1,7 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="PROJECT_PROFILE" value="Project Default" />
|
||||
<option name="USE_PROJECT_PROFILE" value="true" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" />
|
||||
</project>
|
||||
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/shipping.iml" filepath="$PROJECT_DIR$/.idea/shipping.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PhpUnit">
|
||||
<phpunit_settings>
|
||||
<PhpUnitSettings load_method="CUSTOM_LOADER" custom_loader_path="$PROJECT_DIR$/vendor/autoload.php" phpunit_phar_path="" />
|
||||
</phpunit_settings>
|
||||
</component>
|
||||
</project>
|
||||
|
@ -0,0 +1,5 @@
|
||||
<component name="DependencyValidationManager">
|
||||
<state>
|
||||
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
|
||||
</state>
|
||||
</component>
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
@ -0,0 +1,10 @@
|
||||
language: php
|
||||
php:
|
||||
- 5.4
|
||||
|
||||
before_script:
|
||||
- composer install --prefer-dist
|
||||
|
||||
script:
|
||||
- vendor/bin/phpcs --standard=PSR2 src/ tests/
|
||||
- vendor/bin/phpunit
|
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
export USPS_USERNAME='XXXXXXXXXXXX'
|
||||
export USPS_PASSWORD='XXXXXXXXXXXX'
|
||||
|
||||
export UPS_ACCESS_KEY='XXXXXXXXXXXXXXXX'
|
||||
export UPS_USER_ID='XXXXXX'
|
||||
export UPS_PASSWORD='XXXX'
|
||||
export UPS_SHIPPER_NUMBER='XXXXXX'
|
||||
|
||||
export FEDEX_KEY='XXXXXXXXXXXXXXXX'
|
||||
export FEDEX_PASSWORD='XXXXXXXXXXXXXXXXXXXXXXXXX'
|
||||
export FEDEX_ACCOUNT_NUMBER='XXXXXXXXX'
|
||||
export FEDEX_METER_NUMBER='XXXXXXXXX'
|
||||
|
||||
vendor/bin/phpunit
|
@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false">
|
||||
<testsuites>
|
||||
<testsuite name="Ship Test Suite">
|
||||
<directory suffix=".php">./tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false">
|
||||
<testsuites>
|
||||
<testsuite name="Ship Test Suite">
|
||||
<directory suffix=".php">./tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace pdt256\Shipping\RateRequest;
|
||||
|
||||
|
||||
class RequestException extends \Exception {}
|
||||
class RequestException extends \Exception
|
||||
{
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,247 @@
|
||||
<?xml version="1.0"?>
|
||||
<RatingServiceSelectionResponse>
|
||||
<Response>
|
||||
<ResponseStatusCode>1</ResponseStatusCode>
|
||||
<ResponseStatusDescription>Success</ResponseStatusDescription>
|
||||
</Response>
|
||||
<RatedShipment>
|
||||
<Service>
|
||||
<Code>03</Code>
|
||||
</Service>
|
||||
<RatedShipmentWarning>Your invoice may vary from the displayed reference rates</RatedShipmentWarning>
|
||||
<RatedShipmentWarning>Missing / Invalid Shipper Number. Returned rates are Retail Rates.</RatedShipmentWarning>
|
||||
<BillingWeight>
|
||||
<UnitOfMeasurement>
|
||||
<Code>LBS</Code>
|
||||
</UnitOfMeasurement>
|
||||
<Weight>3.0</Weight>
|
||||
</BillingWeight>
|
||||
<TransportationCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>19.10</MonetaryValue>
|
||||
</TransportationCharges>
|
||||
<ServiceOptionsCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>0.00</MonetaryValue>
|
||||
</ServiceOptionsCharges>
|
||||
<TotalCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>19.10</MonetaryValue>
|
||||
</TotalCharges>
|
||||
<GuaranteedDaysToDelivery/>
|
||||
<ScheduledDeliveryTime/>
|
||||
<RatedPackage>
|
||||
<TransportationCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>19.10</MonetaryValue>
|
||||
</TransportationCharges>
|
||||
<ServiceOptionsCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>0.00</MonetaryValue>
|
||||
</ServiceOptionsCharges>
|
||||
<TotalCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>19.10</MonetaryValue>
|
||||
</TotalCharges>
|
||||
<Weight>3.0</Weight>
|
||||
<BillingWeight>
|
||||
<UnitOfMeasurement>
|
||||
<Code>LBS</Code>
|
||||
</UnitOfMeasurement>
|
||||
<Weight>3.0</Weight>
|
||||
</BillingWeight>
|
||||
</RatedPackage>
|
||||
</RatedShipment>
|
||||
<RatedShipment>
|
||||
<Service>
|
||||
<Code>12</Code>
|
||||
</Service>
|
||||
<RatedShipmentWarning>Your invoice may vary from the displayed reference rates</RatedShipmentWarning>
|
||||
<RatedShipmentWarning>Missing / Invalid Shipper Number. Returned rates are Retail Rates.</RatedShipmentWarning>
|
||||
<BillingWeight>
|
||||
<UnitOfMeasurement>
|
||||
<Code>LBS</Code>
|
||||
</UnitOfMeasurement>
|
||||
<Weight>5.0</Weight>
|
||||
</BillingWeight>
|
||||
<TransportationCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>37.18</MonetaryValue>
|
||||
</TransportationCharges>
|
||||
<ServiceOptionsCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>0.00</MonetaryValue>
|
||||
</ServiceOptionsCharges>
|
||||
<TotalCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>37.18</MonetaryValue>
|
||||
</TotalCharges>
|
||||
<GuaranteedDaysToDelivery>3</GuaranteedDaysToDelivery>
|
||||
<ScheduledDeliveryTime/>
|
||||
<RatedPackage>
|
||||
<TransportationCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>37.18</MonetaryValue>
|
||||
</TransportationCharges>
|
||||
<ServiceOptionsCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>0.00</MonetaryValue>
|
||||
</ServiceOptionsCharges>
|
||||
<TotalCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>37.18</MonetaryValue>
|
||||
</TotalCharges>
|
||||
<Weight>3.0</Weight>
|
||||
<BillingWeight>
|
||||
<UnitOfMeasurement>
|
||||
<Code>LBS</Code>
|
||||
</UnitOfMeasurement>
|
||||
<Weight>5.0</Weight>
|
||||
</BillingWeight>
|
||||
</RatedPackage>
|
||||
</RatedShipment>
|
||||
<RatedShipment>
|
||||
<Service>
|
||||
<Code>02</Code>
|
||||
</Service>
|
||||
<RatedShipmentWarning>Your invoice may vary from the displayed reference rates</RatedShipmentWarning>
|
||||
<RatedShipmentWarning>Missing / Invalid Shipper Number. Returned rates are Retail Rates.</RatedShipmentWarning>
|
||||
<BillingWeight>
|
||||
<UnitOfMeasurement>
|
||||
<Code>LBS</Code>
|
||||
</UnitOfMeasurement>
|
||||
<Weight>5.0</Weight>
|
||||
</BillingWeight>
|
||||
<TransportationCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>49.23</MonetaryValue>
|
||||
</TransportationCharges>
|
||||
<ServiceOptionsCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>0.00</MonetaryValue>
|
||||
</ServiceOptionsCharges>
|
||||
<TotalCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>49.23</MonetaryValue>
|
||||
</TotalCharges>
|
||||
<GuaranteedDaysToDelivery>2</GuaranteedDaysToDelivery>
|
||||
<ScheduledDeliveryTime/>
|
||||
<RatedPackage>
|
||||
<TransportationCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>49.23</MonetaryValue>
|
||||
</TransportationCharges>
|
||||
<ServiceOptionsCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>0.00</MonetaryValue>
|
||||
</ServiceOptionsCharges>
|
||||
<TotalCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>49.23</MonetaryValue>
|
||||
</TotalCharges>
|
||||
<Weight>3.0</Weight>
|
||||
<BillingWeight>
|
||||
<UnitOfMeasurement>
|
||||
<Code>LBS</Code>
|
||||
</UnitOfMeasurement>
|
||||
<Weight>5.0</Weight>
|
||||
</BillingWeight>
|
||||
</RatedPackage>
|
||||
</RatedShipment>
|
||||
<RatedShipment>
|
||||
<Service>
|
||||
<Code>13</Code>
|
||||
</Service>
|
||||
<RatedShipmentWarning>Your invoice may vary from the displayed reference rates</RatedShipmentWarning>
|
||||
<RatedShipmentWarning>Missing / Invalid Shipper Number. Returned rates are Retail Rates.</RatedShipmentWarning>
|
||||
<BillingWeight>
|
||||
<UnitOfMeasurement>
|
||||
<Code>LBS</Code>
|
||||
</UnitOfMeasurement>
|
||||
<Weight>5.0</Weight>
|
||||
</BillingWeight>
|
||||
<TransportationCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>89.54</MonetaryValue>
|
||||
</TransportationCharges>
|
||||
<ServiceOptionsCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>0.00</MonetaryValue>
|
||||
</ServiceOptionsCharges>
|
||||
<TotalCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>89.54</MonetaryValue>
|
||||
</TotalCharges>
|
||||
<GuaranteedDaysToDelivery>1</GuaranteedDaysToDelivery>
|
||||
<ScheduledDeliveryTime/>
|
||||
<RatedPackage>
|
||||
<TransportationCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>89.54</MonetaryValue>
|
||||
</TransportationCharges>
|
||||
<ServiceOptionsCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>0.00</MonetaryValue>
|
||||
</ServiceOptionsCharges>
|
||||
<TotalCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>89.54</MonetaryValue>
|
||||
</TotalCharges>
|
||||
<Weight>3.0</Weight>
|
||||
<BillingWeight>
|
||||
<UnitOfMeasurement>
|
||||
<Code>LBS</Code>
|
||||
</UnitOfMeasurement>
|
||||
<Weight>5.0</Weight>
|
||||
</BillingWeight>
|
||||
</RatedPackage>
|
||||
</RatedShipment>
|
||||
<RatedShipment>
|
||||
<Service>
|
||||
<Code>01</Code>
|
||||
</Service>
|
||||
<RatedShipmentWarning>Your invoice may vary from the displayed reference rates</RatedShipmentWarning>
|
||||
<RatedShipmentWarning>Missing / Invalid Shipper Number. Returned rates are Retail Rates.</RatedShipmentWarning>
|
||||
<BillingWeight>
|
||||
<UnitOfMeasurement>
|
||||
<Code>LBS</Code>
|
||||
</UnitOfMeasurement>
|
||||
<Weight>5.0</Weight>
|
||||
</BillingWeight>
|
||||
<TransportationCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>93.28</MonetaryValue>
|
||||
</TransportationCharges>
|
||||
<ServiceOptionsCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>0.00</MonetaryValue>
|
||||
</ServiceOptionsCharges>
|
||||
<TotalCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>93.28</MonetaryValue>
|
||||
</TotalCharges>
|
||||
<GuaranteedDaysToDelivery>1</GuaranteedDaysToDelivery>
|
||||
<ScheduledDeliveryTime>12:00 Noon</ScheduledDeliveryTime>
|
||||
<RatedPackage>
|
||||
<TransportationCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>93.28</MonetaryValue>
|
||||
</TransportationCharges>
|
||||
<ServiceOptionsCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>0.00</MonetaryValue>
|
||||
</ServiceOptionsCharges>
|
||||
<TotalCharges>
|
||||
<CurrencyCode>USD</CurrencyCode>
|
||||
<MonetaryValue>93.28</MonetaryValue>
|
||||
</TotalCharges>
|
||||
<Weight>3.0</Weight>
|
||||
<BillingWeight>
|
||||
<UnitOfMeasurement>
|
||||
<Code>LBS</Code>
|
||||
</UnitOfMeasurement>
|
||||
<Weight>5.0</Weight>
|
||||
</BillingWeight>
|
||||
</RatedPackage>
|
||||
</RatedShipment>
|
||||
</RatingServiceSelectionResponse>
|
@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<RateV4Response>
|
||||
<Package ID="1">
|
||||
<ZipOrigination>90401</ZipOrigination>
|
||||
<ZipDestination>76667</ZipDestination>
|
||||
<Pounds>3</Pounds>
|
||||
<Ounces>0</Ounces>
|
||||
<Size>LARGE</Size>
|
||||
<Machinable>FALSE</Machinable>
|
||||
<Zone>6</Zone>
|
||||
<Postage CLASSID="3">
|
||||
<MailService>Priority Mail Express 2-Day&lt;sup&gt;&#8482;&lt;/sup&gt;</MailService>
|
||||
<Rate>42.25</Rate>
|
||||
</Postage>
|
||||
<Postage CLASSID="2">
|
||||
<MailService>Priority Mail Express 2-Day&lt;sup&gt;&#8482;&lt;/sup&gt; Hold For Pickup
|
||||
</MailService>
|
||||
<Rate>42.25</Rate>
|
||||
</Postage>
|
||||
<Postage CLASSID="1">
|
||||
<MailService>Priority Mail 2-Day&lt;sup&gt;&#8482;&lt;/sup&gt;</MailService>
|
||||
<Rate>12.20</Rate>
|
||||
</Postage>
|
||||
<Postage CLASSID="4">
|
||||
<MailService>Standard Post&lt;sup&gt;&#174;&lt;/sup&gt;</MailService>
|
||||
<Rate>10.01</Rate>
|
||||
</Postage>
|
||||
<Postage CLASSID="6">
|
||||
<MailService>Media Mail Parcel</MailService>
|
||||
<Rate>3.65</Rate>
|
||||
</Postage>
|
||||
<Postage CLASSID="7">
|
||||
<MailService>Library Mail Parcel</MailService>
|
||||
<Rate>3.48</Rate>
|
||||
</Postage>
|
||||
</Package>
|
||||
</RateV4Response>
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace pdt256\Shipping;
|
||||
|
||||
class ArrTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function providerGet()
|
||||
{
|
||||
return array(
|
||||
array(array('uno', 'dos', 'tress'), 1, null, 'dos'),
|
||||
array(array('we' => 'can', 'make' => 'change'), 'we', null, 'can'),
|
||||
array(array('uno', 'dos', 'tress'), 10, null, null),
|
||||
array(array('we' => 'can', 'make' => 'change'), 'he', null, null),
|
||||
array(array('we' => 'can', 'make' => 'change'), 'he', 'who', 'who'),
|
||||
array(array('we' => 'can', 'make' => 'change'), 'he', array('arrays'), array('arrays')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerGet()
|
||||
*/
|
||||
public function testGet(array $array, $key, $default, $expected)
|
||||
{
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
Arr::get($array, $key, $default)
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
namespace pdt256\Shipping\Fedex;
|
||||
|
||||
use pdt256\Shipping\RateRequest\StubFedex;
|
||||
use pdt256\Shipping\Ship;
|
||||
use pdt256\Shipping\Package;
|
||||
use pdt256\Shipping\Shipment;
|
||||
use pdt256\Shipping\Quote;
|
||||
use DateTime;
|
||||
|
||||
class RateTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var Shipment */
|
||||
protected $shipment;
|
||||
|
||||
protected $approvedCodes = [];
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$ship = Ship::factory([
|
||||
'Standard Shipping' => [
|
||||
'fedex' => [
|
||||
'FEDEX_EXPRESS_SAVER' => '1-3 business days',
|
||||
'FEDEX_GROUND' => '1-5 business days',
|
||||
'GROUND_HOME_DELIVERY' => '1-5 business days',
|
||||
],
|
||||
],
|
||||
'Two-Day Shipping' => [
|
||||
'fedex' => [
|
||||
'FEDEX_2_DAY' => '2 business days',
|
||||
],
|
||||
],
|
||||
'One-Day Shipping' => [
|
||||
'fedex' => [
|
||||
'STANDARD_OVERNIGHT' => 'overnight',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->approvedCodes = $ship->getApprovedCodes('fedex');
|
||||
|
||||
$package = new Package;
|
||||
$package->setWeight(3)
|
||||
->setWidth(9)
|
||||
->setLength(9)
|
||||
->setHeight(9);
|
||||
|
||||
$this->shipment = new Shipment;
|
||||
$this->shipment->setFromStateProvinceCode('CA')
|
||||
->setFromPostalCode('90401')
|
||||
->setFromCountryCode('US')
|
||||
->setToPostalCode('78703')
|
||||
->setToCountryCode('US')
|
||||
->setToIsResidential(true)
|
||||
->addPackage($package);
|
||||
}
|
||||
|
||||
public function testMockRates()
|
||||
{
|
||||
$rateAdapter = new Rate([
|
||||
'prod' => false,
|
||||
'drop_off_type' => 'BUSINESS_SERVICE_CENTER',
|
||||
'shipment' => $this->shipment,
|
||||
'approvedCodes' => $this->approvedCodes,
|
||||
'requestAdapter' => new StubFedex,
|
||||
]);
|
||||
|
||||
$rates = $rateAdapter->getRates();
|
||||
|
||||
$ground = new Quote('fedex', 'GROUND_HOME_DELIVERY', 'Ground Home Delivery', 1655);
|
||||
$ground->setTransitTime('THREE_DAYS');
|
||||
|
||||
$express = new Quote('fedex', 'FEDEX_EXPRESS_SAVER', 'Fedex Express Saver', 2989);
|
||||
$express->setDeliveryEstimate(new DateTime('2014-09-30T20:00:00'));
|
||||
|
||||
$secondDay = new Quote('fedex', 'FEDEX_2_DAY', 'Fedex 2 Day', 4072);
|
||||
$secondDay->setDeliveryEstimate(new DateTime('2014-09-29T20:00:00'));
|
||||
|
||||
$overnight = new Quote('fedex', 'STANDARD_OVERNIGHT', 'Standard Overnight', 7834);
|
||||
$overnight->setDeliveryEstimate(new DateTime('2014-09-26T20:00:00'));
|
||||
|
||||
$expected = [$ground, $express, $secondDay, $overnight];
|
||||
|
||||
$this->assertEquals($expected, $rates);
|
||||
}
|
||||
|
||||
public function testLiveRates()
|
||||
{
|
||||
if (getenv('FEDEX_KEY') === false) {
|
||||
$this->markTestSkipped('Live Fedex credentials missing.');
|
||||
}
|
||||
|
||||
$rateAdapter = new Rate([
|
||||
'prod' => false,
|
||||
'key' => getenv('FEDEX_KEY'),
|
||||
'password' => getenv('FEDEX_PASSWORD'),
|
||||
'account_number' => getenv('FEDEX_ACCOUNT_NUMBER'),
|
||||
'meter_number' => getenv('FEDEX_METER_NUMBER'),
|
||||
'drop_off_type' => 'BUSINESS_SERVICE_CENTER',
|
||||
'shipment' => $this->shipment,
|
||||
'approvedCodes' => $this->approvedCodes,
|
||||
'requestAdapter' => new StubFedex,
|
||||
]);
|
||||
|
||||
$rates = $rateAdapter->getRates();
|
||||
|
||||
$this->assertTrue(count($rates) > 0);
|
||||
$this->assertTrue($rates[0] instanceof Quote);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace pdt256\Shipping;
|
||||
|
||||
class PackageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$package = new Package;
|
||||
$package->setWeight(5);
|
||||
$package->setWidth(6);
|
||||
$package->setLength(7);
|
||||
$package->setHeight(8);
|
||||
|
||||
$this->assertEquals(5, $package->getWeight());
|
||||
$this->assertEquals(6, $package->getWidth());
|
||||
$this->assertEquals(7, $package->getLength());
|
||||
$this->assertEquals(8, $package->getHeight());
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace pdt256\Shipping;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class QuoteTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$quote = new Quote;
|
||||
$quote->setCode('-code-');
|
||||
$quote->setName('Test Name');
|
||||
$quote->setCost(500);
|
||||
$quote->setTransitTime('-transit-time-');
|
||||
$quote->setDeliveryEstimate(new DateTime);
|
||||
$quote->setCarrier('-carrier-');
|
||||
|
||||
$this->assertEquals('-code-', $quote->getCode());
|
||||
$this->assertEquals('Test Name', $quote->getName());
|
||||
$this->assertEquals(500, $quote->getCost());
|
||||
$this->assertEquals('-transit-time-', $quote->getTransitTime());
|
||||
$this->assertTrue($quote->getDeliveryEstimate() instanceof DateTime);
|
||||
$this->assertEquals('-carrier-', $quote->getCarrier());
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace pdt256\Shipping;
|
||||
|
||||
class RateAdapterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
/* @var RateAdapter $mock */
|
||||
$mock = $this->getMockForAbstractClass('pdt256\Shipping\RateAdapter');
|
||||
$mockRequestAdapter = $this->getMockForAbstractClass('pdt256\Shipping\RateRequest\Adapter');
|
||||
$mock->setRequestAdapter($mockRequestAdapter);
|
||||
}
|
||||
}
|
@ -1,277 +1,155 @@
|
||||
<?php
|
||||
use pdt256\Shipping\Package;
|
||||
use pdt256\Shipping\Quote;
|
||||
use pdt256\Shipping\Ship;
|
||||
use pdt256\Shipping\Shipment;
|
||||
use pdt256\Shipping\USPS;
|
||||
use pdt256\Shipping\UPS;
|
||||
use pdt256\Shipping\Fedex;
|
||||
use pdt256\Shipping\RateRequest;
|
||||
namespace pdt256\Shipping;
|
||||
|
||||
class ShipTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var Shipment */
|
||||
public $shipment;
|
||||
|
||||
public $shipping_options = [
|
||||
'Standard Shipping' => [
|
||||
'ups' => [
|
||||
'03' => '1-5 business days',
|
||||
],
|
||||
'fedex' => [
|
||||
'FEDEX_EXPRESS_SAVER' => '1-3 business days',
|
||||
'FEDEX_GROUND' => '1-5 business days',
|
||||
'GROUND_HOME_DELIVERY' => '1-5 business days',
|
||||
],
|
||||
'usps' => [
|
||||
'1' => '1-3 business days',
|
||||
'4' => '2-8 business days',
|
||||
],
|
||||
],
|
||||
'Two-Day Shipping' => [
|
||||
'ups' => [
|
||||
'02' => '2 business days',
|
||||
],
|
||||
'fedex' => [
|
||||
'FEDEX_2_DAY' => '2 business days',
|
||||
],
|
||||
],
|
||||
'One-Day Shipping' => [
|
||||
'ups' => [
|
||||
'01' => 'next business day 10:30am',
|
||||
'13' => 'next business day by 3pm',
|
||||
'14' => 'next business day by 8am',
|
||||
],
|
||||
'fedex' => [
|
||||
'STANDARD_OVERNIGHT' => 'overnight',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$s = new Shipment;
|
||||
$s->setFromStateProvinceCode('CA')
|
||||
->setFromPostalCode('90401')
|
||||
->setFromCountryCode('US')
|
||||
->setToPostalCode('78703')
|
||||
->setToCountryCode('US')
|
||||
->setToResidential(true);
|
||||
|
||||
$p = new Package;
|
||||
$p->setWeight(3)
|
||||
->setWidth(9)
|
||||
->setLength(9)
|
||||
->setHeight(9);
|
||||
|
||||
$s->addPackage($p);
|
||||
|
||||
$this->shipment = $s;
|
||||
}
|
||||
|
||||
private function getUSPSOptions()
|
||||
{
|
||||
$ship = Ship::factory($this->shipping_options);
|
||||
$approved_codes = $ship->get_approved_codes('usps');
|
||||
|
||||
return [
|
||||
'prod' => FALSE,
|
||||
'username' => 'XXXX',
|
||||
'password' => 'XXXX',
|
||||
'shipment' => $this->shipment,
|
||||
'approved_codes' => $approved_codes,
|
||||
'request_adapter' => new RateRequest\StubUSPS(),
|
||||
];
|
||||
}
|
||||
|
||||
private function getUPSOptions()
|
||||
{
|
||||
$ship = Ship::factory($this->shipping_options);
|
||||
$approved_codes = $ship->get_approved_codes('ups');
|
||||
|
||||
return [
|
||||
'prod' => FALSE,
|
||||
'access_key' => 'XXXX',
|
||||
'user_id' => 'XXXX',
|
||||
'password' => 'XXXX',
|
||||
'shipper_number' => 'XXXX',
|
||||
'shipment' => $this->shipment,
|
||||
'approved_codes' => $approved_codes,
|
||||
'request_adapter' => new RateRequest\StubUPS(),
|
||||
];
|
||||
}
|
||||
|
||||
private function getFedexOptions()
|
||||
{
|
||||
$ship = Ship::factory($this->shipping_options);
|
||||
$approved_codes = $ship->get_approved_codes('fedex');
|
||||
|
||||
return [
|
||||
'prod' => FALSE,
|
||||
'key' => 'XXXX',
|
||||
'password' => 'XXXX',
|
||||
'account_number' => 'XXXX',
|
||||
'meter_number' => 'XXXX',
|
||||
'drop_off_type' => 'BUSINESS_SERVICE_CENTER',
|
||||
'shipment' => $this->shipment,
|
||||
'approved_codes' => $approved_codes,
|
||||
'request_adapter' => new RateRequest\StubFedex(),
|
||||
];
|
||||
}
|
||||
|
||||
public function testUSPSRate()
|
||||
{
|
||||
$usps = new USPS\Rate($this->getUSPSOptions());
|
||||
$usps_rates = $usps->get_rates();
|
||||
|
||||
$post = new Quote;
|
||||
$post
|
||||
->setCarrier('usps')
|
||||
->setCode(4)
|
||||
->setName('Parcel Post')
|
||||
->setCost(1001);
|
||||
|
||||
$priority = new Quote;
|
||||
$priority
|
||||
->setCarrier('usps')
|
||||
->setCode(1)
|
||||
->setName('Priority Mail')
|
||||
->setCost(1220);
|
||||
|
||||
$expected_return = [$post, $priority];
|
||||
|
||||
$this->assertEquals($expected_return, $usps_rates);
|
||||
}
|
||||
|
||||
public function testUPSRate()
|
||||
{
|
||||
$ups = new UPS\Rate($this->getUPSOptions());
|
||||
$ups_rates = $ups->get_rates();
|
||||
|
||||
$ground = new Quote;
|
||||
$ground
|
||||
->setCarrier('ups')
|
||||
->setCode('03')
|
||||
->setName('UPS Ground')
|
||||
->setCost(1900);
|
||||
|
||||
$twodayair = new Quote;
|
||||
$twodayair
|
||||
->setCarrier('ups')
|
||||
->setCode('02')
|
||||
->setName('UPS 2nd Day Air')
|
||||
->setCost(4900);
|
||||
use DateTime;
|
||||
|
||||
$nextdaysaver = new Quote;
|
||||
$nextdaysaver
|
||||
->setCarrier('ups')
|
||||
->setCode('13')
|
||||
->setName('UPS Next Day Air Saver')
|
||||
->setCost(8900);
|
||||
|
||||
$nextdayair = new Quote;
|
||||
$nextdayair
|
||||
->setCarrier('ups')
|
||||
->setCode('01')
|
||||
->setName('UPS Next Day Air')
|
||||
->setCost(9300);
|
||||
|
||||
$expected_return = [$ground, $twodayair, $nextdaysaver, $nextdayair];
|
||||
|
||||
$this->assertEquals($expected_return, $ups_rates);
|
||||
}
|
||||
|
||||
public function testFedexRate()
|
||||
{
|
||||
$fedex = new Fedex\Rate($this->getFedexOptions());
|
||||
$fedex_rates = $fedex->get_rates();
|
||||
|
||||
$ground = new Quote;
|
||||
$ground
|
||||
->setCarrier('fedex')
|
||||
->setCode('GROUND_HOME_DELIVERY')
|
||||
->setName('Ground Home Delivery')
|
||||
->setCost(1600)
|
||||
->setTransitTime('THREE_DAYS');
|
||||
|
||||
$express = new Quote;
|
||||
$express
|
||||
->setCarrier('fedex')
|
||||
->setCode('FEDEX_EXPRESS_SAVER')
|
||||
->setName('Fedex Express Saver')
|
||||
->setCost(2900)
|
||||
->setDeliveryEstimate(new DateTime('2014-09-30T20:00:00'))
|
||||
->setTransitTime(null);
|
||||
|
||||
$secondday = new Quote;
|
||||
$secondday
|
||||
->setCarrier('fedex')
|
||||
->setCode('FEDEX_2_DAY')
|
||||
->setName('Fedex 2 Day')
|
||||
->setCost(4000)
|
||||
->setDeliveryEstimate(new DateTime('2014-09-29T20:00:00'))
|
||||
->setTransitTime(null);
|
||||
|
||||
$overnight = new Quote;
|
||||
$overnight
|
||||
->setCarrier('fedex')
|
||||
->setCode('STANDARD_OVERNIGHT')
|
||||
->setName('Standard Overnight')
|
||||
->setCost(7800)
|
||||
->setDeliveryEstimate(new DateTime('2014-09-26T20:00:00'))
|
||||
->setTransitTime(null);
|
||||
|
||||
$expected_result = [$ground, $express, $secondday, $overnight];
|
||||
|
||||
$this->assertEquals($expected_result, $fedex_rates);
|
||||
}
|
||||
|
||||
public function testDisplayOptions()
|
||||
{
|
||||
$rates = [];
|
||||
|
||||
$usps = new USPS\Rate($this->getUSPSOptions());
|
||||
$rates['usps'] = $usps->get_rates();
|
||||
|
||||
$ups = new UPS\Rate($this->getUPSOptions());
|
||||
$rates['ups'] = $ups->get_rates();
|
||||
|
||||
$fedex = new Fedex\Rate($this->getFedexOptions());
|
||||
$rates['fedex'] = $fedex->get_rates();
|
||||
|
||||
$ship = Ship::factory($this->shipping_options);
|
||||
$display_rates = $ship->get_display_rates($rates);
|
||||
|
||||
$post = new Quote;
|
||||
$post->setCode(4)
|
||||
->setName('Parcel Post')
|
||||
->setCost(1001)
|
||||
->setCarrier('usps');
|
||||
|
||||
$fedex_two_day = new Quote;
|
||||
$fedex_two_day->setCode('FEDEX_2_DAY')
|
||||
->setName('Fedex 2 Day')
|
||||
->setCost(4000)
|
||||
->setDeliveryEstimate(new DateTime('2014-09-29T20:00:00'))
|
||||
->setCarrier('fedex');
|
||||
|
||||
$overnight = new Quote;
|
||||
$overnight->setCode('STANDARD_OVERNIGHT')
|
||||
->setName('Standard Overnight')
|
||||
->setCost(7800)
|
||||
->setDeliveryEstimate(new DateTime('2014-09-26T20:00:00'))
|
||||
->setCarrier('fedex');
|
||||
|
||||
$this->assertEquals([
|
||||
'Standard Shipping' => [
|
||||
$post,
|
||||
],
|
||||
'Two-Day Shipping' => [
|
||||
$fedex_two_day,
|
||||
],
|
||||
'One-Day Shipping' => [
|
||||
$overnight,
|
||||
],
|
||||
], $display_rates);
|
||||
}
|
||||
class ShipTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var Shipment */
|
||||
public $shipment;
|
||||
|
||||
public $shipping_options = [
|
||||
'Standard Shipping' => [
|
||||
'ups' => [
|
||||
'03' => '1-5 business days',
|
||||
],
|
||||
'fedex' => [
|
||||
'FEDEX_EXPRESS_SAVER' => '1-3 business days',
|
||||
'FEDEX_GROUND' => '1-5 business days',
|
||||
'GROUND_HOME_DELIVERY' => '1-5 business days',
|
||||
],
|
||||
'usps' => [
|
||||
'1' => '1-3 business days',
|
||||
'4' => '2-8 business days',
|
||||
],
|
||||
],
|
||||
'Two-Day Shipping' => [
|
||||
'ups' => [
|
||||
'02' => '2 business days',
|
||||
],
|
||||
'fedex' => [
|
||||
'FEDEX_2_DAY' => '2 business days',
|
||||
],
|
||||
],
|
||||
'One-Day Shipping' => [
|
||||
'ups' => [
|
||||
'01' => 'next business day 10:30am',
|
||||
'13' => 'next business day by 3pm',
|
||||
'14' => 'next business day by 8am',
|
||||
],
|
||||
'fedex' => [
|
||||
'STANDARD_OVERNIGHT' => 'overnight',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$s = new Shipment;
|
||||
$s->setFromStateProvinceCode('CA')
|
||||
->setFromPostalCode('90401')
|
||||
->setFromCountryCode('US')
|
||||
->setToPostalCode('78703')
|
||||
->setToCountryCode('US')
|
||||
->setToIsResidential(true);
|
||||
|
||||
$p = new Package;
|
||||
$p->setWeight(3)
|
||||
->setWidth(9)
|
||||
->setLength(9)
|
||||
->setHeight(9);
|
||||
|
||||
$s->addPackage($p);
|
||||
|
||||
$this->shipment = $s;
|
||||
}
|
||||
|
||||
private function getUSPSOptions()
|
||||
{
|
||||
$ship = Ship::factory($this->shipping_options);
|
||||
$approvedCodes = $ship->getApprovedCodes('usps');
|
||||
|
||||
return [
|
||||
'prod' => false,
|
||||
'username' => 'XXXX',
|
||||
'password' => 'XXXX',
|
||||
'shipment' => $this->shipment,
|
||||
'approvedCodes' => $approvedCodes,
|
||||
'requestAdapter' => new RateRequest\StubUSPS(),
|
||||
];
|
||||
}
|
||||
|
||||
private function getUPSOptions()
|
||||
{
|
||||
$ship = Ship::factory($this->shipping_options);
|
||||
$approvedCodes = $ship->getApprovedCodes('ups');
|
||||
|
||||
return [
|
||||
'prod' => false,
|
||||
'accessKey' => 'XXXX',
|
||||
'userId' => 'XXXX',
|
||||
'password' => 'XXXX',
|
||||
'shipperNumber' => 'XXXX',
|
||||
'shipment' => $this->shipment,
|
||||
'approvedCodes' => $approvedCodes,
|
||||
'requestAdapter' => new RateRequest\StubUPS(),
|
||||
];
|
||||
}
|
||||
|
||||
private function getFedexOptions()
|
||||
{
|
||||
$ship = Ship::factory($this->shipping_options);
|
||||
$approvedCodes = $ship->getApprovedCodes('fedex');
|
||||
|
||||
return [
|
||||
'prod' => false,
|
||||
'key' => 'XXXX',
|
||||
'password' => 'XXXX',
|
||||
'account_number' => 'XXXX',
|
||||
'meter_number' => 'XXXX',
|
||||
'drop_off_type' => 'BUSINESS_SERVICE_CENTER',
|
||||
'shipment' => $this->shipment,
|
||||
'approvedCodes' => $approvedCodes,
|
||||
'requestAdapter' => new RateRequest\StubFedex(),
|
||||
];
|
||||
}
|
||||
|
||||
public function testDisplayOptions()
|
||||
{
|
||||
$rates = [];
|
||||
|
||||
$usps = new USPS\Rate($this->getUSPSOptions());
|
||||
$rates['usps'] = $usps->getRates();
|
||||
|
||||
$ups = new UPS\Rate($this->getUPSOptions());
|
||||
$rates['ups'] = $ups->getRates();
|
||||
|
||||
$fedex = new Fedex\Rate($this->getFedexOptions());
|
||||
$rates['fedex'] = $fedex->getRates();
|
||||
|
||||
$ship = Ship::factory($this->shipping_options);
|
||||
$rates = $ship->getDisplayRates($rates);
|
||||
|
||||
$post = new Quote('usps', '4', 'Parcel Post', 1001);
|
||||
|
||||
$fedexTwoDay = new Quote('fedex', 'FEDEX_2_DAY', 'Fedex 2 Day', 4072);
|
||||
$fedexTwoDay->setDeliveryEstimate(new DateTime('2014-09-29T20:00:00'));
|
||||
|
||||
$overnight = new Quote('fedex', 'STANDARD_OVERNIGHT', 'Standard Overnight', 7834);
|
||||
$overnight->setDeliveryEstimate(new DateTime('2014-09-26T20:00:00'));
|
||||
|
||||
$expected = [
|
||||
'Standard Shipping' => [
|
||||
$post,
|
||||
],
|
||||
'Two-Day Shipping' => [
|
||||
$fedexTwoDay,
|
||||
],
|
||||
'One-Day Shipping' => [
|
||||
$overnight,
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $rates);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace pdt256\Shipping;
|
||||
|
||||
class ShipmentTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$shipment = new Shipment;
|
||||
$shipment->addPackage(new Package);
|
||||
|
||||
$shipment->setFromIsResidential(false);
|
||||
$shipment->setFromPostalCode('90401');
|
||||
$shipment->setFromCountryCode('US');
|
||||
$shipment->setFromStateProvinceCode('CA');
|
||||
|
||||
$shipment->setToIsResidential(true);
|
||||
$shipment->setToPostalCode('90210');
|
||||
$shipment->setToCountryCode('US');
|
||||
|
||||
$this->assertTrue($shipment->getPackages()[0] instanceof Package);
|
||||
$this->assertEquals(1, $shipment->packageCount());
|
||||
|
||||
$this->assertFalse($shipment->getFromIsResidential());
|
||||
$this->assertEquals('90401', $shipment->getFromPostalCode());
|
||||
$this->assertEquals('US', $shipment->getFromCountryCode());
|
||||
$this->assertEquals('CA', $shipment->getFromStateProvinceCode());
|
||||
|
||||
$this->assertTrue($shipment->getToIsResidential());
|
||||
$this->assertEquals('90210', $shipment->getToPostalCode());
|
||||
$this->assertEquals('US', $shipment->getToCountryCode());
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
namespace pdt256\Shipping\UPS;
|
||||
|
||||
use pdt256\Shipping\RateRequest\StubUPS;
|
||||
use pdt256\Shipping\Ship;
|
||||
use pdt256\Shipping\Package;
|
||||
use pdt256\Shipping\Shipment;
|
||||
use pdt256\Shipping\Quote;
|
||||
|
||||
class RateTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var Shipment */
|
||||
protected $shipment;
|
||||
|
||||
protected $approvedCodes = [];
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$ship = Ship::factory([
|
||||
'Standard Shipping' => [
|
||||
'ups' => [
|
||||
'03' => '1-5 business days',
|
||||
],
|
||||
],
|
||||
'Two-Day Shipping' => [
|
||||
'ups' => [
|
||||
'02' => '2 business days',
|
||||
],
|
||||
],
|
||||
'One-Day Shipping' => [
|
||||
'ups' => [
|
||||
'01' => 'next business day 10:30am',
|
||||
'13' => 'next business day by 3pm',
|
||||
'14' => 'next business day by 8am',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->approvedCodes = $ship->getApprovedCodes('ups');
|
||||
|
||||
$package = new Package;
|
||||
$package->setWeight(3)
|
||||
->setWidth(9)
|
||||
->setLength(9)
|
||||
->setHeight(9);
|
||||
|
||||
$this->shipment = new Shipment;
|
||||
$this->shipment->setFromStateProvinceCode('CA')
|
||||
->setFromPostalCode('90401')
|
||||
->setFromCountryCode('US')
|
||||
->setToPostalCode('78703')
|
||||
->setToCountryCode('US')
|
||||
->setToIsResidential(true)
|
||||
->addPackage($package);
|
||||
}
|
||||
|
||||
public function testMockRates()
|
||||
{
|
||||
$rateAdapter = new Rate([
|
||||
'prod' => false,
|
||||
'shipment' => $this->shipment,
|
||||
'approvedCodes' => $this->approvedCodes,
|
||||
'requestAdapter' => new StubUPS,
|
||||
]);
|
||||
|
||||
$rates = $rateAdapter->getRates();
|
||||
|
||||
$expected = [
|
||||
new Quote('ups', '03', 'UPS Ground', 1910),
|
||||
new Quote('ups', '02', 'UPS 2nd Day Air', 4923),
|
||||
new Quote('ups', '13', 'UPS Next Day Air Saver', 8954),
|
||||
new Quote('ups', '01', 'UPS Next Day Air', 9328),
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $rates);
|
||||
}
|
||||
|
||||
public function testLiveRates()
|
||||
{
|
||||
if (getenv('UPS_ACCESS_KEY') === false) {
|
||||
$this->markTestSkipped('Live UPS credentials missing.');
|
||||
}
|
||||
|
||||
$rateAdapter = new Rate([
|
||||
'prod' => false,
|
||||
'accessKey' => getenv('UPS_ACCESS_KEY'),
|
||||
'userId' => getenv('UPS_USER_ID'),
|
||||
'password' => getenv('UPS_PASSWORD'),
|
||||
'shipperNumber' => getenv('UPS_SHIPPER_NUMBER'),
|
||||
'shipment' => $this->shipment,
|
||||
'approvedCodes' => $this->approvedCodes,
|
||||
]);
|
||||
|
||||
$rates = $rateAdapter->getRates();
|
||||
|
||||
$this->assertTrue(count($rates) > 0);
|
||||
$this->assertTrue($rates[0] instanceof Quote);
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
namespace pdt256\Shipping\USPS;
|
||||
|
||||
use pdt256\Shipping\RateRequest\StubUSPS;
|
||||
use pdt256\Shipping\Ship;
|
||||
use pdt256\Shipping\Package;
|
||||
use pdt256\Shipping\Shipment;
|
||||
use pdt256\Shipping\Quote;
|
||||
|
||||
class RateTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var Shipment */
|
||||
protected $shipment;
|
||||
|
||||
protected $approvedCodes = [];
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$ship = Ship::factory([
|
||||
'Standard Shipping' => [
|
||||
'usps' => [
|
||||
'1' => '1-3 business days',
|
||||
'4' => '2-8 business days',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->approvedCodes = $ship->getApprovedCodes('usps');
|
||||
|
||||
$package = new Package;
|
||||
$package->setWeight(3)
|
||||
->setWidth(9)
|
||||
->setLength(9)
|
||||
->setHeight(9);
|
||||
|
||||
$this->shipment = new Shipment;
|
||||
$this->shipment->setFromStateProvinceCode('CA')
|
||||
->setFromPostalCode('90401')
|
||||
->setFromCountryCode('US')
|
||||
->setToPostalCode('78703')
|
||||
->setToCountryCode('US')
|
||||
->setToIsResidential(true)
|
||||
->addPackage($package);
|
||||
}
|
||||
|
||||
public function testMockRates()
|
||||
{
|
||||
$rateAdapter = new Rate([
|
||||
'prod' => false,
|
||||
'username' => 'XXXX',
|
||||
'password' => 'XXXX',
|
||||
'shipment' => $this->shipment,
|
||||
'approvedCodes' => $this->approvedCodes,
|
||||
'requestAdapter' => new StubUSPS,
|
||||
]);
|
||||
|
||||
$rates = $rateAdapter->getRates();
|
||||
|
||||
$expected = [
|
||||
new Quote('usps', '4', 'Parcel Post', 1001),
|
||||
new Quote('usps', '1', 'Priority Mail', 1220),
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $rates);
|
||||
}
|
||||
|
||||
public function testLiveRates()
|
||||
{
|
||||
if (getenv('USPS_USERNAME') === false) {
|
||||
$this->markTestSkipped('Live USPS credentials missing.');
|
||||
}
|
||||
|
||||
$rateAdapter = new Rate([
|
||||
'prod' => false,
|
||||
'username' => getenv('USPS_USERNAME'),
|
||||
'password' => getenv('USPS_PASSWORD'),
|
||||
'shipment' => $this->shipment,
|
||||
'approvedCodes' => $this->approvedCodes,
|
||||
]);
|
||||
|
||||
$rates = $rateAdapter->getRates();
|
||||
|
||||
$this->assertTrue(count($rates) > 0);
|
||||
$this->assertTrue($rates[0] instanceof Quote);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue