コード例 #1
0
ファイル: WeightTest.php プロジェクト: harrygr/shipper
 /** @test **/
 public function it_allows_adding_one_weight_to_another()
 {
     $weight_1 = new Weight(500, 'g');
     $weight_2 = new Weight(2, 'kg');
     $weight_1->add($weight_2);
     $this->assertEquals(2500, $weight_1->value());
 }
コード例 #2
0
ファイル: Package.php プロジェクト: harrygr/shipper
 /**
  * Get the total weight for a package of items.
  *
  * @param Unit|string $unit The unit the weight should be in
  *
  * @return Weight
  */
 public function weight($unit = 'kg')
 {
     $total_weight = new Weight(0, $unit);
     foreach ($this->items as $item) {
         $total_weight->add($item->weight());
     }
     return $total_weight;
 }