![public function create(string|array $references = null): UnavailablePeriod { /** @var User $user */ $randomUser = $this->getRandomReferenceByClass(User::class); $invoice = (new Invoice()) ->setCreatedAt(new DateTimeImmutable()) // the current number, auto-incrementation and save() ->setNumber(InvoiceFixture::count()) // a random User ->setUser($this->getRandomReferenceByClass(User::class)) // randomly a value of Status Enum ->setStatus(self::randomValue(Status::cases())) // randomly True or False ->setConfirmed(self::randomValue([True, False])) // Add random sentence or randomly NULL ->setComment(self::randomValue([null, self::getFaker()->sentence()])) ; // Add references and persist $this->save($invoice, $references); return $invoice; }](https://pbs.twimg.com/media/F3z_FOqXAAAMzTj.jpg?name=small&format=webp)
ALT public function create(string|array $references = null): UnavailablePeriod { /** @var User $user */ $randomUser = $this->getRandomReferenceByClass(User::class); $invoice = (new Invoice()) ->setCreatedAt(new DateTimeImmutable()) // the current number, auto-incrementation and save() ->setNumber(InvoiceFixture::count()) // a random User ->setUser($this->getRandomReferenceByClass(User::class)) // randomly a value of Status Enum ->setStatus(self::randomValue(Status::cases())) // randomly True or False ->setConfirmed(self::randomValue([True, False])) // Add random sentence or randomly NULL ->setComment(self::randomValue([null, self::getFaker()->sentence()])) ; // Add references and persist $this->save($invoice, $references); return $invoice; }
![class UserFixture extends Fixture implements DependentFixtureInterface { public function load(ObjectManager $manager): void { // Use this function to loop through all companies and create users for them. /** @var array<Company> $companies */ $companies = $this->getReferencesByClass(Company::class); // Need a random company? Use this method. /** @var Company $company */ $company = $this->getRandomReferenceByClass(Company::class); } public function create(string|array $references = null): User { // You can also use it in the template to add a default random company. /** @var Company $company */ $company = $this->getRandomReferenceByClass(Company::class); // .. } public function getDependencies(): array { return [ CompanyFixture::class, ]; } }](https://pbs.twimg.com/media/F3z-QWnWwAARGXe.png?name=small&format=webp)
ALT class UserFixture extends Fixture implements DependentFixtureInterface { public function load(ObjectManager $manager): void { // Use this function to loop through all companies and create users for them. /** @var array<Company> $companies */ $companies = $this->getReferencesByClass(Company::class); // Need a random company? Use this method. /** @var Company $company */ $company = $this->getRandomReferenceByClass(Company::class); } public function create(string|array $references = null): User { // You can also use it in the template to add a default random company. /** @var Company $company */ $company = $this->getRandomReferenceByClass(Company::class); // .. } public function getDependencies(): array { return [ CompanyFixture::class, ]; } }

ALT class CompanyFixtures extends Marty\McFly\Fixture { public function load(ObjectManager $manager): void { // A simple call to Create a random Company, addReference and Persist. $this->create(); // Use a loop to create many for ($i=0 ; $i<10 ; $i++) { // Override the default entity $this->create() ->setCity('Paris') ->setPostalCode('75000'); } // Finally, flush to the database $manager->flush(); } public function create(array|string $references = null): object { $company = (new Company()) ->setName(self::getFaker()->company()) ->setAddress(self::getFaker()->address()) ->setCity(self::getFaker()->city()) ->setPostalCode(self::getFaker()->postcode()); $this->save($company, $references); return $company; } }












