-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
74 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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("[email protected]", "John", "Doe", "john_doe", "password", new Location("Royal", "Curepipe", 1, 50, 50)); | ||
$this->client = new Client( | ||
"[email protected]", | ||
"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()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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("[email protected]", "John", "Doe", "john_doe", "password", new Location("Royal", "Curepipe", 1, 50, 50)); | ||
$this->client = new Client( | ||
"[email protected]", | ||
"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,13 +189,19 @@ public function testSaveWithEmptyLineItems(): void | |
$order->save(); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function testAddLineItem(): void | ||
{ | ||
$order = new Order($this->dummy_store->getStoreID(), $this->client->getUserID()); | ||
$order->addLineItem(new OrderProduct(1, "medium", "oat", 1, 5.0)); | ||
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(); | ||
|