add simple apitest
This commit is contained in:
parent
d92a63fd7d
commit
b00b923d43
13 changed files with 349 additions and 8 deletions
|
@ -2,8 +2,10 @@
|
|||
|
||||
namespace App\DataFixtures;
|
||||
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\MenuItem;
|
||||
use App\Entity\OrderItem;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Override;
|
||||
|
@ -39,12 +41,26 @@ final class AppFixtures extends Fixture
|
|||
|
||||
public function addMenuItemsToVendor(FoodVendor $vendor): void
|
||||
{
|
||||
$menuItems = [];
|
||||
foreach (range(1, 10) as $i) {
|
||||
$item = new MenuItem;
|
||||
$item->setName("{$vendor->getName()} Item {$i}");
|
||||
$item->setFoodVendor($vendor);
|
||||
$this->manager->persist($item);
|
||||
$this->manager->flush();
|
||||
$menuItems[] = $item;
|
||||
}
|
||||
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($vendor);
|
||||
|
||||
$this->manager->persist($order);
|
||||
foreach ($menuItems as $item) {
|
||||
$orderItem = new OrderItem;
|
||||
$orderItem->setMenuItem($item);
|
||||
$orderItem->setCreatedBy('John');
|
||||
$order->addOrderItem($orderItem);
|
||||
$this->manager->persist($orderItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ class FoodOrder
|
|||
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
||||
private Ulid|null $id = new Ulid
|
||||
) {
|
||||
$this->id ??= new Ulid;
|
||||
$this->orderItems = new ArrayCollection;
|
||||
$this->open();
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ class FoodVendor
|
|||
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
||||
private Ulid|null $id = new Ulid
|
||||
) {
|
||||
$this->id ??= new Ulid;
|
||||
$this->foodOrders = new ArrayCollection;
|
||||
$this->menuItems = new ArrayCollection;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ class MenuItem
|
|||
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
||||
private Ulid|null $id = new Ulid
|
||||
) {
|
||||
$this->id ??= new Ulid;
|
||||
$this->aliases = new ArrayCollection;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,12 +13,6 @@ use Symfony\Component\Uid\Ulid;
|
|||
#[ApiResource]
|
||||
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;
|
||||
|
||||
|
@ -38,6 +32,16 @@ class OrderItem
|
|||
])]
|
||||
private string|null $createdBy = 'nobody';
|
||||
|
||||
public function __construct(
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
||||
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
||||
private Ulid|null $id = new Ulid
|
||||
) {
|
||||
$this->id ??= new Ulid;
|
||||
}
|
||||
|
||||
public function getId(): Ulid|null
|
||||
{
|
||||
return $this->id;
|
||||
|
@ -87,6 +91,7 @@ class OrderItem
|
|||
public function setMenuItem(MenuItem|null $menuItem): static
|
||||
{
|
||||
$this->menuItem = $menuItem;
|
||||
$this->name = $menuItem->getName();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue