mirror of
https://github.com/kevinveenbirkenbach/coding-challenge-online-shop.git
synced 2024-11-22 02:01:04 +01:00
Implemented Euros and test
This commit is contained in:
parent
9785ebf5a2
commit
523d8f68ec
42
src/entity/currency/Euro.php
Normal file
42
src/entity/currency/Euro.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace entity\currency;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
final class Euro implements CurrencyInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $cents;
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Euro';
|
||||
}
|
||||
|
||||
public function getCents(): int
|
||||
{
|
||||
return $this->cents;
|
||||
}
|
||||
|
||||
public function setCents(int $cents): void
|
||||
{
|
||||
$this->cents = $cents;
|
||||
}
|
||||
|
||||
public function getFloat(): float
|
||||
{
|
||||
return ($this->cents/100);
|
||||
}
|
||||
|
||||
public function getSymbol(): string
|
||||
{
|
||||
return '€';
|
||||
}
|
||||
}
|
||||
|
43
src/entity/currency/EuroTest.php
Normal file
43
src/entity/currency/EuroTest.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace entity\currency;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
class EuroTest extends TestCase
|
||||
{
|
||||
const CENTS = 13301;
|
||||
|
||||
const FLOAT = 133.01;
|
||||
/**
|
||||
*
|
||||
* @var Euro
|
||||
*/
|
||||
protected $euro;
|
||||
|
||||
protected function setUp():void{
|
||||
$this->euro = new Euro();
|
||||
$this->euro->setCents(self::CENTS);
|
||||
}
|
||||
|
||||
public function testName():void{
|
||||
$this->assertEquals('Euro', $this->euro->getName());
|
||||
}
|
||||
|
||||
public function testSymbol():void{
|
||||
$this->assertEquals('€', $this->euro->getSymbol());
|
||||
}
|
||||
|
||||
public function testCent():void{
|
||||
$this->assertEquals(self::CENTS, $this->euro->getCents());
|
||||
}
|
||||
|
||||
public function testFloat():void{
|
||||
$this->assertEquals(self::FLOAT, $this->euro->getFloat());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user