protected function insertUsers(InputInterface $input, OutputInterface $output) { if ($lastUser = $this->doctrine->getRepository('AppBundle:Person')->findOneBy([], ['id' => 'DESC'])) { $startId = $lastUser->getId(); } else { $startId = 0; } $em = $this->doctrine->getManager(); $usercount = $startId + $input->getArgument('usercount'); $faker = \Faker\Factory::create(); for ($i = $startId; $i < $usercount; $i++) { $person = new Person(); $person->setUsername(sprintf('exampleuser%d', $i))->setFirstname($faker->firstName)->setLastname($faker->lastName)->setPassword('password')->setEmail($faker->safeEmail); $output->writeln(sprintf('<info>Added user %s (%s %s)</info>', $person->getUsername(), $person->getFirstname(), $person->getLastname())); $em->persist($person); $em->flush(); } }