Skip to content

Commit

Permalink
Merge pull request #22 from wmde/get-euros
Browse files Browse the repository at this point in the history
Add getEuros method
  • Loading branch information
Abban committed May 24, 2022
2 parents d076d51 + 25fa3a5 commit dfcfb7a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Euro.php
Expand Up @@ -153,6 +153,10 @@ public function getEuroFloat(): float {
return $this->cents / self::CENTS_PER_EURO;
}

public function getEuros(): int {
return intval( $this->cents / self::CENTS_PER_EURO );
}

/**
* Returns the euro amount as string with two decimals always present in format "42.00".
*
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/EuroTest.php
Expand Up @@ -57,6 +57,29 @@ public function testGiven33cents_getEuroFloatReturnsPointThreeThree() {
$this->assertExactFloat( 0.33, $amount->getEuroFloat() );
}

/**
* @dataProvider getEurosDataProvider
*/
public function testGetEurosReturnsCorrectValues( int $cents, int $expectedEuros ) {
$amount = Euro::newFromCents( $cents );
$this->assertEquals( $expectedEuros, $amount->getEuros() );
}

public function getEurosDataProvider(): array {
return [
[ 0, 0 ],
[ 3, 0 ],
[ 102, 1 ],
[ 149, 1 ],
[ 150, 1 ],
[ 151, 1 ],
[ 199, 1 ],
[ 555, 5 ],
[ 1033, 10 ],
[ 9999, 99 ],
];
}

public function testGivenNegativeAmount_constructorThrowsException() {
$this->expectException( \InvalidArgumentException::class );
Euro::newFromCents( -1 );
Expand Down

0 comments on commit dfcfb7a

Please sign in to comment.