Skip to content

Commit 4519b10

Browse files
committed
Merge pull request #1 from texdc/master
merge texdc/money
2 parents bd39872 + b717d1e commit 4519b10

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

lib/Money/CurrencyPair.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,17 @@ public function getRatio()
9595
{
9696
return $this->ratio;
9797
}
98+
99+
/**
100+
* @param \Money\CurrencyPair $other the currency pair to compare
101+
* @return boolean
102+
*/
103+
public function equals(CurrencyPair $other)
104+
{
105+
return (
106+
$this->baseCurrency->equals($other->baseCurrency)
107+
&& $this->counterCurrency->equals($other->counterCurrency)
108+
&& $this->ratio === $other->ratio
109+
);
110+
}
98111
}

tests/Money/Tests/CurrencyPairTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,44 @@ public function testConvertWithInvalidCurrency()
9191

9292
$pair->convert($money);
9393
}
94+
95+
/**
96+
* @dataProvider provideEqualityComparisonPairs
97+
*/
98+
public function testEqualityComparisons($pair1, $pair2, $equal)
99+
{
100+
$this->assertSame($equal, $pair1->equals($pair2));
101+
}
102+
103+
public function provideEqualityComparisonPairs()
104+
{
105+
$usd = new Currency('USD');
106+
$eur = new Currency('EUR');
107+
$gbp = new Currency('GBP');
108+
109+
return array(
110+
'Base Mismatch EUR != GBP' => array(
111+
new CurrencyPair($eur, $usd, 1.2500),
112+
new CurrencyPair($gbp, $usd, 1.2500),
113+
false
114+
),
115+
'Counter Mismatch USD != GBP' => array(
116+
new CurrencyPair($eur, $usd, 1.2500),
117+
new CurrencyPair($eur, $gbp, 1.2500),
118+
false
119+
),
120+
'Ratio Mismatch 1.2500 != 1.5000' => array(
121+
new CurrencyPair($eur, $usd, 1.2500),
122+
new CurrencyPair($eur, $usd, 1.5000),
123+
false
124+
),
125+
'Full Equality EUR/USD 1.2500' => array(
126+
new CurrencyPair($eur, $usd, 1.2500),
127+
new CurrencyPair($eur, $usd, 1.2500),
128+
true
129+
),
130+
);
131+
}
94132

95133
public function provideNonNumericRatio()
96134
{

0 commit comments

Comments
 (0)