Compare commits

..

10 Commits

Author SHA1 Message Date
b04134946d Fix typo 2020-05-29 17:40:13 -06:00
ef5bbc91dd Add pounds/ounces 2020-05-29 17:38:34 -06:00
Hari KT
9a9fca51d5 update timeout 2019-12-12 09:42:56 -08:00
Jamie Isaacs
4139f52d14 Fixed phpunit coverage whitelist 2019-12-12 01:09:03 -08:00
Jamie Isaacs
8a4a7ebbdf Fixed composer to work with packagist. Fixed risky tests. 2019-12-12 00:29:28 -08:00
Jamie Isaacs
8d1cd60d1a
Merge pull request #19 from harikt/create-func
create_function has been DEPRECATED as of PHP 7.2.0
2019-12-11 23:55:52 -08:00
Hari K T
2e920b5449
Merge branch 'master' into create-func 2019-12-12 12:21:50 +05:30
Hari KT
0e115da493 upgrade phpunit and codesniffer 2019-12-12 12:20:22 +05:30
Hari KT
7a89fea6f6 update travis 2019-12-11 12:57:25 +05:30
Hari KT
0a494a591f create_function has been DEPRECATED as of PHP 7.2.0 2019-12-11 12:50:54 +05:30
26 changed files with 214 additions and 122 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ coverage_report
!.idea/runConfigurations/ !.idea/runConfigurations/
.DS_Store .DS_Store
live_phpunit.sh live_phpunit.sh
/nbproject/private/

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="All Unit Tests" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
<TestRunner class="pdt256\Shipping\PackageDimensionsValidationTrait" configuration_file="$PROJECT_DIR$/phpunit.xml" directory="$PROJECT_DIR$" file="$PROJECT_DIR$/tests/PackageDimensionsValidationTrait.php" scope="XML" use_alternative_configuration_file="true" />
<method v="2" />
</configuration>
</component>

View File

@ -1,6 +1,9 @@
language: php language: php
php: php:
- 7.1 - 7.1
- 7.2
- 7.3
- 7.4
before_script: before_script:
- composer install --prefer-dist - composer install --prefer-dist

View File

@ -1,6 +1,7 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2014 Jamie Isaacs <pdt256@gmail.com> Copyright (c) 2014 Jamie Isaacs <pdt256@gmail.com>
Copyright (c) 2020 Netsyms Technologies <opensource@netsyms.com>
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -15,19 +15,6 @@ Multiple packages can be added to get additional rates.
All code (including tests) conform to the PSR-2 coding standards. All code (including tests) conform to the PSR-2 coding standards.
The namespace and autoloader are using the PSR-4 standard. The namespace and autoloader are using the PSR-4 standard.
All pull requests are processed by Travis CI to conform to PSR-2 and to verify all unit tests pass.
## Installation
Add the following lines to your ``composer.json`` file.
```JSON
{
"require": {
"pdt256/shipping": "1.0.*"
}
}
```
## Example ## Example
@ -56,7 +43,7 @@ $shipment->addPackage($package);
## UPS (Stub) Example ## UPS (Stub) Example
Below is an example request to get shipping rates from the UPS API. Below is an example request to get shipping rates from the UPS API.
Notice: The below line uses a stub class to fake a response from the UPS API. Notice: The below line uses a stub class to fake a response from the UPS API.
You can immediately use this method in your code until you get an account with UPS. You can immediately use this method in your code until you get an account with UPS.
@ -93,7 +80,7 @@ Output array sorted by cost: (in cents)
```php ```php
array ( array (
0 => 0 =>
pdt256\Shipping\Quote::__set_state(array( pdt256\Shipping\Quote::__set_state(array(
'code' => '03', 'code' => '03',
'name' => 'UPS Ground', 'name' => 'UPS Ground',
@ -102,7 +89,7 @@ array (
'deliveryEstimate' => NULL, 'deliveryEstimate' => NULL,
'carrier' => 'ups', 'carrier' => 'ups',
)), )),
1 => 1 =>
pdt256\Shipping\Quote::__set_state(array( pdt256\Shipping\Quote::__set_state(array(
'code' => '02', 'code' => '02',
'name' => 'UPS 2nd Day Air', 'name' => 'UPS 2nd Day Air',
@ -111,7 +98,7 @@ array (
'deliveryEstimate' => NULL, 'deliveryEstimate' => NULL,
'carrier' => 'ups', 'carrier' => 'ups',
)), )),
2 => 2 =>
pdt256\Shipping\Quote::__set_state(array( pdt256\Shipping\Quote::__set_state(array(
'code' => '13', 'code' => '13',
'name' => 'UPS Next Day Air Saver', 'name' => 'UPS Next Day Air Saver',
@ -120,7 +107,7 @@ array (
'deliveryEstimate' => NULL, 'deliveryEstimate' => NULL,
'carrier' => 'ups', 'carrier' => 'ups',
)), )),
3 => 3 =>
pdt256\Shipping\Quote::__set_state(array( pdt256\Shipping\Quote::__set_state(array(
'code' => '01', 'code' => '01',
'name' => 'UPS Next Day Air', 'name' => 'UPS Next Day Air',
@ -157,7 +144,7 @@ Output array sorted by cost: (in cents)
```php ```php
array ( array (
0 => 0 =>
pdt256\Shipping\Quote::__set_state(array( pdt256\Shipping\Quote::__set_state(array(
'code' => '4', 'code' => '4',
'name' => 'Parcel Post', 'name' => 'Parcel Post',
@ -166,7 +153,7 @@ array (
'deliveryEstimate' => NULL, 'deliveryEstimate' => NULL,
'carrier' => 'usps', 'carrier' => 'usps',
)), )),
1 => 1 =>
pdt256\Shipping\Quote::__set_state(array( pdt256\Shipping\Quote::__set_state(array(
'code' => '1', 'code' => '1',
'name' => 'Priority Mail', 'name' => 'Priority Mail',
@ -209,7 +196,7 @@ Output array sorted by cost: (in cents)
```php ```php
array ( array (
0 => 0 =>
pdt256\Shipping\Quote::__set_state(array( pdt256\Shipping\Quote::__set_state(array(
'code' => 'GROUND_HOME_DELIVERY', 'code' => 'GROUND_HOME_DELIVERY',
'name' => 'Ground Home Delivery', 'name' => 'Ground Home Delivery',
@ -218,13 +205,13 @@ array (
'deliveryEstimate' => NULL, 'deliveryEstimate' => NULL,
'carrier' => 'fedex', 'carrier' => 'fedex',
)), )),
1 => 1 =>
pdt256\Shipping\Quote::__set_state(array( pdt256\Shipping\Quote::__set_state(array(
'code' => 'FEDEX_EXPRESS_SAVER', 'code' => 'FEDEX_EXPRESS_SAVER',
'name' => 'Fedex Express Saver', 'name' => 'Fedex Express Saver',
'cost' => 2989, 'cost' => 2989,
'transitTime' => NULL, 'transitTime' => NULL,
'deliveryEstimate' => 'deliveryEstimate' =>
DateTime::__set_state(array( DateTime::__set_state(array(
'date' => '2014-09-30 20:00:00', 'date' => '2014-09-30 20:00:00',
'timezone_type' => 3, 'timezone_type' => 3,
@ -232,13 +219,13 @@ array (
)), )),
'carrier' => 'fedex', 'carrier' => 'fedex',
)), )),
2 => 2 =>
pdt256\Shipping\Quote::__set_state(array( pdt256\Shipping\Quote::__set_state(array(
'code' => 'FEDEX_2_DAY', 'code' => 'FEDEX_2_DAY',
'name' => 'Fedex 2 Day', 'name' => 'Fedex 2 Day',
'cost' => 4072, 'cost' => 4072,
'transitTime' => NULL, 'transitTime' => NULL,
'deliveryEstimate' => 'deliveryEstimate' =>
DateTime::__set_state(array( DateTime::__set_state(array(
'date' => '2014-09-29 20:00:00', 'date' => '2014-09-29 20:00:00',
'timezone_type' => 3, 'timezone_type' => 3,
@ -246,13 +233,13 @@ array (
)), )),
'carrier' => 'fedex', 'carrier' => 'fedex',
)), )),
3 => 3 =>
pdt256\Shipping\Quote::__set_state(array( pdt256\Shipping\Quote::__set_state(array(
'code' => 'STANDARD_OVERNIGHT', 'code' => 'STANDARD_OVERNIGHT',
'name' => 'Standard Overnight', 'name' => 'Standard Overnight',
'cost' => 7834, 'cost' => 7834,
'transitTime' => NULL, 'transitTime' => NULL,
'deliveryEstimate' => 'deliveryEstimate' =>
DateTime::__set_state(array( DateTime::__set_state(array(
'date' => '2014-09-26 20:00:00', 'date' => '2014-09-26 20:00:00',
'timezone_type' => 3, 'timezone_type' => 3,

View File

@ -1,5 +1,5 @@
{ {
"name": "pdt256/shipping", "name": "netsyms/shippingrates",
"description": "Shipping Rate API", "description": "Shipping Rate API",
"license": "MIT", "license": "MIT",
"keywords": ["ship", "ups", "usps", "fedex"], "keywords": ["ship", "ups", "usps", "fedex"],
@ -7,16 +7,20 @@
{ {
"name": "Jamie Isaacs", "name": "Jamie Isaacs",
"email": "pdt256@gmail.com" "email": "pdt256@gmail.com"
},
{
"name": "Netsyms Technologies",
"email": "opensource@netsyms.com"
} }
], ],
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.0.0" "dev-master": "1.0.x-dev"
} }
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "4.0.*", "phpunit/phpunit": "7.0.*",
"squizlabs/php_codesniffer": "1.5.5" "squizlabs/php_codesniffer": "3.5.*"
}, },
"require": { "require": {
"php": ">=7.1" "php": ">=7.1"

View File

@ -0,0 +1,22 @@
auxiliary.org-netbeans-modules-php-phpunit.bootstrap_2e_create_2e_tests=false
auxiliary.org-netbeans-modules-php-phpunit.bootstrap_2e_enabled=false
auxiliary.org-netbeans-modules-php-phpunit.bootstrap_2e_path=
auxiliary.org-netbeans-modules-php-phpunit.configuration_2e_enabled=false
auxiliary.org-netbeans-modules-php-phpunit.configuration_2e_path=
auxiliary.org-netbeans-modules-php-phpunit.customSuite_2e_enabled=false
auxiliary.org-netbeans-modules-php-phpunit.customSuite_2e_path=
auxiliary.org-netbeans-modules-php-phpunit.phpUnit_2e_enabled=false
auxiliary.org-netbeans-modules-php-phpunit.phpUnit_2e_path=
auxiliary.org-netbeans-modules-php-phpunit.test_2e_groups_2e_ask=false
auxiliary.org-netbeans-modules-php-phpunit.test_2e_run_2e_all=false
auxiliary.org-netbeans-modules-php-phpunit.test_2e_run_2e_phpunit_2e_only=false
file.reference.ShippingRates-tests=tests
include.path=${php.global.include.path}
php.version=PHP_73
source.encoding=UTF-8
src.dir=src
tags.asp=false
tags.short=false
test.src.dir=${file.reference.ShippingRates-tests}
testing.providers=PhpUnit
web.root=.

9
nbproject/project.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.php.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/php-project/1">
<name>ShippingRates</name>
</data>
</configuration>
</project>

View File

@ -14,4 +14,9 @@
<directory suffix=".php">./tests</directory> <directory suffix=".php">./tests</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit> </phpunit>

View File

@ -1,35 +1,63 @@
<?php namespace pdt256\Shipping; <?php
class Package namespace pdt256\Shipping;
{
protected $weight; class Package {
protected $pounds;
protected $ounces;
protected $width; protected $width;
protected $length; protected $length;
protected $height; protected $height;
/** public function getWeight() {
* @return mixed $weight = 0;
*/ if (!empty($this->getPounds())) {
public function getWeight() $weight += $this->getPounds();
{ }
return $this->weight; if (!empty($this->getOunces())) {
$weight += ($this->getOunces() / 16);
}
if ($weight == 0) {
return null;
}
return $weight;
}
public function getPounds() {
return $this->pounds ?? 0;
}
public function getOunces() {
return $this->ounces ?? 0;
}
public function setWeight($pounds) {
return $this->setPounds($pounds)->setOunces(0);
} }
/** /**
* @param mixed $weight * @param mixed $pounds
* @return $this * @return $this
*/ */
public function setWeight($weight) public function setPounds($pounds) {
{ $this->pounds = $pounds;
$this->weight = $weight; return $this;
}
/**
* @param mixed $ounces
* @return $this
*/
public function setOunces($ounces) {
$this->ounces = $ounces;
return $this; return $this;
} }
/** /**
* @return mixed * @return mixed
*/ */
public function getWidth() public function getWidth() {
{
return $this->width; return $this->width;
} }
@ -37,8 +65,7 @@ class Package
* @param mixed $width * @param mixed $width
* @return $this * @return $this
*/ */
public function setWidth($width) public function setWidth($width) {
{
$this->width = $width; $this->width = $width;
return $this; return $this;
} }
@ -46,8 +73,7 @@ class Package
/** /**
* @return mixed * @return mixed
*/ */
public function getLength() public function getLength() {
{
return $this->length; return $this->length;
} }
@ -55,8 +81,7 @@ class Package
* @param mixed $length * @param mixed $length
* @return $this * @return $this
*/ */
public function setLength($length) public function setLength($length) {
{
$this->length = $length; $this->length = $length;
return $this; return $this;
} }
@ -64,8 +89,7 @@ class Package
/** /**
* @return mixed * @return mixed
*/ */
public function getHeight() public function getHeight() {
{
return $this->height; return $this->height;
} }
@ -73,9 +97,9 @@ class Package
* @param mixed $height * @param mixed $height
* @return $this * @return $this
*/ */
public function setHeight($height) public function setHeight($height) {
{
$this->height = $height; $this->height = $height;
return $this; return $this;
} }
} }

View File

@ -1,8 +1,6 @@
<?php <?php
namespace pdt256\Shipping; namespace pdt256\Shipping;
use Exception;
abstract class RateAdapter abstract class RateAdapter
{ {
protected $isProduction; protected $isProduction;
@ -18,20 +16,25 @@ abstract class RateAdapter
/** /**
* Make sure all necessary fields are set * Make sure all necessary fields are set
* @return self
*/ */
abstract protected function validate(); abstract protected function validate();
/** /**
* Prepare XML * Prepare XML
* @return self
*/ */
abstract protected function prepare(); abstract protected function prepare();
/** /**
* Curl Request * Curl Request
* @return self
*/ */
abstract protected function execute(); abstract protected function execute();
/** /**
* Convert to shipping rates array * Convert to shipping rates array
* @return self
*/ */
abstract protected function process(); abstract protected function process();
@ -71,17 +74,20 @@ abstract class RateAdapter
return $this->shipment; return $this->shipment;
} }
public function setIsProduction($isProduction) public function setIsProduction($isProduction): void
{ {
$this->isProduction = $isProduction; $this->isProduction = $isProduction;
} }
public function getIsProduction() public function getIsProduction(): bool
{ {
return $this->isProduction; return $this->isProduction;
} }
public function getRates() /**
* @return Quote[]
*/
public function getRates(): array
{ {
$this $this
->validate() ->validate()
@ -93,8 +99,10 @@ abstract class RateAdapter
return array_values($this->rates); return array_values($this->rates);
} }
protected function sortByCost() protected function sortByCost(): void
{ {
uasort($this->rates, create_function('$a, $b', 'return ($a->getCost() > $b->getCost());')); uasort($this->rates, static function (Quote $a, Quote $b) {
return ($a->getCost() > $b->getCost());
});
} }
} }

View File

@ -3,8 +3,8 @@ namespace pdt256\Shipping\RateRequest;
abstract class Adapter abstract class Adapter
{ {
protected $curlConnectTimeoutInMilliseconds = 1000; protected $curlConnectTimeoutInMilliseconds = 1500;
protected $curlDownloadTimeoutInSeconds = 11; protected $curlDownloadTimeoutInSeconds = 50;
abstract public function execute($url, $data = null); abstract public function execute($url, $data = null);
} }

View File

@ -139,8 +139,10 @@ class Ship
return $display_rates; return $display_rates;
} }
protected function sortByCost(& $rates) protected function sortByCost(&$rates)
{ {
uasort($rates, create_function('$a, $b', 'return ($a->getCost() > $b->getCost());')); uasort($rates, function ($a, $b) {
return ($a->getCost() > $b->getCost());
});
} }
} }

View File

@ -95,8 +95,8 @@ class Rate extends RateAdapter
]); ]);
$this->setRequestAdapter(Arr::get($options, 'requestAdapter', new RateRequest\Post())); $this->setRequestAdapter(Arr::get($options, 'requestAdapter', new RateRequest\Post()));
} }
protected function validate() protected function validate()
{ {
$this->validatePackages(); $this->validatePackages();

View File

@ -1,4 +1,5 @@
<?php <?php
namespace pdt256\Shipping\USPS; namespace pdt256\Shipping\USPS;
use pdt256\Shipping; use pdt256\Shipping;
@ -10,18 +11,17 @@ use pdt256\Shipping\Validator;
use DOMDocument; use DOMDocument;
use Exception; use Exception;
class Rate extends RateAdapter class Rate extends RateAdapter {
{
private $urlDev = 'http://production.shippingapis.com/ShippingAPI.dll'; private $urlDev = 'http://production.shippingapis.com/ShippingAPI.dll';
private $urlProd = 'http://production.shippingapis.com/ShippingAPI.dll'; private $urlProd = 'http://production.shippingapis.com/ShippingAPI.dll';
private $username; private $username;
private $password; private $password;
/** /**
* Codes of appropriate shipping types. Default value is specified in __construct. * Codes of appropriate shipping types. Default value is specified in __construct.
*/ */
public $approvedCodes; public $approvedCodes;
private $shipping_codes = [ private $shipping_codes = [
'domestic' => [ 'domestic' => [
'00' => 'First-Class Mail Parcel', '00' => 'First-Class Mail Parcel',
@ -67,20 +67,19 @@ class Rate extends RateAdapter
], ],
]; ];
public function __construct($options = []) public function __construct($options = []) {
{
parent::__construct($options); parent::__construct($options);
$this->username = Arr::get($options, 'username'); $this->username = Arr::get($options, 'username');
$this->password = Arr::get($options, 'password'); $this->password = Arr::get($options, 'password');
$this->approvedCodes = Arr::get($options, 'approvedCodes', [ $this->approvedCodes = Arr::get($options, 'approvedCodes', [
'1', '1',
'4', '4',
]); ]);
$this->setRequestAdapter(Arr::get($options, 'requestAdapter', new RateRequest\Get())); $this->setRequestAdapter(Arr::get($options, 'requestAdapter', new RateRequest\Get()));
} }
protected function validate()
{ protected function validate() {
$this->validatePackages(); $this->validatePackages();
Validator::checkIfNull($this->username, 'username'); Validator::checkIfNull($this->username, 'username');
Validator::checkIfNull($this->password, 'password'); Validator::checkIfNull($this->password, 'password');
@ -89,8 +88,8 @@ class Rate extends RateAdapter
return $this; return $this;
} }
protected function prepare()
{ protected function prepare() {
$packages = ''; $packages = '';
$sequence_number = 0; $sequence_number = 0;
foreach ($this->shipment->getPackages() as $p) { foreach ($this->shipment->getPackages() as $p) {
@ -119,33 +118,30 @@ class Rate extends RateAdapter
$container = 'VARIABLE'; $container = 'VARIABLE';
} }
$packages .= $packages .= '<Package ID="' . $sequence_number . '">' .
'<Package ID="' . $sequence_number . '">' .
'<Service>ALL</Service>' . '<Service>ALL</Service>' .
'<ZipOrigination>' . $this->shipment->getFromPostalCode() . '</ZipOrigination>' . '<ZipOrigination>' . $this->shipment->getFromPostalCode() . '</ZipOrigination>' .
'<ZipDestination>' . $this->shipment->getToPostalCode() . '</ZipDestination>' . '<ZipDestination>' . $this->shipment->getToPostalCode() . '</ZipDestination>' .
'<Pounds>' . $p->getWeight() . '</Pounds>' . '<Pounds>' . $p->getPounds() . '</Pounds>' .
'<Ounces>0</Ounces>' . '<Ounces>' . $p->getOunces() . '</Ounces>' .
'<Container>' . $container . '</Container>' . '<Container>' . $container . '</Container>' .
'<Size>' . $size . '</Size>' . '<Size>' . $size . '</Size>' .
'<Width>' . $p->getWidth() . '</Width>' . '<Width>' . $p->getWidth() . '</Width>' .
'<Length>' . $p->getLength() . '</Length>' . '<Length>' . $p->getLength() . '</Length>' .
'<Height>' . $p->getHeight() . '</Height>' . '<Height>' . $p->getHeight() . '</Height>' .
'<Machinable>' . 'False' . '</Machinable>' . '<Machinable>' . 'False' . '</Machinable>' .
'</Package>'; '</Package>';
} }
$this->data = $this->data = '<RateV4Request USERID="' . $this->username . '">' .
'<RateV4Request USERID="' . $this->username . '">' .
'<Revision/>' . '<Revision/>' .
$packages . $packages .
'</RateV4Request>'; '</RateV4Request>';
return $this; return $this;
} }
protected function execute() protected function execute() {
{
if ($this->isProduction) { if ($this->isProduction) {
$url = $this->urlProd; $url = $this->urlProd;
} else { } else {
@ -159,8 +155,7 @@ class Rate extends RateAdapter
return $this; return $this;
} }
protected function process() protected function process() {
{
try { try {
$dom = new DOMDocument('1.0', 'UTF-8'); $dom = new DOMDocument('1.0', 'UTF-8');
$dom->loadXml($this->response); $dom->loadXml($this->response);
@ -195,10 +190,10 @@ class Rate extends RateAdapter
$quote = new Quote; $quote = new Quote;
$quote $quote
->setCarrier('usps') ->setCarrier('usps')
->setCode($code) ->setCode($code)
->setName($name) ->setName($name)
->setCost((int) $cost); ->setCost((int) $cost);
$rates[$quote->getCode()] = $quote; $rates[$quote->getCode()] = $quote;
} }
@ -207,4 +202,5 @@ class Rate extends RateAdapter
return $this; return $this;
} }
} }

View File

@ -1,7 +1,9 @@
<?php <?php
namespace pdt256\Shipping; namespace pdt256\Shipping;
class ArrTest extends \PHPUnit_Framework_TestCase use PHPUnit\Framework\TestCase;
class ArrTest extends TestCase
{ {
public function providerGet() public function providerGet()
{ {

View File

@ -7,8 +7,9 @@ use pdt256\Shipping\Package;
use pdt256\Shipping\Shipment; use pdt256\Shipping\Shipment;
use pdt256\Shipping\Quote; use pdt256\Shipping\Quote;
use DateTime; use DateTime;
use PHPUnit\Framework\TestCase;
class RateTest extends \PHPUnit_Framework_TestCase class RateTest extends TestCase
{ {
/** @var Shipment */ /** @var Shipment */
protected $shipment; protected $shipment;
@ -182,6 +183,5 @@ class RateTest extends \PHPUnit_Framework_TestCase
'requestAdapter' => new StubFedex, 'requestAdapter' => new StubFedex,
]); ]);
$rateAdapter->getRates(); $rateAdapter->getRates();
} }
} }

View File

@ -5,8 +5,9 @@ namespace pdt256\Shipping;
use pdt256\Shipping\RateRequest\StubFedex; use pdt256\Shipping\RateRequest\StubFedex;
use pdt256\Shipping\RateRequest\StubUPS; use pdt256\Shipping\RateRequest\StubUPS;
use pdt256\Shipping\RateRequest\StubUSPS; use pdt256\Shipping\RateRequest\StubUSPS;
use PHPUnit\Framework\TestCase;
class PackageDimensionsValidationTrait extends \PHPUnit_Framework_TestCase class PackageDimensionsValidationTrait extends TestCase
{ {
protected function getNormalPackage() protected function getNormalPackage()
{ {
@ -107,12 +108,15 @@ class PackageDimensionsValidationTrait extends \PHPUnit_Framework_TestCase
->addPackage($package); ->addPackage($package);
$adapter->setShipment($shipment); $adapter->setShipment($shipment);
$adapter->getRates(); $adapter->getRates();
$this->assertEquals($shipment, $adapter->getShipment());
} }
public function testNormalUSPS() public function testNormalUSPS()
{ {
$this->validatePackage($this->getNormalPackage(), $this->getUSPSAdapter()); $this->validatePackage($this->getNormalPackage(), $this->getUSPSAdapter());
} }
/** /**
* @expectedException \LogicException * @expectedException \LogicException
*/ */
@ -120,6 +124,7 @@ class PackageDimensionsValidationTrait extends \PHPUnit_Framework_TestCase
{ {
$this->validatePackage($this->getNoHeightPackage(), $this->getUSPSAdapter()); $this->validatePackage($this->getNoHeightPackage(), $this->getUSPSAdapter());
} }
/** /**
* @expectedException \LogicException * @expectedException \LogicException
*/ */
@ -127,6 +132,7 @@ class PackageDimensionsValidationTrait extends \PHPUnit_Framework_TestCase
{ {
$this->validatePackage($this->getNoLengthPackage(), $this->getUSPSAdapter()); $this->validatePackage($this->getNoLengthPackage(), $this->getUSPSAdapter());
} }
/** /**
* @expectedException \LogicException * @expectedException \LogicException
*/ */
@ -134,6 +140,7 @@ class PackageDimensionsValidationTrait extends \PHPUnit_Framework_TestCase
{ {
$this->validatePackage($this->getNoWidthPackage(), $this->getUSPSAdapter()); $this->validatePackage($this->getNoWidthPackage(), $this->getUSPSAdapter());
} }
/** /**
* @expectedException \LogicException * @expectedException \LogicException
*/ */
@ -147,6 +154,7 @@ class PackageDimensionsValidationTrait extends \PHPUnit_Framework_TestCase
{ {
$this->validatePackage($this->getNormalPackage(), $this->getUPSAdapter()); $this->validatePackage($this->getNormalPackage(), $this->getUPSAdapter());
} }
/** /**
* @expectedException \LogicException * @expectedException \LogicException
*/ */
@ -154,6 +162,7 @@ class PackageDimensionsValidationTrait extends \PHPUnit_Framework_TestCase
{ {
$this->validatePackage($this->getNoHeightPackage(), $this->getUPSAdapter()); $this->validatePackage($this->getNoHeightPackage(), $this->getUPSAdapter());
} }
/** /**
* @expectedException \LogicException * @expectedException \LogicException
*/ */
@ -161,6 +170,7 @@ class PackageDimensionsValidationTrait extends \PHPUnit_Framework_TestCase
{ {
$this->validatePackage($this->getNoLengthPackage(), $this->getUPSAdapter()); $this->validatePackage($this->getNoLengthPackage(), $this->getUPSAdapter());
} }
/** /**
* @expectedException \LogicException * @expectedException \LogicException
*/ */
@ -168,6 +178,7 @@ class PackageDimensionsValidationTrait extends \PHPUnit_Framework_TestCase
{ {
$this->validatePackage($this->getNoWidthPackage(), $this->getUPSAdapter()); $this->validatePackage($this->getNoWidthPackage(), $this->getUPSAdapter());
} }
/** /**
* @expectedException \LogicException * @expectedException \LogicException
*/ */
@ -181,6 +192,7 @@ class PackageDimensionsValidationTrait extends \PHPUnit_Framework_TestCase
{ {
$this->validatePackage($this->getNormalPackage(), $this->getFedexAdapter()); $this->validatePackage($this->getNormalPackage(), $this->getFedexAdapter());
} }
/** /**
* @expectedException \LogicException * @expectedException \LogicException
*/ */
@ -188,6 +200,7 @@ class PackageDimensionsValidationTrait extends \PHPUnit_Framework_TestCase
{ {
$this->validatePackage($this->getNoHeightPackage(), $this->getFedexAdapter()); $this->validatePackage($this->getNoHeightPackage(), $this->getFedexAdapter());
} }
/** /**
* @expectedException \LogicException * @expectedException \LogicException
*/ */
@ -195,6 +208,7 @@ class PackageDimensionsValidationTrait extends \PHPUnit_Framework_TestCase
{ {
$this->validatePackage($this->getNoLengthPackage(), $this->getFedexAdapter()); $this->validatePackage($this->getNoLengthPackage(), $this->getFedexAdapter());
} }
/** /**
* @expectedException \LogicException * @expectedException \LogicException
*/ */
@ -202,6 +216,7 @@ class PackageDimensionsValidationTrait extends \PHPUnit_Framework_TestCase
{ {
$this->validatePackage($this->getNoWidthPackage(), $this->getFedexAdapter()); $this->validatePackage($this->getNoWidthPackage(), $this->getFedexAdapter());
} }
/** /**
* @expectedException \LogicException * @expectedException \LogicException
*/ */

View File

@ -1,7 +1,9 @@
<?php <?php
namespace pdt256\Shipping; namespace pdt256\Shipping;
class PackageTest extends \PHPUnit_Framework_TestCase use PHPUnit\Framework\TestCase;
class PackageTest extends TestCase
{ {
public function testCreate() public function testCreate()
{ {
@ -12,8 +14,16 @@ class PackageTest extends \PHPUnit_Framework_TestCase
$package->setHeight(8); $package->setHeight(8);
$this->assertEquals(5, $package->getWeight()); $this->assertEquals(5, $package->getWeight());
$this->assertEquals(5, $package->getPounds());
$this->assertEquals(0, $package->getOunces());
$this->assertEquals(6, $package->getWidth()); $this->assertEquals(6, $package->getWidth());
$this->assertEquals(7, $package->getLength()); $this->assertEquals(7, $package->getLength());
$this->assertEquals(8, $package->getHeight()); $this->assertEquals(8, $package->getHeight());
$package->setPounds(3);
$package->setOunces(4);
$this->assertEquals(3, $package->getPounds());
$this->assertEquals(4, $package->getOunces());
$this->assertEquals(3.25, $package->getWeight());
} }
} }

View File

@ -2,8 +2,9 @@
namespace pdt256\Shipping; namespace pdt256\Shipping;
use DateTime; use DateTime;
use PHPUnit\Framework\TestCase;
class QuoteTest extends \PHPUnit_Framework_TestCase class QuoteTest extends TestCase
{ {
public function testCreate() public function testCreate()
{ {

View File

@ -1,13 +0,0 @@
<?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);
}
}

View File

@ -2,8 +2,9 @@
namespace pdt256\Shipping; namespace pdt256\Shipping;
use DateTime; use DateTime;
use PHPUnit\Framework\TestCase;
class ShipTest extends \PHPUnit_Framework_TestCase class ShipTest extends TestCase
{ {
/** @var Shipment */ /** @var Shipment */
public $shipment; public $shipment;

View File

@ -1,7 +1,9 @@
<?php <?php
namespace pdt256\Shipping; namespace pdt256\Shipping;
class ShipmentTest extends \PHPUnit_Framework_TestCase use PHPUnit\Framework\TestCase;
class ShipmentTest extends TestCase
{ {
public function testCreate() public function testCreate()
{ {

View File

@ -6,8 +6,9 @@ use pdt256\Shipping\Ship;
use pdt256\Shipping\Package; use pdt256\Shipping\Package;
use pdt256\Shipping\Shipment; use pdt256\Shipping\Shipment;
use pdt256\Shipping\Quote; use pdt256\Shipping\Quote;
use PHPUnit\Framework\TestCase;
class RateTest extends \PHPUnit_Framework_TestCase class RateTest extends TestCase
{ {
/** @var Shipment */ /** @var Shipment */
protected $shipment; protected $shipment;

View File

@ -6,8 +6,9 @@ use pdt256\Shipping\Ship;
use pdt256\Shipping\Package; use pdt256\Shipping\Package;
use pdt256\Shipping\Shipment; use pdt256\Shipping\Shipment;
use pdt256\Shipping\Quote; use pdt256\Shipping\Quote;
use PHPUnit\Framework\TestCase;
class RateTest extends \PHPUnit_Framework_TestCase class RateTest extends TestCase
{ {
/** @var Shipment */ /** @var Shipment */
protected $shipment; protected $shipment;

View File

@ -1,7 +1,10 @@
<?php <?php
namespace pdt256\Shipping; namespace pdt256\Shipping;
class ValidatorTest extends \PHPUnit_Framework_TestCase use PHPUnit\Framework\TestCase;
use stdClass;
class ValidatorTest extends TestCase
{ {
/** /**
* @expectedException \LogicException * @expectedException \LogicException
@ -15,8 +18,9 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase
{ {
Validator::checkIfNull('XXX', 'notNullValue'); Validator::checkIfNull('XXX', 'notNullValue');
Validator::checkIfNull([], 'notNullValue'); Validator::checkIfNull([], 'notNullValue');
Validator::checkIfNull(new \stdClass(), 'notNullValue'); Validator::checkIfNull(new stdClass(), 'notNullValue');
Validator::checkIfNull(function () { Validator::checkIfNull(function () {
}, 'notNullValue'); }, 'notNullValue');
$this->assertTrue(true);
} }
} }