From 5ff1832dee0759c0f05d13a94243a12e637ed21b Mon Sep 17 00:00:00 2001 From: lubiana Date: Wed, 26 Jun 2024 20:31:27 +0200 Subject: [PATCH 1/2] make orderitem menuitem non nullable --- migrations/Version20240626182031.php | 43 ++++++++++++++++++++ src/Controller/OrderItemController.php | 1 + src/Entity/OrderItem.php | 2 +- tests/Controller/OrderItemControllerTest.php | 12 +++++- 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 migrations/Version20240626182031.php diff --git a/migrations/Version20240626182031.php b/migrations/Version20240626182031.php new file mode 100644 index 0000000..8f74202 --- /dev/null +++ b/migrations/Version20240626182031.php @@ -0,0 +1,43 @@ +addSql('CREATE TEMPORARY TABLE __temp__order_item AS SELECT id, food_order_id, name, extras, menu_item_id FROM order_item'); + $this->addSql('DROP TABLE order_item'); + $this->addSql('CREATE TABLE order_item (id BLOB NOT NULL, food_order_id BLOB DEFAULT NULL, name VARCHAR(255) NOT NULL, extras VARCHAR(255) DEFAULT NULL, menu_item_id BLOB NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_52EA1F09A5D24A7A FOREIGN KEY (food_order_id) REFERENCES food_order (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_52EA1F099AB44FE0 FOREIGN KEY (menu_item_id) REFERENCES menu_item (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('INSERT INTO order_item (id, food_order_id, name, extras, menu_item_id) SELECT id, food_order_id, name, extras, menu_item_id FROM __temp__order_item'); + $this->addSql('DROP TABLE __temp__order_item'); + $this->addSql('CREATE INDEX IDX_52EA1F099AB44FE0 ON order_item (menu_item_id)'); + $this->addSql('CREATE INDEX IDX_52EA1F09A5D24A7A ON order_item (food_order_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE TEMPORARY TABLE __temp__order_item AS SELECT id, name, extras, food_order_id, menu_item_id FROM order_item'); + $this->addSql('DROP TABLE order_item'); + $this->addSql('CREATE TABLE order_item (id BLOB NOT NULL, name VARCHAR(255) NOT NULL, extras VARCHAR(255) DEFAULT NULL, food_order_id BLOB DEFAULT NULL, menu_item_id BLOB DEFAULT NULL, PRIMARY KEY(id), CONSTRAINT FK_52EA1F09A5D24A7A FOREIGN KEY (food_order_id) REFERENCES food_order (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_52EA1F099AB44FE0 FOREIGN KEY (menu_item_id) REFERENCES menu_item (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('INSERT INTO order_item (id, name, extras, food_order_id, menu_item_id) SELECT id, name, extras, food_order_id, menu_item_id FROM __temp__order_item'); + $this->addSql('DROP TABLE __temp__order_item'); + $this->addSql('CREATE INDEX IDX_52EA1F09A5D24A7A ON order_item (food_order_id)'); + $this->addSql('CREATE INDEX IDX_52EA1F099AB44FE0 ON order_item (menu_item_id)'); + } +} diff --git a/src/Controller/OrderItemController.php b/src/Controller/OrderItemController.php index 512d0d7..6f615a8 100644 --- a/src/Controller/OrderItemController.php +++ b/src/Controller/OrderItemController.php @@ -76,6 +76,7 @@ final class OrderItemController extends AbstractController $newOrderItem->setFoodOrder($orderItem->getFoodOrder()); $newOrderItem->setName($orderItem->getName()); $newOrderItem->setExtras($orderItem->getExtras()); + $newOrderItem->setMenuItem($orderItem->getMenuItem()); $entityManager->persist($newOrderItem); $entityManager->flush(); diff --git a/src/Entity/OrderItem.php b/src/Entity/OrderItem.php index eb98fb3..1429a5d 100644 --- a/src/Entity/OrderItem.php +++ b/src/Entity/OrderItem.php @@ -28,7 +28,7 @@ class OrderItem private FoodOrder|null $foodOrder = null; #[ORM\ManyToOne] - #[ORM\JoinColumn(nullable: true)] + #[ORM\JoinColumn(nullable: false)] private MenuItem|null $menuItem = null; public function getId(): Ulid|null diff --git a/tests/Controller/OrderItemControllerTest.php b/tests/Controller/OrderItemControllerTest.php index c8762df..f090f27 100644 --- a/tests/Controller/OrderItemControllerTest.php +++ b/tests/Controller/OrderItemControllerTest.php @@ -4,6 +4,7 @@ namespace App\Tests\Controller; use App\Entity\FoodOrder; use App\Entity\FoodVendor; +use App\Entity\MenuItem; use App\Entity\OrderItem; use App\Tests\DbWebTest; use Override; @@ -14,6 +15,7 @@ final class OrderItemControllerTest extends DbWebTest { public FoodVendor $vendor; public FoodOrder $order; + public Menuitem $menuItem; private string $path = '/order/item/'; #[Override] @@ -28,6 +30,11 @@ final class OrderItemControllerTest extends DbWebTest $this->order->setFoodVendor($this->vendor); $this->manager->persist($this->order); + + $this->menuItem = new MenuItem(); + $this->menuItem->setName('Testing'); + $this->menuItem->setFoodVendor($this->vendor); + $this->manager->persist($this->menuItem); $this->manager->flush(); } @@ -53,8 +60,10 @@ final class OrderItemControllerTest extends DbWebTest public function testRemove(): void { $fixture = new OrderItem; - $fixture->setName('Value'); + $fixture->setName('Testing'); $fixture->setExtras('Value'); + $fixture->setMenuItem($this->menuItem); + $fixture->setFoodOrder($this->order); $this->manager->persist($fixture); @@ -72,6 +81,7 @@ final class OrderItemControllerTest extends DbWebTest $orderItem->setName('My Title'); $orderItem->setExtras('My Title'); $orderItem->setFoodOrder($this->order); + $orderItem->setMenuItem($this->menuItem); $this->manager->persist($orderItem); $this->manager->flush(); -- 2.39.5 From 83e1ae3204b3f6103544dda13b3ec1bc5f8953c0 Mon Sep 17 00:00:00 2001 From: Continuous Integration Date: Wed, 26 Jun 2024 18:32:46 +0000 Subject: [PATCH 2/2] Continuous Integration Fixes --- tests/Controller/OrderItemControllerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Controller/OrderItemControllerTest.php b/tests/Controller/OrderItemControllerTest.php index f090f27..a7b0fb8 100644 --- a/tests/Controller/OrderItemControllerTest.php +++ b/tests/Controller/OrderItemControllerTest.php @@ -31,9 +31,10 @@ final class OrderItemControllerTest extends DbWebTest $this->manager->persist($this->order); - $this->menuItem = new MenuItem(); + $this->menuItem = new MenuItem; $this->menuItem->setName('Testing'); $this->menuItem->setFoodVendor($this->vendor); + $this->manager->persist($this->menuItem); $this->manager->flush(); } -- 2.39.5