add menuitem aliases
All checks were successful
/ ls (pull_request) Successful in 2m42s
/ ls (release) Successful in 50s
/ ls (push) Successful in 2m27s

This commit is contained in:
lubiana 2025-01-25 02:14:39 +01:00
parent 70b39515ec
commit 9781bd561f
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
13 changed files with 713 additions and 212 deletions

View file

@ -0,0 +1,50 @@
<?php declare(strict_types=1);
namespace App\DataFixtures;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Override;
use function range;
final class AppFixtures extends Fixture
{
private ObjectManager $manager;
#[Override]
public function load(ObjectManager $manager): void
{
$this->manager = $manager;
$vendorA = $this->createVendor('Vendor A');
$this->addMenuItemsToVendor($vendorA);
$vendorB = $this->createVendor('Vendor B');
$this->addMenuItemsToVendor($vendorB);
}
public function createVendor(string $name): FoodVendor
{
$vendorA = new FoodVendor;
$vendorA->setName($name);
$vendorA->setMenuLink('https://vendora.com');
$vendorA->setPhone('1234567890');
$this->manager->persist($vendorA);
$this->manager->flush();
return $vendorA;
}
public function addMenuItemsToVendor(FoodVendor $vendor): void
{
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();
}
}
}