Solved add bug

This commit is contained in:
Kevin Frantz 2018-07-15 13:07:26 +02:00
parent ca8aaa95be
commit 9f059d1202
2 changed files with 8 additions and 3 deletions

View File

@ -42,12 +42,17 @@ final class Order implements OrderInterface
public function removeProduct(ProductInterface $product): void 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 public function addProduct(ProductInterface $product): void
{ {
$this->products->set($product->getId(), $product); $this->products->add($product);
} }
public function getId(): int public function getId(): int

View File

@ -56,7 +56,7 @@ class OrderTest extends TestCase
} }
public function testAdd():void{ 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{ public function testRemove():void{