From 9f059d12024de03f33dd84d8ce1803971fe0ecf7 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 15 Jul 2018 13:07:26 +0200 Subject: [PATCH] Solved add bug --- src/entity/order/Order.php | 9 +++++++-- src/entity/order/OrderTest.php | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/entity/order/Order.php b/src/entity/order/Order.php index 422e361..9a9074b 100644 --- a/src/entity/order/Order.php +++ b/src/entity/order/Order.php @@ -42,12 +42,17 @@ final class Order implements OrderInterface public function removeProduct(ProductInterface $product): void { - $this->products->remove($product->getId()); + foreach ($this->products->toArray() as $productItem){ + if($productItem->getId() === + $product->getId()){ + $this->products->removeElement($productItem); + } + } } public function addProduct(ProductInterface $product): void { - $this->products->set($product->getId(), $product); + $this->products->add($product); } public function getId(): int diff --git a/src/entity/order/OrderTest.php b/src/entity/order/OrderTest.php index 8c5d2af..faa2612 100644 --- a/src/entity/order/OrderTest.php +++ b/src/entity/order/OrderTest.php @@ -56,7 +56,7 @@ class OrderTest extends TestCase } public function testAdd():void{ - $this->assertEquals($this->product, $this->order->getProducts()->get($this->product->getId())); + $this->assertEquals(true, $this->order->getProducts()->contains($this->product)); } public function testRemove():void{