diff --git a/src/controller/order/Order.php b/src/controller/order/Order.php index 3c3158f..6c81133 100644 --- a/src/controller/order/Order.php +++ b/src/controller/order/Order.php @@ -65,6 +65,8 @@ final class Order extends AbstractDefaultController implements OrderInterface $this->core->getBasket()->setCustomer($this->core->getUser()); if($this->orderRepository->saveOrder($this->core->getBasket())){ $this->core->setBasket(new OrderEntity()); + }else{ + throw new \Exception('Order could not be saved!'); } } } diff --git a/src/repository/order/Order.php b/src/repository/order/Order.php index acfc797..9214c05 100644 --- a/src/repository/order/Order.php +++ b/src/repository/order/Order.php @@ -3,7 +3,6 @@ namespace repository\order; use repository\AbstractRepository; use entity\order\OrderInterface as OrderEntityInterface; -use core\CoreInterface; /** * @@ -20,13 +19,21 @@ final class Order extends AbstractRepository implements OrderInterface return $this->database->rollBack(); } - private function saveOrderEntity(OrderEntityInterface $order):void{ + /** + * Public for testing reasons + * @param OrderEntityInterface $order + */ + public function saveOrderEntity(OrderEntityInterface $order):void{ $statement = $this->database->prepare("INSERT INTO `order` (`customer`) VALUES (?);"); $statement->execute([$order->getCustomer()->getId()]); $order->setId($this->database->lastInsertId()); } - private function saveConnection(OrderEntityInterface $order):void{ + /** + * Public for testing reasons + * @param OrderEntityInterface $order + */ + public function saveConnection(OrderEntityInterface $order):void{ foreach ($order->getProducts()->toArray() as $product){ $statement = $this->database->prepare("INSERT INTO `order_product` (`product_id`,`order_id`) VALUES (?,?);"); $statement->execute([$product->getId(),$order->getId()]); diff --git a/src/repository/order/OrderTest.php b/src/repository/order/OrderTest.php new file mode 100644 index 0000000..1ab2f8c --- /dev/null +++ b/src/repository/order/OrderTest.php @@ -0,0 +1,48 @@ +core = new Core(); + $user = new User(); + $user->setId(1); + $this->core->setUser($user); + $this->repository = new OrderRepository($this->core); + $this->order = new OrderEntity(); + $this->order->setCustomer($user); + } + + public function testEntitySaver():void{ + $this->repository->saveOrder($this->order); + $this->assertGreaterThan(0,$this->order->getId()); + } +} +