#64: wip add phonenumberfield to foodvendor

This commit is contained in:
Jonas 2024-12-19 01:11:09 +01:00
parent 2d3100b5c9
commit b65a4814f4
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
6 changed files with 75 additions and 3 deletions

View file

@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241218235101 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->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');
}
}

View file

@ -23,8 +23,10 @@ final class FoodVendorController extends AbstractController
} }
#[Route('/new', name: 'app_food_vendor_new', methods: ['GET', 'POST'])] #[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; $foodVendor = new FoodVendor;
$form = $this->createForm(FoodVendorType::class, $foodVendor); $form = $this->createForm(FoodVendorType::class, $foodVendor);
$form->handleRequest($request); $form->handleRequest($request);
@ -63,7 +65,6 @@ final class FoodVendorController extends AbstractController
} }
return $this->render('food_vendor/edit.html.twig', [ return $this->render('food_vendor/edit.html.twig', [
'food_vendor' => $foodVendor,
'form' => $form, 'form' => $form,
]); ]);
} }

View file

@ -16,6 +16,11 @@ class FoodVendor
#[ORM\Column(length: 50)] #[ORM\Column(length: 50)]
private string|null $name = null; private string|null $name = null;
#[ORM\Column(length: 50, nullable: true, options: [
'default' => "",
])]
private string|null $phone = null;
/** /**
* @var Collection<int, FoodOrder> * @var Collection<int, FoodOrder>
*/ */
@ -131,4 +136,15 @@ class FoodVendor
return $this; return $this;
} }
public function getPhone(): string|null
{
return $this->phone;
}
public function setPhone(string|null $phone): static
{
$this->phone = $phone;
return $this;
}
} }

View file

@ -16,6 +16,7 @@ final class FoodVendorType extends AbstractType
$builder $builder
->add('name') ->add('name')
->add('menuLink') ->add('menuLink')
->add('phone')
; ;
} }

View file

@ -114,6 +114,8 @@ final class FoodVendorControllerTest extends DbWebTest
{ {
$fixture = new FoodVendor; $fixture = new FoodVendor;
$fixture->setName('Value'); $fixture->setName('Value');
$fixture->setMenuLink('Value');
$fixture->setPhone('Value');
$this->manager->persist($fixture); $this->manager->persist($fixture);
$this->manager->flush(); $this->manager->flush();
@ -125,10 +127,23 @@ final class FoodVendorControllerTest extends DbWebTest
->attr('value', ''), ->attr('value', ''),
'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', [ $this->client->submitForm('Update', [
'food_vendor[name]' => 'Something New', 'food_vendor[name]' => 'Something New',
'food_vendor[menuLink]' => 'https://example.com/', 'food_vendor[menuLink]' => 'https://example.com/',
'food_vendor[phone]' => '1234567890',
]); ]);
self::assertResponseRedirects('/food/vendor/'); self::assertResponseRedirects('/food/vendor/');
@ -137,6 +152,7 @@ final class FoodVendorControllerTest extends DbWebTest
self::assertSame('Something New', $fixture[0]->getName()); self::assertSame('Something New', $fixture[0]->getName());
self::assertSame('https://example.com/', $fixture[0]->getMenuLink()); self::assertSame('https://example.com/', $fixture[0]->getMenuLink());
self::assertSame('1234567890', $fixture[0]->getPhone());
} }
#[Override] #[Override]

View file

@ -16,6 +16,9 @@ final class FoodVendorTest extends TestCase
$vendor->setName('Test'); $vendor->setName('Test');
$this->assertEquals('Test', $vendor->getName()); $this->assertEquals('Test', $vendor->getName());
$this->assertInstanceOf(Ulid::class, $vendor->getId()); $this->assertInstanceOf(Ulid::class, $vendor->getId());
$this->assertEmpty($vendor->getPhone());
$vendor->setPhone('1234567890');
$this->assertEquals('1234567890', $vendor->getPhone());
$this->assertCount(0, $vendor->getFoodOrders()); $this->assertCount(0, $vendor->getFoodOrders());
$order1 = new FoodOrder; $order1 = new FoodOrder;