diff --git a/migrations/Version20241218235101.php b/migrations/Version20241218235101.php new file mode 100644 index 0000000..86337fa --- /dev/null +++ b/migrations/Version20241218235101.php @@ -0,0 +1,35 @@ +addSql('ALTER TABLE food_vendor ADD COLUMN phone VARCHAR(50) DEFAULT \'\''); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE TEMPORARY TABLE __temp__food_vendor AS SELECT name, menu_link, id FROM food_vendor'); + $this->addSql('DROP TABLE food_vendor'); + $this->addSql('CREATE TABLE food_vendor (name VARCHAR(50) NOT NULL, menu_link VARCHAR(255) DEFAULT NULL, id BLOB NOT NULL, PRIMARY KEY(id))'); + $this->addSql('INSERT INTO food_vendor (name, menu_link, id) SELECT name, menu_link, id FROM __temp__food_vendor'); + $this->addSql('DROP TABLE __temp__food_vendor'); + } +} diff --git a/src/Controller/FoodVendorController.php b/src/Controller/FoodVendorController.php index 0cb790a..283eae9 100644 --- a/src/Controller/FoodVendorController.php +++ b/src/Controller/FoodVendorController.php @@ -23,8 +23,10 @@ final class FoodVendorController extends AbstractController } #[Route('/new', name: 'app_food_vendor_new', methods: ['GET', 'POST'])] - public function new(Request $request, EntityManagerInterface $entityManager): Response - { + public function new( + Request $request, + EntityManagerInterface $entityManager + ): Response { $foodVendor = new FoodVendor; $form = $this->createForm(FoodVendorType::class, $foodVendor); $form->handleRequest($request); @@ -63,7 +65,6 @@ final class FoodVendorController extends AbstractController } return $this->render('food_vendor/edit.html.twig', [ - 'food_vendor' => $foodVendor, 'form' => $form, ]); } diff --git a/src/Entity/FoodVendor.php b/src/Entity/FoodVendor.php index b688136..749aa63 100644 --- a/src/Entity/FoodVendor.php +++ b/src/Entity/FoodVendor.php @@ -16,6 +16,11 @@ class FoodVendor #[ORM\Column(length: 50)] private string|null $name = null; + #[ORM\Column(length: 50, nullable: true, options: [ + 'default' => "", + ])] + private string|null $phone = null; + /** * @var Collection */ @@ -131,4 +136,15 @@ class FoodVendor return $this; } + + public function getPhone(): string|null + { + return $this->phone; + } + + public function setPhone(string|null $phone): static + { + $this->phone = $phone; + return $this; + } } diff --git a/src/Form/FoodVendorType.php b/src/Form/FoodVendorType.php index 9c155f6..7ff61da 100644 --- a/src/Form/FoodVendorType.php +++ b/src/Form/FoodVendorType.php @@ -16,6 +16,7 @@ final class FoodVendorType extends AbstractType $builder ->add('name') ->add('menuLink') + ->add('phone') ; } diff --git a/tests/Controller/FoodVendorControllerTest.php b/tests/Controller/FoodVendorControllerTest.php index b475fa1..5e50526 100644 --- a/tests/Controller/FoodVendorControllerTest.php +++ b/tests/Controller/FoodVendorControllerTest.php @@ -114,6 +114,8 @@ final class FoodVendorControllerTest extends DbWebTest { $fixture = new FoodVendor; $fixture->setName('Value'); + $fixture->setMenuLink('Value'); + $fixture->setPhone('Value'); $this->manager->persist($fixture); $this->manager->flush(); @@ -125,10 +127,23 @@ final class FoodVendorControllerTest extends DbWebTest ->attr('value', ''), 'Value' ); + $this->assertSame( + $crawler->filter('#food_vendor_menuLink') + ->last() + ->attr('value', ''), + 'Value' + ); + $this->assertSame( + $crawler->filter('#food_vendor_phone') + ->last() + ->attr('value', ''), + 'Value' + ); $this->client->submitForm('Update', [ 'food_vendor[name]' => 'Something New', 'food_vendor[menuLink]' => 'https://example.com/', + 'food_vendor[phone]' => '1234567890', ]); self::assertResponseRedirects('/food/vendor/'); @@ -137,6 +152,7 @@ final class FoodVendorControllerTest extends DbWebTest self::assertSame('Something New', $fixture[0]->getName()); self::assertSame('https://example.com/', $fixture[0]->getMenuLink()); + self::assertSame('1234567890', $fixture[0]->getPhone()); } #[Override] diff --git a/tests/Entity/FoodVendorTest.php b/tests/Entity/FoodVendorTest.php index daa90c6..7fcd698 100644 --- a/tests/Entity/FoodVendorTest.php +++ b/tests/Entity/FoodVendorTest.php @@ -16,6 +16,9 @@ final class FoodVendorTest extends TestCase $vendor->setName('Test'); $this->assertEquals('Test', $vendor->getName()); $this->assertInstanceOf(Ulid::class, $vendor->getId()); + $this->assertEmpty($vendor->getPhone()); + $vendor->setPhone('1234567890'); + $this->assertEquals('1234567890', $vendor->getPhone()); $this->assertCount(0, $vendor->getFoodOrders()); $order1 = new FoodOrder;