diff --git a/src/AbstractMoney.php b/src/AbstractMoney.php index ee84935..dc21d2e 100644 --- a/src/AbstractMoney.php +++ b/src/AbstractMoney.php @@ -203,6 +203,22 @@ final public function isGreaterThanOrEqualTo($that) : bool return $this->getAmount()->isGreaterThanOrEqualTo($this->getAmountOf($that)); } + /** + * Returns whether this money's amount and currency are equal to those of the given money. + * + * Unlike isEqualTo(), this method only accepts a money, and returns false if the given money is in another + * currency, instead of throwing a MoneyMismatchException. + * + * @param AbstractMoney $that + * + * @return bool + */ + final public function isAmountAndCurrencyEqualTo(AbstractMoney $that) : bool + { + return $this->getAmount()->isEqualTo($that->getAmount()) + && $this->getCurrency()->is($that->getCurrency()); + } + /** * Returns the amount of the given parameter. * diff --git a/tests/MoneyTest.php b/tests/MoneyTest.php index 5e90062..955ca86 100644 --- a/tests/MoneyTest.php +++ b/tests/MoneyTest.php @@ -777,6 +777,23 @@ public function testIsGreaterThanOrEqualToOtherCurrency() : void Money::of('1.00', 'EUR')->isGreaterThanOrEqualTo(Money::of('1.00', 'USD')); } + /** + * @dataProvider providerIsAmountAndCurrencyEqualTo + */ + public function testIsAmountAndCurrencyEqualTo(array $a, array $b, bool $c) : void + { + $this->assertSame($c, Money::of(...$a)->isAmountAndCurrencyEqualTo(Money::of(...$b))); + } + + public function providerIsAmountAndCurrencyEqualTo() : \Generator + { + foreach ($this->providerCompare() as [$a, $b, $c]) { + yield [$a, $b, $c === 0]; + } + + yield [[1, 'EUR'], [1, 'USD'], false]; + } + /** * @return array */