mirror of
https://github.com/kevinveenbirkenbach/coding-challenge-online-shop.git
synced 2024-12-22 23:25:03 +01:00
Implemented price and tests
This commit is contained in:
parent
523d8f68ec
commit
ac7d0aae21
@ -2,6 +2,7 @@
|
||||
namespace entity\price;
|
||||
|
||||
use entity\currency\CurrencyInterface;
|
||||
use entity\currency\Euro;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -10,14 +11,43 @@ use entity\currency\CurrencyInterface;
|
||||
*/
|
||||
final class Price implements PriceInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
private $tax;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $netto;
|
||||
|
||||
public function getGross(): CurrencyInterface
|
||||
{}
|
||||
{
|
||||
$gross = new Euro();
|
||||
$gross->setCents($this->netto->getCents()*(100+$this->tax)/100);
|
||||
return $gross;
|
||||
}
|
||||
|
||||
public function getNetto(): CurrencyInterface
|
||||
{}
|
||||
{
|
||||
return $this->netto;
|
||||
}
|
||||
|
||||
public function setPrice(CurrencyInterface $price): void
|
||||
{}
|
||||
public function setPrice(CurrencyInterface $netto): void
|
||||
{
|
||||
$this->netto = $netto;
|
||||
}
|
||||
|
||||
public function setTax(int $percent): void
|
||||
{
|
||||
$this->tax = $percent;
|
||||
}
|
||||
public function getTax(): int
|
||||
{
|
||||
return $this->tax;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ interface PriceInterface
|
||||
* Sets the price
|
||||
* @param CurrencyInterface $price
|
||||
*/
|
||||
public function setPrice(CurrencyInterface $price):void;
|
||||
public function setPrice(CurrencyInterface $netto):void;
|
||||
|
||||
/**
|
||||
* Returns the netto price
|
||||
@ -27,5 +27,9 @@ interface PriceInterface
|
||||
* @return int
|
||||
*/
|
||||
public function getGross():CurrencyInterface;
|
||||
|
||||
public function setTax(int $percent):void;
|
||||
|
||||
public function getTax():int;
|
||||
}
|
||||
|
||||
|
51
src/entity/price/PriceTest.php
Normal file
51
src/entity/price/PriceTest.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace entity\price;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use entity\currency\Euro;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
class PriceTest extends TestCase
|
||||
{
|
||||
const NETTO = 100;
|
||||
|
||||
const GROSS = 119;
|
||||
|
||||
const TAX = 19;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Price
|
||||
*/
|
||||
protected $price;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Euro
|
||||
*/
|
||||
protected $nettoEuro;
|
||||
|
||||
protected function setUp():void{
|
||||
$this->nettoEuro = new Euro();
|
||||
$this->nettoEuro->setCents(100);
|
||||
$this->price = new Price();
|
||||
$this->price->setTax(self::TAX);
|
||||
$this->price->setPrice($this->nettoEuro);
|
||||
}
|
||||
|
||||
public function testNetto():void{
|
||||
$this->assertEquals(self::NETTO, $this->price->getNetto()->getCents());
|
||||
}
|
||||
|
||||
public function testGross():void{
|
||||
$this->assertEquals(self::GROSS, $this->price->getGross()->getCents());
|
||||
}
|
||||
|
||||
public function testTax():void{
|
||||
$this->assertEquals(self::TAX, $this->price->getTax());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user