Advertisement
JLChafardet

NovelFixtures Fixtures file

Mar 5th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\DataFixtures;
  4.  
  5. use App\Entity\Novel;
  6. use App\Entity\Author;
  7. use Doctrine\Common\DataFixtures\DependentFixtureInterface;
  8. use Doctrine\Common\Persistence\ObjectManager;
  9.  
  10. class NovelFixtures extends BaseFixture implements DependentFixtureInterface
  11. {
  12.     public function loadData(ObjectManager $manager)
  13.     {
  14.         $this->createMany(Novel::class, 100, function(Novel $novel, $count) {
  15.             $novel->setTitle($this->faker->sentence($nbWords = 4, $variableNbWords = true));
  16.             $novel->setVisibility($this->faker->boolean($chanceOfGettingTrue = 85));
  17.             $novel->setPublishedAt($this->faker->dateTime(null, $max = '-1 year'));
  18.             $novel->setDescription($this->faker->paragraph($nbSentences = 3, $variableNbSentences = true));
  19.             $novel->setCoverImage($this->faker->imageUrl($width = 175, $height = 225, null, false, $this->faker->word()));
  20.             $novel->setAuthor($this->getRandomReference(Author::class));
  21.  
  22.         });
  23.  
  24.         $manager->flush();
  25.     }
  26.  
  27.     public function getDependencies()
  28.     {
  29.         return [Author::class];
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement