#64: wip add phonenumberfield to foodvendor
This commit is contained in:
parent
2d3100b5c9
commit
b65a4814f4
6 changed files with 75 additions and 3 deletions
35
migrations/Version20241218235101.php
Normal file
35
migrations/Version20241218235101.php
Normal 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');
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -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<int, FoodOrder>
|
||||
*/
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ final class FoodVendorType extends AbstractType
|
|||
$builder
|
||||
->add('name')
|
||||
->add('menuLink')
|
||||
->add('phone')
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue