From af31cfed769538fcb7d283cb1fad80ac8d07b663 Mon Sep 17 00:00:00 2001 From: Nicolas Hart Date: Sun, 30 Jul 2017 22:04:29 +0200 Subject: [PATCH] Add list user command --- .../CoreBundle/Command/ListUserCommand.php | 43 +++++++++++++++++++ .../Command/ListUserCommandTest.php | 26 +++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/Wallabag/CoreBundle/Command/ListUserCommand.php create mode 100644 tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php diff --git a/src/Wallabag/CoreBundle/Command/ListUserCommand.php b/src/Wallabag/CoreBundle/Command/ListUserCommand.php new file mode 100644 index 00000000..852e93b7 --- /dev/null +++ b/src/Wallabag/CoreBundle/Command/ListUserCommand.php @@ -0,0 +1,43 @@ +setName('wallabag:user:list') + ->setDescription('List all users') + ->setHelp('This command list all existing users') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new SymfonyStyle($input, $output); + + $users = $this->getContainer()->get('wallabag_user.user_repository')->findAll(); + + $rows = []; + foreach ($users as $user) { + $rows[] = [ + $user->getUsername(), + $user->getEmail(), + $user->isEnabled() ? 'yes' : 'no', + $user->hasRole('ROLE_SUPER_ADMIN') || $user->hasRole('ROLE_ADMIN') ? 'yes' : 'no', + ]; + } + + $io->table(['username', 'email', 'is enabled?', 'is admin?'], $rows); + + $io->success(sprintf('%s user(s) displayed.', count($users))); + + return 0; + } +} diff --git a/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php new file mode 100644 index 00000000..5e644247 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php @@ -0,0 +1,26 @@ +getClient()->getKernel()); + $application->add(new ListUserCommand()); + + $command = $application->find('wallabag:user:list'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + ]); + + $this->assertContains('3 user(s) displayed.', $tester->getDisplay()); + } +} -- 2.41.0