/** * @expectedException \RoyalMailPriceCalculator\Exceptions\UnknownPackageTypeException */ public function testUnknownPackageTypeException() { $service = new FirstClassService(); $package = new Package(); $package->setDimensions(100, 100, 100); $package->setWeight(20000); $service->getPackageType($package); }
public function testCalculatePriceWithUnknownPackageType() { $calculator = new Calculator(); $usePriceOn = new \DateTime('2015-03-01'); $package = new Package(); $package->setDimensions(15, 15, 0.4); $package->setWeight(30000); $expected = array(array('service' => new FirstClassService($usePriceOn), 'prices' => array()), array('service' => new SecondClassService($usePriceOn), 'prices' => array())); $calculator->setServices(array(new FirstClassService($usePriceOn), new SecondClassService($usePriceOn))); $this->assertEquals($expected, $calculator->calculatePrice($package)); }
/** * @param Package $package * @returns String * @throws UnknownPackageTypeException */ public function getPackageType(Package $package) { $length = $package->getLength(); $width = $package->getWidth(); $depth = $package->getDepth(); $weight = $package->getWeight(); if ($length <= 24 && $width <= 16.5 && $depth <= 0.5 && $weight <= 100) { return self::LETTER; } elseif ($length <= 35.3 && $width <= 25 && $depth <= 2.5 && $weight <= 750) { return self::LARGE_LETTER; } elseif ($length <= 45 && $width <= 35 && $depth <= 16 && $weight <= 2000) { return self::SMALL_PARCEL; } elseif ($length <= 61 && $width <= 46 && $depth <= 46 && $weight <= 20000) { return self::MEDIUM_PARCEL; } else { throw new UnknownPackageTypeException(); } }
public function testSettersAndGetters() { $package = new Package(); $package->setDimensions(5, 10, 15); $this->assertEquals(5, $package->getLength()); $this->assertEquals(10, $package->getWidth()); $this->assertEquals(15, $package->getDepth()); $package->setWeight(150); $this->assertEquals(150, $package->getWeight()); }