Example #1
0
 /** @test **/
 public function it_calculates_the_total_package_weight()
 {
     $items = [new PackageItem(['weight' => new Weight(2000, 'g')]), new PackageItem(['weight' => new Weight(1, 'kg')])];
     $package = new Package($items);
     $this->assertEquals(3, $package->weight(new Unit('kg'))->value());
 }
 /**
  * Get the current rate of shipping.
  *
  * @param Location|null $origin      The origin of the package
  * @param Location|null $destination The destination of the package
  * @param Package|null  $package     The package being sent
  *
  * @return float The shipping rate
  */
 public function getRate(Location $origin = null, Location $destination = null, Package $package = null)
 {
     $weight = $package->weight();
     $weight_cost = $weight->in($this->unit)->value() * $this->weight_rate;
     return $this->base_rate + $weight_cost;
 }