1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Codeception\Module\Drupal\UserRegistry\Command; |
4
|
|
|
|
5
|
|
|
use Codeception\Exception\Module as ModuleException; |
6
|
|
|
use Symfony\Component\Console\Command\Command; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class CreateTestUsersCommand. |
13
|
|
|
* |
14
|
|
|
* @package Codeception\Module\DrupalUserRegistry\Command\TestUsersCommand |
15
|
|
|
*/ |
16
|
|
View Code Duplication |
class CreateTestUsersCommand extends Command |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
use TestUsersCommandTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Configuration for this command. |
22
|
|
|
*/ |
23
|
|
|
protected function configure() |
24
|
|
|
{ |
25
|
|
|
$this |
26
|
|
|
->setName('users:create') |
27
|
|
|
->setDescription('Create test users.') |
28
|
|
|
->addArgument( |
29
|
|
|
'suite', |
30
|
|
|
InputArgument::OPTIONAL, |
31
|
|
|
"Which suite configuration to use. Defaults to 'acceptance'." |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Execute command: create any defined test users on the configured Drush alias. |
37
|
|
|
* |
38
|
|
|
* @todo Codeception debug calls won't work here. |
39
|
|
|
* |
40
|
|
|
* @param InputInterface $input |
41
|
|
|
* The command input. |
42
|
|
|
* |
43
|
|
|
* @param OutputInterface $output |
44
|
|
|
* The command output. |
45
|
|
|
* |
46
|
|
|
* @return int|null|void |
47
|
|
|
* |
48
|
|
|
* @throws ModuleException |
49
|
|
|
*/ |
50
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
51
|
|
|
{ |
52
|
|
|
// The suite name can be passed as an argument. Without it, the command defaults to 'acceptance'. |
53
|
|
|
$suiteName = $input->getArgument('suite'); |
54
|
|
|
if (!$suiteName) { |
55
|
|
|
$suiteName = 'acceptance'; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$this->getTestUsers($suiteName); |
59
|
|
|
$this->testUserManager->createUsers($this->users); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.