Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/Money/CurrencyPair.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,17 @@ public function getRatio()
{
return $this->ratio;
}

/**
* @param \Money\CurrencyPair $other the currency pair to compare
* @return boolean
*/
public function equals(CurrencyPair $other)
{
return (
$this->baseCurrency->equals($other->baseCurrency)
&& $this->counterCurrency->equals($other->counterCurrency)
&& $this->ratio === $other->ratio
);
}
}
38 changes: 38 additions & 0 deletions tests/Money/Tests/CurrencyPairTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,44 @@ public function testConvertWithInvalidCurrency()

$pair->convert($money);
}

/**
* @dataProvider provideEqualityComparisonPairs
*/
public function testEqualityComparisons($pair1, $pair2, $equal)
{
$this->assertSame($equal, $pair1->equals($pair2));
}

public function provideEqualityComparisonPairs()
{
$usd = new Currency('USD');
$eur = new Currency('EUR');
$gbp = new Currency('GBP');

return array(
'Base Mismatch EUR != GBP' => array(
new CurrencyPair($eur, $usd, 1.2500),
new CurrencyPair($gbp, $usd, 1.2500),
false
),
'Counter Mismatch USD != GBP' => array(
new CurrencyPair($eur, $usd, 1.2500),
new CurrencyPair($eur, $gbp, 1.2500),
false
),
'Ratio Mismatch 1.2500 != 1.5000' => array(
new CurrencyPair($eur, $usd, 1.2500),
new CurrencyPair($eur, $usd, 1.5000),
false
),
'Full Equality EUR/USD 1.2500' => array(
new CurrencyPair($eur, $usd, 1.2500),
new CurrencyPair($eur, $usd, 1.2500),
true
),
);
}

public function provideNonNumericRatio()
{
Expand Down