diff options
author | Nicolas Hart <contact@nclshart.net> | 2017-07-30 22:04:29 +0200 |
---|---|---|
committer | Nicolas Hart <contact@nclshart.net> | 2017-07-30 22:04:29 +0200 |
commit | af31cfed769538fcb7d283cb1fad80ac8d07b663 (patch) | |
tree | 61117d2944479a9aa814369091991328350ca07d | |
parent | 882da5c5eb283cbc7a869182b26a69b8fbebda2b (diff) | |
download | wallabag-af31cfed769538fcb7d283cb1fad80ac8d07b663.tar.gz wallabag-af31cfed769538fcb7d283cb1fad80ac8d07b663.tar.zst wallabag-af31cfed769538fcb7d283cb1fad80ac8d07b663.zip |
Add list user command
-rw-r--r-- | src/Wallabag/CoreBundle/Command/ListUserCommand.php | 43 | ||||
-rw-r--r-- | tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php | 26 |
2 files changed, 69 insertions, 0 deletions
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 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Command; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
6 | use Symfony\Component\Console\Input\InputInterface; | ||
7 | use Symfony\Component\Console\Output\OutputInterface; | ||
8 | use Symfony\Component\Console\Style\SymfonyStyle; | ||
9 | |||
10 | class ListUserCommand extends ContainerAwareCommand | ||
11 | { | ||
12 | protected function configure() | ||
13 | { | ||
14 | $this | ||
15 | ->setName('wallabag:user:list') | ||
16 | ->setDescription('List all users') | ||
17 | ->setHelp('This command list all existing users') | ||
18 | ; | ||
19 | } | ||
20 | |||
21 | protected function execute(InputInterface $input, OutputInterface $output) | ||
22 | { | ||
23 | $io = new SymfonyStyle($input, $output); | ||
24 | |||
25 | $users = $this->getContainer()->get('wallabag_user.user_repository')->findAll(); | ||
26 | |||
27 | $rows = []; | ||
28 | foreach ($users as $user) { | ||
29 | $rows[] = [ | ||
30 | $user->getUsername(), | ||
31 | $user->getEmail(), | ||
32 | $user->isEnabled() ? 'yes' : 'no', | ||
33 | $user->hasRole('ROLE_SUPER_ADMIN') || $user->hasRole('ROLE_ADMIN') ? 'yes' : 'no', | ||
34 | ]; | ||
35 | } | ||
36 | |||
37 | $io->table(['username', 'email', 'is enabled?', 'is admin?'], $rows); | ||
38 | |||
39 | $io->success(sprintf('%s user(s) displayed.', count($users))); | ||
40 | |||
41 | return 0; | ||
42 | } | ||
43 | } | ||
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 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Command; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
6 | use Symfony\Component\Console\Tester\CommandTester; | ||
7 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
8 | use Wallabag\CoreBundle\Command\ListUserCommand; | ||
9 | |||
10 | class ListUserCommandTest extends WallabagCoreTestCase | ||
11 | { | ||
12 | public function testRunListUserCommand() | ||
13 | { | ||
14 | $application = new Application($this->getClient()->getKernel()); | ||
15 | $application->add(new ListUserCommand()); | ||
16 | |||
17 | $command = $application->find('wallabag:user:list'); | ||
18 | |||
19 | $tester = new CommandTester($command); | ||
20 | $tester->execute([ | ||
21 | 'command' => $command->getName(), | ||
22 | ]); | ||
23 | |||
24 | $this->assertContains('3 user(s) displayed.', $tester->getDisplay()); | ||
25 | } | ||
26 | } | ||