add order
All checks were successful
/ ls (pull_request) Successful in 27s
/ ls (push) Successful in 27s

This commit is contained in:
Jonas 2024-06-14 17:41:00 +02:00
parent 7663f684a4
commit 1dc5306967
Signed by: lubiana
SSH key fingerprint: SHA256:gkqM8DUX4Blf6P52fycW8ISTd+4eAHH+Uzu9iyc8hAM
37 changed files with 1060 additions and 113 deletions

View file

@ -14,5 +14,8 @@ return static function (ContainerConfigurator $containerConfigurator): void {
__DIR__ . '/../src/DependencyInjection/', __DIR__ . '/../src/DependencyInjection/',
__DIR__ . '/../src/Entity/', __DIR__ . '/../src/Entity/',
__DIR__ . '/../src/Kernel.php', __DIR__ . '/../src/Kernel.php',
__DIR__ . '/../src/Controller/',
]); ]);
$services->load('App\\Controller\\', __DIR__ . '/../src/Controller/')
->tag('controller.service_arguments');
}; };

View file

@ -1,32 +0,0 @@
<?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 Version20240610175726 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('CREATE TABLE food_vendor (id BLOB NOT NULL --(DC2Type:ulid)
, name VARCHAR(50) NOT NULL, PRIMARY KEY(id))');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE food_vendor');
}
}

View file

@ -0,0 +1,44 @@
<?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 Version20240614153440 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('CREATE TABLE food_order (id BLOB NOT NULL --(DC2Type:ulid)
, food_vendor_id BLOB NOT NULL --(DC2Type:ulid)
, created_at DATETIME NOT NULL --(DC2Type:datetime_immutable)
, closed_at DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
, PRIMARY KEY(id), CONSTRAINT FK_44856726EF983E8 FOREIGN KEY (food_vendor_id) REFERENCES food_vendor (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_44856726EF983E8 ON food_order (food_vendor_id)');
$this->addSql('CREATE TABLE food_vendor (id BLOB NOT NULL --(DC2Type:ulid)
, name VARCHAR(50) NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE order_item (id BLOB NOT NULL --(DC2Type:ulid)
, food_order_id BLOB NOT NULL --(DC2Type:ulid)
, name VARCHAR(255) NOT NULL, extras VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id), CONSTRAINT FK_52EA1F09A5D24A7A FOREIGN KEY (food_order_id) REFERENCES food_order (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$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('DROP TABLE food_order');
$this->addSql('DROP TABLE food_vendor');
$this->addSql('DROP TABLE order_item');
}
}

1
public/static/css/simple.min.css vendored Normal file

File diff suppressed because one or more lines are too long

1
public/static/js/htmx.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,72 @@
<?php declare(strict_types=1);
namespace App\Controller;
use App\Entity\FoodOrder;
use App\Form\FoodOrderType;
use App\Repository\FoodOrderRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
#[Route('/food/order')]
final class FoodOrderController extends AbstractController
{
#[Route('/', name: 'app_food_order_index', methods: ['GET'])]
public function index(FoodOrderRepository $foodOrderRepository): Response
{
return $this->render('food_order/index.html.twig', [
'food_orders' => $foodOrderRepository->findAll(),
]);
}
#[Route('/new', name: 'app_food_order_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$foodOrder = new FoodOrder;
$form = $this->createForm(FoodOrderType::class, $foodOrder, [
'action' => $this->generateUrl('app_food_order_new'),
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($foodOrder);
$entityManager->flush();
return $this->redirectToRoute('app_food_order_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('food_order/new.html.twig', [
'food_order' => $foodOrder,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_food_order_show', methods: ['GET'])]
public function show(FoodOrder $foodOrder): Response
{
return $this->render('food_order/show.html.twig', [
'food_order' => $foodOrder,
]);
}
#[Route('/{id}/close', name: 'app_food_order_close', methods: ['GET'])]
public function close(FoodOrder $foodOrder, FoodOrderRepository $repository): Response
{
$repository->save($foodOrder->close());
return $this->redirectToRoute('app_food_order_show', [
'id' => $foodOrder->getId(),
], Response::HTTP_SEE_OTHER);
}
#[Route('/{id}/open', name: 'app_food_order_open', methods: ['GET'])]
public function open(FoodOrder $foodOrder, FoodOrderRepository $repository): Response
{
$repository->save($foodOrder->open());
return $this->redirectToRoute('app_food_order_show', [
'id' => $foodOrder->getId(),
], Response::HTTP_SEE_OTHER);
}
}

View file

@ -67,15 +67,4 @@ final class FoodVendorController extends AbstractController
'form' => $form, 'form' => $form,
]); ]);
} }
#[Route('/{id}', name: 'app_food_vendor_delete', methods: ['POST'])]
public function delete(Request $request, FoodVendor $foodVendor, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete' . $foodVendor->getId(), $request->getPayload()->getString('_token'))) {
$entityManager->remove($foodVendor);
$entityManager->flush();
}
return $this->redirectToRoute('app_food_vendor_index', [], Response::HTTP_SEE_OTHER);
}
} }

View file

@ -1,15 +0,0 @@
<?php declare(strict_types=1);
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
final class Home
{
#[Route('/', name: 'home')]
public function home(): Response
{
return new Response('<h1>Halloo</h1>');
}
}

View file

@ -0,0 +1,17 @@
<?php declare(strict_types=1);
namespace App\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
final class HomeController
{
#[Route('/', name: 'home')]
public function home(UrlGeneratorInterface $router): Response
{
return new RedirectResponse($router->generate('app_food_order_index'));
}
}

View file

@ -0,0 +1,81 @@
<?php declare(strict_types=1);
namespace App\Controller;
use App\Entity\OrderItem;
use App\Form\OrderItemType;
use App\Repository\OrderItemRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
#[Route('/order/item')]
final class OrderItemController extends AbstractController
{
#[Route('/', name: 'app_order_item_index', methods: ['GET'])]
public function index(OrderItemRepository $orderItemRepository): Response
{
return $this->render('order_item/index.html.twig', [
'order_items' => $orderItemRepository->findAll(),
]);
}
#[Route('/new', name: 'app_order_item_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$orderItem = new OrderItem;
$form = $this->createForm(OrderItemType::class, $orderItem);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($orderItem);
$entityManager->flush();
return $this->redirectToRoute('app_order_item_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('order_item/new.html.twig', [
'order_item' => $orderItem,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_order_item_show', methods: ['GET'])]
public function show(OrderItem $orderItem): Response
{
return $this->render('order_item/show.html.twig', [
'order_item' => $orderItem,
]);
}
#[Route('/{id}/edit', name: 'app_order_item_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, OrderItem $orderItem, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(OrderItemType::class, $orderItem);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('app_order_item_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('order_item/edit.html.twig', [
'order_item' => $orderItem,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_order_item_delete', methods: ['POST'])]
public function delete(Request $request, OrderItem $orderItem, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete' . $orderItem->getId(), $request->getPayload()->getString('_token'))) {
$entityManager->remove($orderItem);
$entityManager->flush();
}
return $this->redirectToRoute('app_order_item_index', [], Response::HTTP_SEE_OTHER);
}
}

128
src/Entity/FoodOrder.php Normal file
View file

@ -0,0 +1,128 @@
<?php declare(strict_types=1);
namespace App\Entity;
use App\Repository\FoodOrderRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: FoodOrderRepository::class)]
class FoodOrder
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid|null $id = null;
#[ORM\Column]
private DateTimeImmutable $createdAt;
#[ORM\Column(nullable: true)]
private DateTimeImmutable|null $closedAt = null;
#[ORM\ManyToOne(inversedBy: 'foodOrders')]
#[ORM\JoinColumn(nullable: false)]
private FoodVendor|null $foodVendor = null;
/**
* @var Collection<int, OrderItem>
*/
#[ORM\OneToMany(targetEntity: OrderItem::class, mappedBy: 'foodOrder', orphanRemoval: true)]
private Collection $orderItems;
public function __construct()
{
$this->createdAt = new DateTimeImmutable;
$this->orderItems = new ArrayCollection;
}
public function getId(): Ulid|null
{
return $this->id;
}
public function getCreatedAt(): DateTimeImmutable|null
{
return $this->createdAt;
}
public function setCreatedAt(DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getClosedAt(): DateTimeImmutable|null
{
return $this->closedAt;
}
public function setClosedAt(DateTimeImmutable|null $closedAt): static
{
$this->closedAt = $closedAt;
return $this;
}
public function isClosed(): bool
{
return $this->closedAt instanceof DateTimeImmutable;
}
public function close(): static
{
return $this->setClosedAt(new DateTimeImmutable);
}
public function open(): static
{
return $this->setClosedAt(null);
}
public function getFoodVendor(): FoodVendor|null
{
return $this->foodVendor;
}
public function setFoodVendor(FoodVendor|null $foodVendor): static
{
$this->foodVendor = $foodVendor;
return $this;
}
/**
* @return Collection<int, OrderItem>
*/
public function getOrderItems(): Collection
{
return $this->orderItems;
}
public function addOrderItem(OrderItem $orderItem): static
{
if (! $this->orderItems->contains($orderItem)) {
$this->orderItems->add($orderItem);
$orderItem->setFoodOrder($this);
}
return $this;
}
public function removeOrderItem(OrderItem $orderItem): static
{
// set the owning side to null (unless already changed)
if ($this->orderItems->removeElement($orderItem) && $orderItem->getFoodOrder() === $this) {
$orderItem->setFoodOrder(null);
}
return $this;
}
}

View file

@ -3,6 +3,8 @@
namespace App\Entity; namespace App\Entity;
use App\Repository\FoodVendorRepository; use App\Repository\FoodVendorRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator; use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Bridge\Doctrine\Types\UlidType; use Symfony\Bridge\Doctrine\Types\UlidType;
@ -20,6 +22,17 @@ class FoodVendor
#[ORM\Column(length: 50)] #[ORM\Column(length: 50)]
private string|null $name = null; private string|null $name = null;
/**
* @var Collection<int, FoodOrder>
*/
#[ORM\OneToMany(targetEntity: FoodOrder::class, mappedBy: 'foodVendor', orphanRemoval: true)]
private Collection $foodOrders;
public function __construct()
{
$this->foodOrders = new ArrayCollection;
}
public function getId(): Ulid|null public function getId(): Ulid|null
{ {
return $this->id; return $this->id;
@ -36,4 +49,32 @@ class FoodVendor
return $this; return $this;
} }
/**
* @return Collection<int, FoodOrder>
*/
public function getFoodOrders(): Collection
{
return $this->foodOrders;
}
public function addFoodOrder(FoodOrder $foodOrder): static
{
if (! $this->foodOrders->contains($foodOrder)) {
$this->foodOrders->add($foodOrder);
$foodOrder->setFoodVendor($this);
}
return $this;
}
public function removeFoodOrder(FoodOrder $foodOrder): static
{
// set the owning side to null (unless already changed)
if ($this->foodOrders->removeElement($foodOrder) && $foodOrder->getFoodVendor() === $this) {
$foodOrder->setFoodVendor(null);
}
return $this;
}
} }

70
src/Entity/OrderItem.php Normal file
View file

@ -0,0 +1,70 @@
<?php declare(strict_types=1);
namespace App\Entity;
use App\Repository\OrderItemRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: OrderItemRepository::class)]
class OrderItem
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid|null $id = null;
#[ORM\Column(length: 255)]
private string|null $name = null;
#[ORM\Column(length: 255, nullable: true)]
private string|null $extras = null;
#[ORM\ManyToOne(inversedBy: 'orderItems')]
#[ORM\JoinColumn(nullable: false)]
private FoodOrder|null $foodOrder = null;
public function getId(): Ulid|null
{
return $this->id;
}
public function getName(): string|null
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getExtras(): string|null
{
return $this->extras;
}
public function setExtras(string|null $extras): static
{
$this->extras = $extras;
return $this;
}
public function getFoodOrder(): FoodOrder|null
{
return $this->foodOrder;
}
public function setFoodOrder(FoodOrder|null $foodOrder): static
{
$this->foodOrder = $foodOrder;
return $this;
}
}

View file

@ -0,0 +1,37 @@
<?php declare(strict_types=1);
namespace App\Form;
use App\Entity\FoodOrder;
use App\Entity\FoodVendor;
use Override;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
final class FoodOrderType extends AbstractType
{
#[Override]
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$action = $options['action'] ?? null;
$builder
->add('foodVendor', EntityType::class, [
'class' => FoodVendor::class,
'choice_label' => 'name',
])
;
if ($action !== null) {
$builder->setAction($action);
}
}
#[Override]
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => FoodOrder::class,
]);
}
}

View file

@ -0,0 +1,29 @@
<?php declare(strict_types=1);
namespace App\Form;
use App\Entity\OrderItem;
use Override;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
final class OrderItemType extends AbstractType
{
#[Override]
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name')
->add('extras')
;
}
#[Override]
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => OrderItem::class,
]);
}
}

View file

@ -0,0 +1,26 @@
<?php declare(strict_types=1);
namespace App\Repository;
use App\Entity\FoodOrder;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<FoodOrder>
*/
final class FoodOrderRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, FoodOrder::class);
}
public function save(FoodOrder $order): void
{
$this->getEntityManager()
->persist($order);
$this->getEntityManager()
->flush();
}
}

View file

@ -0,0 +1,43 @@
<?php declare(strict_types=1);
namespace App\Repository;
use App\Entity\OrderItem;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<OrderItem>
*/
final class OrderItemRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, OrderItem::class);
}
// /**
// * @return OrderItem[] Returns an array of OrderItem objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('o')
// ->andWhere('o.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('o.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?OrderItem
// {
// return $this->createQueryBuilder('o')
// ->andWhere('o.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View file

@ -0,0 +1,4 @@
{{ form_start(form) }}
{{ form_widget(form) }}
<button class="btn">{{ button_label|default('Save') }}</button>
{{ form_end(form) }}

View file

@ -4,9 +4,19 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>{% block title %}Welcome!{% endblock %}</title> <title>{% block title %}Welcome!{% endblock %}</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>⚫️</text><text y=%221.3em%22 x=%220.2em%22 font-size=%2276%22 fill=%22%23fff%22>sf</text></svg>"> <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>⚫️</text><text y=%221.3em%22 x=%220.2em%22 font-size=%2276%22 fill=%22%23fff%22>sf</text></svg>">
<link rel="stylesheet" href="/static/css/water.min.css"> <link rel="stylesheet" href="/static/css/simple.min.css">
<script src="/static/js/htmx.min.js"></script>
</head> </head>
<body> <body>
<header>
<nav>
<a href="{{ path('app_food_order_index') }}">Orders</a>
<a href="{{ path('app_food_vendor_index') }}">Vendors</a>
</nav>
</header>
<main>
{% block body %}{% endblock %} {% block body %}{% endblock %}
</body> </main>
</html> </html>

View file

@ -0,0 +1,12 @@
{% extends 'base.html.twig' %}
{% block title %}Edit FoodOrder{% endblock %}
{% block body %}
<h1>Edit FoodOrder</h1>
{{ include('_form.html.twig', {'button_label': 'Update'}) }}
<a href="{{ path('app_food_order_index') }}">back to list</a>
{% endblock %}

View file

@ -0,0 +1,34 @@
{% extends 'base.html.twig' %}
{% block title %}FoodOrder index{% endblock %}
{% block body %}
<h1>FoodOrder index</h1>
<table class="table">
<thead>
<tr>
<th>Vendor</th>
<th>CreatedAt</th>
<th>ClosedAt</th>
<th>actions</th>
</tr>
</thead>
<tbody>
{% for food_order in food_orders %}
{{ include('food_order/table_row.html.twig') }}
{% else %}
<tr>
<td colspan="4">no records found</td>
</tr>
{% endfor %}
</tbody>
</table>
<div>
<button
hx-get="{{ path('app_food_order_new') }}"
hx-trigger="click"
hx-target="closest div"
>Create new</button>
</div>
{% endblock %}

View file

@ -0,0 +1,2 @@
{{ include('_form.html.twig') }}

View file

@ -0,0 +1,31 @@
{% extends 'base.html.twig' %}
{% block title %}FoodOrder{% endblock %}
{% block body %}
<h1>FoodOrder</h1>
<table class="table">
<tbody>
<tr>
<th>Vendor</th>
<td>{{ food_order.foodVendor.name }}</td>
</tr>
<tr>
<th>CreatedAt</th>
<td>{{ food_order.createdAt ? food_order.createdAt|date('Y-m-d H:i:s') : '' }}</td>
</tr>
<tr>
<th>ClosedAt</th>
<td>{{ food_order.closedAt ? food_order.closedAt|date('Y-m-d H:i:s') : '' }}</td>
</tr>
</tbody>
</table>
<a class="button" href="{{ path('app_food_order_index') }}">back to list</a>
{% if(food_order.isClosed) %}
<a class="button" href="{{ path('app_food_order_open', {'id': food_order.id}) }}">reopen</a>
{% else %}
<a class="button" href="{{ path('app_food_order_close', {'id': food_order.id}) }}">close</a>
{% endif %}
{% endblock %}

View file

@ -0,0 +1,8 @@
<tr>
<td>{{ food_order.foodVendor.name }}</td>
<td>{{ food_order.createdAt ? food_order.createdAt|date('Y-m-d H:i:s') : '' }}</td>
<td>{{ food_order.closedAt ? food_order.closedAt|date('Y-m-d H:i:s') : '' }}</td>
<td>
<a href="{{ path('app_food_order_show', {'id': food_order.id}) }}">show</a>
</td>
</tr>

View file

@ -1,4 +0,0 @@
<form method="post" action="{{ path('app_food_vendor_delete', {'id': food_vendor.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ food_vendor.id) }}">
<button class="btn">Delete</button>
</form>

View file

@ -21,6 +21,4 @@
<a href="{{ path('app_food_vendor_index') }}">back to list</a> <a href="{{ path('app_food_vendor_index') }}">back to list</a>
<a href="{{ path('app_food_vendor_edit', {'id': food_vendor.id}) }}">edit</a> <a href="{{ path('app_food_vendor_edit', {'id': food_vendor.id}) }}">edit</a>
{{ include('food_vendor/_delete_form.html.twig') }}
{% endblock %} {% endblock %}

View file

@ -0,0 +1,4 @@
<form method="post" action="{{ path('app_order_item_delete', {'id': order_item.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ order_item.id) }}">
<button class="btn">Delete</button>
</form>

View file

@ -0,0 +1,4 @@
{{ form_start(form) }}
{{ form_widget(form) }}
<button class="btn">{{ button_label|default('Save') }}</button>
{{ form_end(form) }}

View file

@ -0,0 +1,13 @@
{% extends 'base.html.twig' %}
{% block title %}Edit OrderItem{% endblock %}
{% block body %}
<h1>Edit OrderItem</h1>
{{ include('order_item/_form.html.twig', {'button_label': 'Update'}) }}
<a href="{{ path('app_order_item_index') }}">back to list</a>
{{ include('order_item/_delete_form.html.twig') }}
{% endblock %}

View file

@ -0,0 +1,37 @@
{% extends 'base.html.twig' %}
{% block title %}OrderItem index{% endblock %}
{% block body %}
<h1>OrderItem index</h1>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Extras</th>
<th>actions</th>
</tr>
</thead>
<tbody>
{% for order_item in order_items %}
<tr>
<td>{{ order_item.id }}</td>
<td>{{ order_item.name }}</td>
<td>{{ order_item.extras }}</td>
<td>
<a href="{{ path('app_order_item_show', {'id': order_item.id}) }}">show</a>
<a href="{{ path('app_order_item_edit', {'id': order_item.id}) }}">edit</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="4">no records found</td>
</tr>
{% endfor %}
</tbody>
</table>
<a href="{{ path('app_order_item_new') }}">Create new</a>
{% endblock %}

View file

@ -0,0 +1,11 @@
{% extends 'base.html.twig' %}
{% block title %}New OrderItem{% endblock %}
{% block body %}
<h1>Create new OrderItem</h1>
{{ include('order_item/_form.html.twig') }}
<a href="{{ path('app_order_item_index') }}">back to list</a>
{% endblock %}

View file

@ -0,0 +1,30 @@
{% extends 'base.html.twig' %}
{% block title %}OrderItem{% endblock %}
{% block body %}
<h1>OrderItem</h1>
<table class="table">
<tbody>
<tr>
<th>Id</th>
<td>{{ order_item.id }}</td>
</tr>
<tr>
<th>Name</th>
<td>{{ order_item.name }}</td>
</tr>
<tr>
<th>Extras</th>
<td>{{ order_item.extras }}</td>
</tr>
</tbody>
</table>
<a href="{{ path('app_order_item_index') }}">back to list</a>
<a href="{{ path('app_order_item_edit', {'id': order_item.id}) }}">edit</a>
{{ include('order_item/_delete_form.html.twig') }}
{% endblock %}

View file

@ -0,0 +1,114 @@
<?php declare(strict_types=1);
namespace App\Test\Controller;
use App\Entity\FoodOrder;
use App\Tests\DbWebTest;
use Override;
use function sprintf;
final class FoodOrderControllerTest extends DbWebTest
{
private string $path = '/food/order/';
#[Override]
public function getEntityClass(): string
{
return FoodOrder::class;
}
public function testIndex(): void
{
$this->client->request('GET', $this->path);
self::assertResponseStatusCodeSame(200);
self::assertPageTitleContains('FoodOrder index');
// Use the $crawler to perform additional assertions e.g.
// self::assertSame('Some text on the page', $crawler->filter('.p')->first());
}
public function testNew(): void
{
$this->markTestIncomplete();
$this->client->request('GET', sprintf('%snew', $this->path));
self::assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [
'food_order[createdAt]' => 'Testing',
'food_order[closedAt]' => 'Testing',
'food_order[foodVendor]' => 'Testing',
]);
self::assertResponseRedirects($this->path);
self::assertSame(1, $this->repository->count([]));
}
public function testShow(): void
{
$this->markTestIncomplete();
$fixture = new FoodOrder;
$fixture->setCreatedAt('My Title');
$fixture->setClosedAt('My Title');
$fixture->setFoodVendor('My Title');
$this->manager->persist($fixture);
$this->manager->flush();
$this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
self::assertResponseStatusCodeSame(200);
self::assertPageTitleContains('FoodOrder');
// Use assertions to check that the properties are properly displayed.
}
public function testEdit(): void
{
$this->markTestIncomplete();
$fixture = new FoodOrder;
$fixture->setCreatedAt('Value');
$fixture->setClosedAt('Value');
$fixture->setFoodVendor('Value');
$this->manager->persist($fixture);
$this->manager->flush();
$this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId()));
$this->client->submitForm('Update', [
'food_order[createdAt]' => 'Something New',
'food_order[closedAt]' => 'Something New',
'food_order[foodVendor]' => 'Something New',
]);
self::assertResponseRedirects('/food/order/');
$fixture = $this->repository->findAll();
self::assertSame('Something New', $fixture[0]->getCreatedAt());
self::assertSame('Something New', $fixture[0]->getClosedAt());
self::assertSame('Something New', $fixture[0]->getFoodVendor());
}
public function testRemove(): void
{
$this->markTestIncomplete();
$fixture = new FoodOrder;
$fixture->setCreatedAt('Value');
$fixture->setClosedAt('Value');
$fixture->setFoodVendor('Value');
$this->manager->persist($fixture);
$this->manager->flush();
$this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
$this->client->submitForm('Delete');
self::assertResponseRedirects('/food/order/');
self::assertSame(0, $this->repository->count([]));
}
}

View file

@ -3,43 +3,15 @@
namespace App\Test\Controller; namespace App\Test\Controller;
use App\Entity\FoodVendor; use App\Entity\FoodVendor;
use Doctrine\ORM\EntityManagerInterface; use App\Tests\DbWebTest;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Tools\SchemaTool;
use Override; use Override;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use function sprintf; use function sprintf;
final class FoodVendorControllerTest extends WebTestCase final class FoodVendorControllerTest extends DbWebTest
{ {
private KernelBrowser $client;
private EntityManagerInterface $manager;
private EntityRepository $repository;
private string $path = '/food/vendor/'; private string $path = '/food/vendor/';
private function initDataBase(): void
{
(new SchemaTool($this->manager))
->createSchema($this->manager->getMetadataFactory()->getAllMetadata());
}
#[Override]
protected function setUp(): void
{
$this->client = static::createClient();
$this->manager = static::getContainer()->get('doctrine')->getManager();
$this->initDataBase();
$this->repository = $this->manager->getRepository(FoodVendor::class);
foreach ($this->repository->findAll() as $object) {
$this->manager->remove($object);
}
$this->manager->flush();
}
public function testIndex(): void public function testIndex(): void
{ {
$this->client->request('GET', $this->path); $this->client->request('GET', $this->path);
@ -121,4 +93,10 @@ final class FoodVendorControllerTest extends WebTestCase
self::assertResponseRedirects('/food/vendor/'); self::assertResponseRedirects('/food/vendor/');
self::assertSame(0, $this->repository->count([])); self::assertSame(0, $this->repository->count([]));
} }
#[Override]
public function getEntityClass(): string
{
return FoodVendor::class;
}
} }

View file

@ -1,17 +0,0 @@
<?php declare(strict_types=1);
namespace App\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
final class HomeTest extends WebTestCase
{
public function testSomething(): void
{
$client = static::createClient();
$client->request('GET', '/');
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('h1', 'Halloo');
}
}

View file

@ -0,0 +1,108 @@
<?php declare(strict_types=1);
namespace App\Test\Controller;
use App\Entity\OrderItem;
use App\Tests\DbWebTest;
use Override;
use function sprintf;
final class OrderItemControllerTest extends DbWebTest
{
private string $path = '/order/item/';
public function testIndex(): void
{
$this->client->request('GET', $this->path);
self::assertResponseStatusCodeSame(200);
self::assertPageTitleContains('OrderItem index');
// Use the $crawler to perform additional assertions e.g.
// self::assertSame('Some text on the page', $crawler->filter('.p')->first());
}
public function testNew(): void
{
$this->markTestIncomplete();
$this->client->request('GET', sprintf('%snew', $this->path));
self::assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [
'order_item[name]' => 'Testing',
'order_item[extras]' => 'Testing',
]);
self::assertResponseRedirects($this->path);
self::assertSame(1, $this->repository->count([]));
}
public function testShow(): void
{
$this->markTestIncomplete();
$fixture = new OrderItem;
$fixture->setName('My Title');
$fixture->setExtras('My Title');
$this->manager->persist($fixture);
$this->manager->flush();
$this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
self::assertResponseStatusCodeSame(200);
self::assertPageTitleContains('OrderItem');
// Use assertions to check that the properties are properly displayed.
}
public function testEdit(): void
{
$this->markTestIncomplete();
$fixture = new OrderItem;
$fixture->setName('Value');
$fixture->setExtras('Value');
$this->manager->persist($fixture);
$this->manager->flush();
$this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId()));
$this->client->submitForm('Update', [
'order_item[name]' => 'Something New',
'order_item[extras]' => 'Something New',
]);
self::assertResponseRedirects('/order/item/');
$fixture = $this->repository->findAll();
self::assertSame('Something New', $fixture[0]->getName());
self::assertSame('Something New', $fixture[0]->getExtras());
}
public function testRemove(): void
{
$this->markTestIncomplete();
$fixture = new OrderItem;
$fixture->setName('Value');
$fixture->setExtras('Value');
$this->manager->persist($fixture);
$this->manager->flush();
$this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
$this->client->submitForm('Delete');
self::assertResponseRedirects('/order/item/');
self::assertSame(0, $this->repository->count([]));
}
#[Override]
public function getEntityClass(): string
{
return OrderItem::class;
}
}

35
tests/DbWebTest.php Normal file
View file

@ -0,0 +1,35 @@
<?php declare(strict_types=1);
namespace App\Tests;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Tools\SchemaTool;
use Override;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
abstract class DbWebTest extends WebTestCase
{
abstract public function getEntityClass(): string;
protected KernelBrowser $client;
protected EntityManagerInterface $manager;
protected EntityRepository $repository;
#[Override]
protected function setUp(): void
{
$this->client = static::createClient();
$this->manager = static::getContainer()->get('doctrine')->getManager();
(new SchemaTool($this->manager))
->createSchema($this->manager->getMetadataFactory()->getAllMetadata());
$this->repository = $this->manager->getRepository($this->getEntityClass());
foreach ($this->repository->findAll() as $object) {
$this->manager->remove($object);
}
$this->manager->flush();
}
}