/** * @expectedException RuntimeException */ public function testAddingInvestmentThrowsAnExeptionWhenMaxAmountExceeded() { $tranche = new Tranche(); $tranche->setMaxAmount(1000); $investment = new Investment(); $investment->setInvestor(new Investor()); $investment->setAmount(1500); $tranche->addInvestment($investment); }
/** * @param Investment $investment */ public function addInvestment(Investment $investment) { $currentAmount = $this->getCurrentAmount(); $investmentAmount = $investment->getAmount(); if ($currentAmount + $investmentAmount > $this->getMaxAmount()) { throw new \RuntimeException(); } $this->investments[] = $investment; }