From 053184f493d052ec0f5478b256bc54fc4b2a3ef3 Mon Sep 17 00:00:00 2001 From: Pereyaslov Konstantin Date: Tue, 9 Dec 2014 09:32:46 +0300 Subject: [PATCH] Tests for missing package dimensions --- tests/PackageDimensionsTest.php | 212 ++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 tests/PackageDimensionsTest.php diff --git a/tests/PackageDimensionsTest.php b/tests/PackageDimensionsTest.php new file mode 100644 index 0000000..a6451fe --- /dev/null +++ b/tests/PackageDimensionsTest.php @@ -0,0 +1,212 @@ +setHeight(10) + ->setWidth(6) + ->setLength(10) + ->setWeight(5) + ; + return $normalPackage; + } + protected function getNoHeightPackage() + { + $noHeightPackage = new Package(); + $noHeightPackage + ->setWidth(6) + ->setLength(10) + ->setWeight(5) + ; + return $noHeightPackage; + } + protected function getNoWidthPackage() + { + $noWidthPackage = new Package(); + $noWidthPackage + ->setHeight(10) + ->setLength(10) + ->setWeight(5) + ; + return $noWidthPackage; + } + protected function getNoLengthPackage() + { + $noLengthPackage = new Package(); + $noLengthPackage + ->setHeight(10) + ->setWidth(6) + ->setWeight(5) + ; + return $noLengthPackage; + } + protected function getNoWeightPackage() + { + $noWeightPackage = new Package(); + $noWeightPackage + ->setHeight(10) + ->setWidth(10) + ->setWidth(6) + ; + return $noWeightPackage; + } + protected function getUSPSAdapter() + { + return new USPS\Rate([ + 'prod' => false, + 'username' => 'XXXX', + 'password' => 'XXXX', + 'requestAdapter' => new StubUSPS(), + ]); + } + + protected function getUPSAdapter() + { + return new UPS\Rate([ + 'accessKey' => 'XXX', + 'userId' => 'XXX', + 'password' => 'XXX', + 'shipperNumber' => 'XXX', + 'prod' => false, + 'requestAdapter' => new StubUPS(), + ]); + } + + protected function getFedexAdapter() + { + return new Fedex\Rate([ + 'prod' => false, + 'key' => 'XXX', + 'password' => 'XXX', + 'accountNumber' => 'XXX', + 'meterNumber' => 'XXX', + 'dropOffType' => 'BUSINESS_SERVICE_CENTER', + 'requestAdapter' => new StubFedex(), + ]); + } + + protected function validatePackage(Package $package, RateAdapter $adapter) + { + $shipment = new Shipment(); + $shipment->setFromStateProvinceCode('CA') + ->setFromPostalCode('90401') + ->setFromCountryCode('US') + ->setFromIsResidential(true) + ->setToPostalCode('78703') + ->setToCountryCode('US') + ->setToIsResidential(true) + ->addPackage($package); + $adapter->setShipment($shipment); + $adapter->getRates(); + } + + public function testNormalUSPS() + { + $this->validatePackage($this->getNormalPackage(), $this->getUSPSAdapter()); + } + /** + * @expectedException \LogicException + */ + public function testNoHeightPackageUSPS() + { + $this->validatePackage($this->getNoHeightPackage(), $this->getUSPSAdapter()); + } + /** + * @expectedException \LogicException + */ + public function testNoLengthPackageUSPS() + { + $this->validatePackage($this->getNoLengthPackage(), $this->getUSPSAdapter()); + } + /** + * @expectedException \LogicException + */ + public function testNoWidthPackageUSPS() + { + $this->validatePackage($this->getNoWidthPackage(), $this->getUSPSAdapter()); + } + /** + * @expectedException \LogicException + */ + public function testNoWeightPackageUSPS() + { + $this->validatePackage($this->getNoWeightPackage(), $this->getUSPSAdapter()); + } + + + public function testNormalUPS() + { + $this->validatePackage($this->getNormalPackage(), $this->getUPSAdapter()); + } + /** + * @expectedException \LogicException + */ + public function testNoHeightPackageUPS() + { + $this->validatePackage($this->getNoHeightPackage(), $this->getUPSAdapter()); + } + /** + * @expectedException \LogicException + */ + public function testNoLengthPackageUPS() + { + $this->validatePackage($this->getNoLengthPackage(), $this->getUPSAdapter()); + } + /** + * @expectedException \LogicException + */ + public function testNoWidthPackageUPS() + { + $this->validatePackage($this->getNoWidthPackage(), $this->getUPSAdapter()); + } + /** + * @expectedException \LogicException + */ + public function testNoWeightPackageUPS() + { + $this->validatePackage($this->getNoWeightPackage(), $this->getUPSAdapter()); + } + + + public function testNormalFedex() + { + $this->validatePackage($this->getNormalPackage(), $this->getFedexAdapter()); + } + /** + * @expectedException \LogicException + */ + public function testNoHeightPackageFedex() + { + $this->validatePackage($this->getNoHeightPackage(), $this->getFedexAdapter()); + } + /** + * @expectedException \LogicException + */ + public function testNoLengthPackageFedex() + { + $this->validatePackage($this->getNoLengthPackage(), $this->getFedexAdapter()); + } + /** + * @expectedException \LogicException + */ + public function testNoWidthPackageFedex() + { + $this->validatePackage($this->getNoWidthPackage(), $this->getFedexAdapter()); + } + /** + * @expectedException \LogicException + */ + public function testNoWeightPackageFedex() + { + $this->validatePackage($this->getNoWeightPackage(), $this->getFedexAdapter()); + } +}