diff --git a/app/creational/prototype/Laptop.php b/app/creational/prototype/Laptop.php index 281ea15..098f0a1 100644 --- a/app/creational/prototype/Laptop.php +++ b/app/creational/prototype/Laptop.php @@ -10,5 +10,6 @@ public function __construct() { $this->id = 2; $this->name = 'Smartphone'; + $this->color = 'Default color'; } } diff --git a/app/creational/prototype/ProductPrototype.php b/app/creational/prototype/ProductPrototype.php index d9c67d9..467c7e6 100644 --- a/app/creational/prototype/ProductPrototype.php +++ b/app/creational/prototype/ProductPrototype.php @@ -8,6 +8,7 @@ abstract class ProductPrototype { protected int $id; protected string $name; + protected string $color; public function getId(): int { @@ -18,4 +19,14 @@ public function getName(): string { return $this->name; } + + public function getColor(): string + { + return $this->color; + } + + public function setColor(string $color): void + { + $this->color = $color; + } } diff --git a/app/creational/prototype/Smartphone.php b/app/creational/prototype/Smartphone.php index a53192e..9b955e4 100644 --- a/app/creational/prototype/Smartphone.php +++ b/app/creational/prototype/Smartphone.php @@ -10,5 +10,6 @@ public function __construct() { $this->id = 1; $this->name = 'Smartphone'; + $this->color = 'Default color'; } } diff --git a/tests/creational/prototype/PrototypeTest.php b/tests/creational/prototype/PrototypeTest.php index eba6a2e..95c540e 100644 --- a/tests/creational/prototype/PrototypeTest.php +++ b/tests/creational/prototype/PrototypeTest.php @@ -19,7 +19,9 @@ public function testSmartphoneClone(): void self::assertEquals($clonedSmartphone->getId(), $smartphone->getId()); self::assertEquals($clonedSmartphone->getName(), $smartphone->getName()); + self::assertEquals($clonedSmartphone->getColor(), $smartphone->getColor()); self::assertEquals($clonedSmartphone, $smartphone); + self::assertNotSame($clonedSmartphone, $smartphone); } public function testCartCanAddClonedProducts(): void @@ -30,12 +32,14 @@ public function testCartCanAddClonedProducts(): void $cart->addProduct($laptop); $clonedLaptop = clone $laptop; - + $clonedLaptop->setColor('White'); $cart->addProduct($clonedLaptop); self::assertCount(2, $cart->getProducts()); - self::assertEquals($cart->getProducts()[1], $cart->getProducts()[0]); - self::assertNotSame($cart->getProducts()[1], $cart->getProducts()[0]); + self::assertEquals($cart->getProducts()[1]->getId(), $cart->getProducts()[0]->getId()); + self::assertEquals($cart->getProducts()[1]->getName(), $cart->getProducts()[0]->getName()); + self::assertEquals('White', $cart->getProducts()[1]->getColor()); + self::assertEquals('Default color', $cart->getProducts()[0]->getColor()); } }