mirror of
https://github.com/kevinveenbirkenbach/coding-challenge-online-shop.git
synced 2024-12-22 23:25:03 +01:00
Implemented order and tests
This commit is contained in:
parent
e05884340b
commit
400e64a822
89
src/entity/order/Order.php
Normal file
89
src/entity/order/Order.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
namespace entity\order;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use entity\product\ProductInterface;
|
||||
use entity\user\UserInterface;
|
||||
use entity\user\User;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
final class Order implements OrderInterface
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $status;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var ArrayCollection
|
||||
*/
|
||||
private $products;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
private $customer;
|
||||
|
||||
public function __construct(){
|
||||
$this->products = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function removeProduct(ProductInterface $product): void
|
||||
{
|
||||
$this->products->remove($product->getId());
|
||||
}
|
||||
|
||||
public function addProduct(ProductInterface $product): void
|
||||
{
|
||||
$this->products->set($product->getId(), $product);
|
||||
}
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getProducts(): ArrayCollection
|
||||
{
|
||||
return $this->products;
|
||||
}
|
||||
|
||||
public function getStatus(): bool
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function setCustomer(UserInterface $customer)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
}
|
||||
|
||||
public function setStatus(bool $status): void
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
public function getCustomer(): UserInterface
|
||||
{
|
||||
return $this->customer;
|
||||
}
|
||||
|
||||
public function setId(int $id): void
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,6 +40,8 @@ interface OrderInterface
|
||||
*/
|
||||
public function getId():int;
|
||||
|
||||
public function setId(int $id):void;
|
||||
|
||||
/**
|
||||
* @return UserInterface
|
||||
*/
|
||||
@ -48,7 +50,7 @@ interface OrderInterface
|
||||
/**
|
||||
* @param UserInterface $customer
|
||||
*/
|
||||
public function setCutomer(UserInterface $customer);
|
||||
public function setCustomer(UserInterface $customer);
|
||||
|
||||
/**
|
||||
* @param bool $status
|
||||
|
67
src/entity/order/OrderTest.php
Normal file
67
src/entity/order/OrderTest.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace entity\order;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use entity\user\User;
|
||||
use entity\product\Product;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
class OrderTest extends TestCase
|
||||
{
|
||||
const ID = '123456';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Order
|
||||
*/
|
||||
protected $order;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
protected $customer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Product
|
||||
*/
|
||||
protected $product;
|
||||
|
||||
protected function setUp():void{
|
||||
$this->order = new Order();
|
||||
$this->customer = new User();
|
||||
$this->product = new Product();
|
||||
$this->product->setId(1234);
|
||||
$this->order->setId('123456');
|
||||
$this->order->setCustomer($this->customer);
|
||||
$this->order->setStatus(true);
|
||||
$this->order->addProduct($this->product);
|
||||
}
|
||||
|
||||
public function testId():void{
|
||||
$this->assertEquals(self::ID, $this->order->getId());
|
||||
}
|
||||
|
||||
public function testCustomer():void{
|
||||
$this->assertEquals($this->customer, $this->order->getCustomer());
|
||||
}
|
||||
|
||||
public function testStatus():void{
|
||||
$this->assertEquals(true, $this->order->getStatus());
|
||||
}
|
||||
|
||||
public function testAdd():void{
|
||||
$this->assertEquals($this->product, $this->order->getProducts()->get($this->product->getId()));
|
||||
}
|
||||
|
||||
public function testRemove():void{
|
||||
$this->order->removeProduct($this->product);
|
||||
$this->assertEquals(false, $this->order->getProducts()->contains($this->product));
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ namespace entity\product;
|
||||
|
||||
use entity\price\PriceInterface;
|
||||
use entity\image\ImageInterface;
|
||||
use entity\color\ColorInterface;
|
||||
|
||||
/**
|
||||
* Attention:
|
||||
|
Loading…
Reference in New Issue
Block a user