diff --git a/tests/OrderProductTest.php b/tests/OrderProductTest.php index 7104b4b..2850896 100644 --- a/tests/OrderProductTest.php +++ b/tests/OrderProductTest.php @@ -21,6 +21,9 @@ class OrderProductTest extends TestCase private ?Product $dummy_product; private array $line_items = []; + /** + * @throws Exception + */ public function setUp(): void { parent::setUp(); @@ -51,14 +54,30 @@ public function setUp(): void } // Create a dummy client - $this->client = new Client("john@example.com", "John", "Doe", "john_doe", "password", new Location("Royal", "Curepipe", 1, 50, 50)); + $this->client = new Client( + "john@example.com", + "John", + "Doe", + "john_doe", + "password", + new Location("Royal", "Curepipe", 1, 50, 50) + ); $success = $this->client->save(); if (!$success) { throw new Exception('Unable to save client'); } // Create a dummy product - $this->dummy_product = new Product("Latte", 50, "latte.jpeg", "A delicious latte", "Beverage", 5.0, "A cup of latte", new DateTime()); + $this->dummy_product = new Product( + "Latte", + 50, + "latte.jpeg", + "A delicious latte", + "Beverage", + 5.0, + "A cup of latte", + new DateTime() + ); $success = $this->dummy_product->save(); if (!$success) { throw new Exception('Unable to save product'); @@ -98,7 +117,9 @@ public function tearDown(): void $this->line_items = []; // Clear all data from relevant tables - self::query('DELETE FROM order_product; DELETE FROM `order`; DELETE FROM client; DELETE FROM user; DELETE FROM store_product; DELETE FROM product; DELETE FROM store;'); + self::query( + 'DELETE FROM order_product; DELETE FROM `order`; DELETE FROM client; DELETE FROM user; DELETE FROM store_product; DELETE FROM product; DELETE FROM store;' + ); } public function testValidate(): void @@ -123,7 +144,10 @@ public function testValidate(): void public function testGetByID(): void { // Assuming getByID is a method that retrieves an OrderProduct by order ID and product ID - $retrievedOrderProduct = OrderProduct::getByID($this->dummy_order->getOrderID(), $this->dummy_product->getProductID()); + $retrievedOrderProduct = OrderProduct::getByID( + $this->dummy_order->getOrderID(), + $this->dummy_product->getProductID() + ); $this->assertNotNull($retrievedOrderProduct); $this->assertEquals($this->dummy_order->getOrderID(), $retrievedOrderProduct->getOrderID()); diff --git a/tests/OrderTest.php b/tests/OrderTest.php index d825c10..0bbda2a 100644 --- a/tests/OrderTest.php +++ b/tests/OrderTest.php @@ -21,6 +21,9 @@ class OrderTest extends TestCase private ?Store $dummy_store = null; private array $line_items = []; + /** + * @throws Exception + */ public function setUp(): void { parent::setUp(); @@ -51,20 +54,45 @@ public function setUp(): void } // Create a dummy client - $this->client = new Client("john@example.com", "John", "Doe", "john_doe", "password", new Location("Royal", "Curepipe", 1, 50, 50)); + $this->client = new Client( + "john@example.com", + "John", + "Doe", + "john_doe", + "password", + new Location("Royal", "Curepipe", 1, 50, 50) + ); $success = $this->client->save(); if (!$success) { throw new Exception('Unable to save client'); } // Create dummy products - $product1 = new Product("Latte", 50, "latte.jpeg", "A delicious latte", "Beverage", 5.0, "A cup of latte", new DateTime()); + $product1 = new Product( + "Latte", + 50, + "latte.jpeg", + "A delicious latte", + "Beverage", + 5.0, + "A cup of latte", + new DateTime() + ); $success = $product1->save(); if (!$success) { throw new Exception('Unable to save product 1'); } - $product2 = new Product("Espresso", 30, "espresso.jpeg", "A strong espresso", "Beverage", 3.0, "A cup of espresso", new DateTime()); + $product2 = new Product( + "Espresso", + 30, + "espresso.jpeg", + "A strong espresso", + "Beverage", + 3.0, + "A cup of espresso", + new DateTime() + ); $success = $product2->save(); if (!$success) { throw new Exception('Unable to save product 2'); @@ -96,7 +124,9 @@ public function tearDown(): void $this->line_items = []; // Clear all data from relevant tables - self::query('DELETE FROM order_product; DELETE FROM `order`; DELETE FROM client; DELETE FROM user; DELETE FROM store_product; DELETE FROM product; DELETE FROM store;'); + self::query( + 'DELETE FROM order_product; DELETE FROM `order`; DELETE FROM client; DELETE FROM user; DELETE FROM store_product; DELETE FROM product; DELETE FROM store;' + ); } public function testConstructor(): void @@ -132,6 +162,9 @@ public function testToArray(): void self::assertEquals($this->dummy_order->getStoreID(), $result['store_id']); } + /** + * @throws Exception + */ public function testSave(): void { $success = $this->dummy_order->save(); @@ -156,6 +189,9 @@ public function testSaveWithEmptyLineItems(): void $order->save(); } + /** + * @throws Exception + */ public function testAddLineItem(): void { $order = new Order($this->dummy_store->getStoreID(), $this->client->getUserID()); @@ -163,6 +199,9 @@ public function testAddLineItem(): void self::assertCount(1, $order->getLineItems()); } + /** + * @throws Exception + */ public function testGetByID(): void { $this->dummy_order->save(); @@ -179,6 +218,9 @@ public function testGetByID(): void self::assertNull(Order::getByID(-1)); } + /** + * @throws Exception + */ public function testCalculateTotalPrice(): void { $this->dummy_order->save();