protected function execute(InputInterface $input, OutputInterface $output) { $maxResults = $input->getArgument('max-results'); $emails = $this->em->getRepository('AppBundle:User')->createQueryBuilder('u')->select('u.email')->getQuery()->getScalarResult(); array_walk($emails, function (&$result) { $result = $result['email']; }); $generator = Faker\Factory::create('en_GB'); for ($i = 0; $i < 15; ++$i) { $emails[] = $generator->email; } $populator = new Faker\ORM\Doctrine\Populator($generator, $this->em); $populator->addEntity(Post::class, $maxResults, ['authorEmail' => function () use($generator, $emails) { return $generator->randomElement($emails); }, 'slug' => function () use($generator) { return $generator->slug(4); }]); $populator->addEntity(Comment::class, $maxResults * 10); $populator->execute(); }
/** * @Given /^there is subscriber with id (\d+) in database$/ */ public function thereIsSubscriberWithIdInDatabase($id) { $generator = Factory::create(); $populator = new Populator($generator, $this->getDoctrine()->getManager()); $populator->addEntity('FSi\\FixturesBundle\\Entity\\Subscriber', 1, array('id' => $id, 'email' => function () use($generator) { return $generator->email(); })); $populator->execute(); expect(count($this->getEntityRepository('FSi\\FixturesBundle\\Entity\\Subscriber')->findAll()))->toBe(1); }
/** * @Given /^there are (\d+) visible galleries$/ */ public function thereAreVisibleGalleries($galleriesCount) { $generator = Factory::create(); $populator = new Populator($generator, $this->getDoctrine()->getManager()); $populator->addEntity('FSi\\FixturesBundle\\Entity\\Gallery', (int) $galleriesCount, array('visible' => true)); $populator->execute(); }