Author: Matthieu Bontemps (matthieu@knplabs.com)
Author: Thibault Duplessis (thibault.duplessis@gmail.com)
Author: Luis Cordova (cordoval@gmail.com)
Inheritance: extends Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
 private function createCommandTester(ContainerInterface $container, Application $application = null)
 {
     if (null === $application) {
         $application = new Application();
     }
     $application->setAutoExit(false);
     $command = new CreateUserCommand();
     $command->setContainer($container);
     $application->add($command);
     return new CommandTester($application->find('fos:user:create'));
 }
Example #2
0
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     parent::interact($input, $output);
     if (!$input->getArgument('firstname')) {
         $firstname = $this->getHelper('dialog')->askAndValidate($output, 'Please choose a firstname:', function ($firstname) {
             if (empty($firstname)) {
                 throw new \Exception('Firstname can not be empty');
             }
             return $firstname;
         });
         $input->setArgument('firstname', $firstname);
     }
     if (!$input->getArgument('lastname')) {
         $lastname = $this->getHelper('dialog')->askAndValidate($output, 'Please choose a lastname:', function ($lastname) {
             if (empty($lastname)) {
                 throw new \Exception('Lastname can not be empty');
             }
             return $lastname;
         });
         $input->setArgument('lastname', $lastname);
     }
     if (!$input->getArgument('enterprise')) {
         $enterprise = $this->getHelper('dialog')->askAndValidate($output, 'Please choose an enterprise:', function ($enterprise) {
             if (empty($enterprise)) {
                 throw new \Exception('Enterprise can not be empty');
             }
             return $enterprise;
         });
         $input->setArgument('enterprise', $enterprise);
     }
 }
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     /** @var UserDiscriminatorInterface $discriminator */
     $discriminator = $this->getContainer()->get('rollerworks_multi_user.user_discriminator');
     $discriminator->setCurrentUser($input->getOption('user-system'));
     parent::interact($input, $output);
 }
 public function testUserCreationWithOptions()
 {
     $kernel = $this->createKernel();
     $command = new CreateUserCommand();
     $application = new Application($kernel);
     $application->setAutoExit(false);
     $tester = new ApplicationTester($application);
     $username = '******';
     $password = '******';
     $email = '*****@*****.**';
     $tester->run(array('command' => $command->getFullName(), 'username' => $username, 'password' => $password, 'email' => $email, '--inactive' => true, '--super-admin' => true), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
     $userManager = $this->getService('fos_user.user_manager');
     $user = $userManager->findUserByUsername($username);
     $this->assertTrue($user instanceof User);
     $this->assertEquals($email, $user->getEmail());
     $this->assertFalse($user->isEnabled());
     $this->assertTrue($user->hasRole('ROLE_SUPERADMIN'));
     $userManager->deleteUser($user);
 }
 /**
  * @see Command
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     //list available databases without prefix
     $dbs_list = 'Available databases:' . "\n";
     $dbs_array = $this->database_list();
     foreach ($dbs_array as $db) {
         $dbs_list .= '- ' . $db . "\n";
     }
     parent::interact($input, $output);
     //display help
     if (!$input->getArgument('dbName')) {
         $dbName = $this->getHelper('dialog')->askAndValidate($output, $dbs_list . 'Please choose a database name in the list (otherwise, new database will be created):', function ($dbName) {
             if (empty($dbName)) {
                 throw new \Exception('Database name can not be empty');
             }
             return $dbName;
         });
         $input->setArgument('dbName', $dbName);
     }
 }
Example #6
0
 /**
  * @see Command
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     parent::interact($input, $output);
     if (!$input->getArgument('nom')) {
         $nom = $this->getHelper('dialog')->askAndValidate($output, 'Please choose a lastname:', function ($nom) {
             if (empty($nom)) {
                 throw new \Exception('Lastname can not be empty');
             }
             return $nom;
         });
         $input->setArgument('nom', $nom);
     }
     if (!$input->getArgument('prenom')) {
         $prenom = $this->getHelper('dialog')->askAndValidate($output, 'Please choose a firstname:', function ($prenom) {
             if (empty($prenom)) {
                 throw new \Exception('firstname can not be empty');
             }
             return $prenom;
         });
         $input->setArgument('prenom', $prenom);
     }
 }
 /**
  * @see Command
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     parent::interact($input, $output);
     if (!$input->getArgument('nom')) {
         $firstname = $this->getHelper('dialog')->askAndValidate($output, 'Please choose a firstname:', function ($firstname) {
             if (empty($firstname)) {
                 throw new \Exception('Firstname can not be empty');
             }
             return $firstname;
         });
         $input->setArgument('nom', $firstname);
     }
     if (!$input->getArgument('prenoms')) {
         $lastname = $this->getHelper('dialog')->askAndValidate($output, 'Please choose a lastname:', function ($lastname) {
             if (empty($lastname)) {
                 throw new \Exception('Lastname can not be empty');
             }
             return $lastname;
         });
         $input->setArgument('prenoms', $lastname);
     }
     if (!$input->getArgument('dateNaissance')) {
         $birthday = $this->getHelper('dialog')->askAndValidate($output, 'Please choose a birthday:', function ($birthday) {
             if (empty($birthday)) {
                 throw new \Exception('birthday can not be empty');
             }
             return $birthday;
         });
         $input->setArgument('dateNaissance', $birthday);
     }
     if (!$input->getArgument('sexe')) {
         $gender = $this->getHelper('dialog')->askAndValidate($output, 'Please choose a gender (M=1) (F=2) :', function ($gender) {
             if (empty($gender)) {
                 throw new \Exception('gender can not be empty');
             }
             return $gender;
         });
         $input->setArgument('sexe', $gender);
     }
     if (!$input->getArgument('adresse')) {
         $address = $this->getHelper('dialog')->askAndValidate($output, 'Please choose an address :', function ($address) {
             if (empty($address)) {
                 throw new \Exception('address can not be empty');
             }
             return $address;
         });
         $input->setArgument('adresse', $address);
     }
     if (!$input->getArgument('telephone')) {
         $telephone = $this->getHelper('dialog')->askAndValidate($output, 'Please choose a telephone number :', function ($telephone) {
             return $telephone;
         });
         $input->setArgument('telephone', $telephone);
     }
     if (!$input->getArgument('image')) {
         $image = $this->getHelper('dialog')->askAndValidate($output, 'Please choose a picture :', function ($image) {
             return $image;
         });
         $input->setArgument('image', $image);
     }
 }