add food vendor tests
This commit is contained in:
parent
63bf367ab0
commit
a7bec45c48
8 changed files with 39 additions and 53 deletions
|
@ -26,7 +26,9 @@ final class FakeDataCommand extends Command
|
|||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$this->fakeData->resetDb();
|
||||
$this->fakeData->generate();
|
||||
|
||||
$io->success('Added some fake data to database');
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
|
|
@ -20,9 +20,6 @@ class FoodOrder
|
|||
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
||||
private Ulid|null $id = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private DateTimeImmutable $createdAt;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private DateTimeImmutable|null $closedAt = null;
|
||||
|
||||
|
@ -38,7 +35,6 @@ class FoodOrder
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new DateTimeImmutable;
|
||||
$this->orderItems = new ArrayCollection;
|
||||
}
|
||||
|
||||
|
@ -47,16 +43,9 @@ class FoodOrder
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): DateTimeImmutable|null
|
||||
public function getCreatedAt(): DateTimeImmutable
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function setCreatedAt(DateTimeImmutable $createdAt): static
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
|
||||
return $this;
|
||||
return $this->id->getDateTime();
|
||||
}
|
||||
|
||||
public function getClosedAt(): DateTimeImmutable|null
|
||||
|
|
|
@ -31,7 +31,7 @@ final class FoodOrderRepository extends ServiceEntityRepository
|
|||
{
|
||||
$qb = $this->createQueryBuilder('alias');
|
||||
|
||||
$qb->orderBy('alias.createdAt', 'DESC');
|
||||
$qb->orderBy('alias.id', 'DESC');
|
||||
$qb->setMaxResults($limit);
|
||||
|
||||
$query = $qb->getQuery();
|
||||
|
|
|
@ -5,6 +5,9 @@ namespace App\Service;
|
|||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use App\Entity\OrderItem;
|
||||
use App\Repository\FoodOrderRepository;
|
||||
use App\Repository\FoodVendorRepository;
|
||||
use App\Repository\OrderItemRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use function range;
|
||||
|
@ -12,16 +15,32 @@ use function range;
|
|||
final readonly class FakeData
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager
|
||||
private EntityManagerInterface $entityManager,
|
||||
private FoodVendorRepository $foodVendorRepository,
|
||||
private FoodOrderRepository $foodOrderRepository,
|
||||
private OrderItemRepository $orderItemRepository,
|
||||
) {}
|
||||
|
||||
public function generate(): void
|
||||
public function resetDb(): void
|
||||
{
|
||||
$vendors = $this->generateVendors();
|
||||
foreach ($this->orderItemRepository->findAll() as $item) {
|
||||
$this->entityManager->remove($item);
|
||||
}
|
||||
foreach ($this->foodOrderRepository->findAll() as $item) {
|
||||
$this->entityManager->remove($item);
|
||||
}
|
||||
foreach ($this->foodVendorRepository->findAll() as $item) {
|
||||
$this->entityManager->remove($item);
|
||||
}
|
||||
}
|
||||
|
||||
public function generate(int $vendorAmount = 3, int $orderAmount = 4, int $itemAmount = 10): void
|
||||
{
|
||||
$vendors = $this->generateVendors($vendorAmount);
|
||||
foreach ($vendors as $vendor) {
|
||||
$orders = $this->generateOrdersForVendor($vendor);
|
||||
$orders = $this->generateOrdersForVendor($vendor, $orderAmount);
|
||||
foreach ($orders as $order) {
|
||||
$this->generateItemsForOrder($order);
|
||||
$this->generateItemsForOrder($order, $itemAmount);
|
||||
}
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue