/** * @param Money $money * @return Money */ public function add(Money $money) { if (!$this->currency->equals($money->currency)) { throw new \RuntimeException("You can't add different currencies"); } return new Money($this->amount + $money->amount(), $this->currency); }
public function test_it_should_not_add_different_currencies() { $stub = $this->getCurrencyDummy(); $stub->expects($this->once())->method('equals')->willReturn(false); $money = new Money(10, $stub); $this->setExpectedException(\RuntimeException::class, "You can't add different currencies"); $money->add(new Money(5, $this->getCurrencyDummy())); }