/** * Decrease this account current balance * * @param Money $amount * @throws InsufficientFunds * A member cannot withdraw more than it's account current balance */ public function withdraw(Money $amount) { if ($amount->greaterThan($this->balance)) { throw new InsufficientFunds("Cannot withdraw {$amount->getAmount()}"); } $this->balance = $this->balance->subtract($amount); }
public function testComparison() { $euro1 = new Money(1, new Currency('EUR')); $euro2 = new Money(2, new Currency('EUR')); $usd = new Money(1, new Currency('USD')); $this->assertTrue($euro2->greaterThan($euro1)); $this->assertFalse($euro1->greaterThan($euro2)); $this->assertTrue($euro1->lessThan($euro2)); $this->assertFalse($euro2->lessThan($euro1)); $this->assertEquals(-1, $euro1->compare($euro2)); $this->assertEquals(1, $euro2->compare($euro1)); $this->assertEquals(0, $euro1->compare($euro1)); }
/** * Returns true if the provided amount is lower, than the current upper * limit * * @param Money $other * @return bool */ protected function matches($other) { return $this->upperLimit->greaterThan($other); }