1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerTest\Shared\Testify\Fixtures; |
9
|
|
|
|
10
|
|
|
use Codeception\Codecept; |
11
|
|
|
use Codeception\Command\Run; |
12
|
|
|
use Codeception\Command\Shared\ConfigTrait; |
13
|
|
|
use Codeception\Configuration; |
14
|
|
|
use Codeception\CustomCommandInterface; |
15
|
|
|
use Codeception\Exception\TestRuntimeException; |
16
|
|
|
use PHPUnit\Runner\Version; |
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Input\InputOption; |
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
20
|
|
|
|
21
|
|
|
class FixturesCommand extends Run implements CustomCommandInterface |
22
|
|
|
{ |
23
|
|
|
use ConfigTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var int |
27
|
|
|
*/ |
28
|
|
|
public const CODE_SUCCESS = 0; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return string |
32
|
|
|
*/ |
33
|
|
|
public static function getCommandName(): string |
34
|
|
|
{ |
35
|
|
|
return 'fixtures'; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
|
|
public function getDescription(): string |
42
|
|
|
{ |
43
|
|
|
return 'Builds fixtures and serializes them into files'; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Sets Run arguments |
48
|
|
|
* |
49
|
|
|
* @return void |
50
|
|
|
*/ |
51
|
|
|
protected function configure(): void |
52
|
|
|
{ |
53
|
|
|
$this->setDefinition([ |
54
|
|
|
new InputOption( |
55
|
|
|
'no-colors', |
56
|
|
|
'', |
57
|
|
|
InputOption::VALUE_NONE, |
58
|
|
|
'Force no colors in output (useful to override config file)', |
59
|
|
|
), |
60
|
|
|
new InputOption('silent', '', InputOption::VALUE_NONE, 'Only outputs suite names and final results'), |
61
|
|
|
new InputOption('steps', '', InputOption::VALUE_NONE, 'Show steps in output'), |
62
|
|
|
new InputOption('debug', 'd', InputOption::VALUE_NONE, 'Show debug and scenario output'), |
63
|
|
|
new InputOption('no-exit', '', InputOption::VALUE_NONE, 'Don\'t finish with exit code'), |
64
|
|
|
new InputOption( |
65
|
|
|
'skip', |
66
|
|
|
's', |
67
|
|
|
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, |
68
|
|
|
'Skip selected suites', |
69
|
|
|
), |
70
|
|
|
new InputOption( |
71
|
|
|
'group', |
72
|
|
|
'g', |
73
|
|
|
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, |
74
|
|
|
'Groups of fixtures to be build', |
75
|
|
|
), |
76
|
|
|
new InputOption( |
77
|
|
|
'skip-group', |
78
|
|
|
'x', |
79
|
|
|
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, |
80
|
|
|
'Skip selected groups', |
81
|
|
|
), |
82
|
|
|
new InputOption( |
83
|
|
|
'env', |
84
|
|
|
'', |
85
|
|
|
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, |
86
|
|
|
'Run tests in selected environments.', |
87
|
|
|
), |
88
|
|
|
new InputOption( |
89
|
|
|
'seed', |
90
|
|
|
'', |
91
|
|
|
InputOption::VALUE_REQUIRED, |
92
|
|
|
'Define random seed for shuffle setting', |
93
|
|
|
), |
94
|
|
|
]); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
99
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
100
|
|
|
* |
101
|
|
|
* @throws \Codeception\Exception\TestRuntimeException |
102
|
|
|
* |
103
|
|
|
* @return int |
104
|
|
|
*/ |
105
|
|
|
public function execute(InputInterface $input, OutputInterface $output): int |
106
|
|
|
{ |
107
|
|
|
$this->options = $input->getOptions(); |
|
|
|
|
108
|
|
|
$this->output = $output; |
|
|
|
|
109
|
|
|
|
110
|
|
|
// load config |
111
|
|
|
$config = $this->getGlobalConfig(); |
112
|
|
|
|
113
|
|
|
if (!$this->options['silent']) { |
114
|
|
|
$output->writeln( |
115
|
|
|
Codecept::versionString() . "\nPowered by " . Version::getVersionString(), |
116
|
|
|
); |
117
|
|
|
$output->writeln( |
118
|
|
|
'Running with seed: ' . $this->options['seed'] . "\n", |
119
|
|
|
); |
120
|
|
|
} |
121
|
|
|
if ($this->options['group']) { |
122
|
|
|
$output->writeln(sprintf('[Groups] <info>%s</info> ', implode(', ', $this->options['group']))); |
123
|
|
|
} |
124
|
|
|
if ($this->options['debug']) { |
125
|
|
|
$output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$userOptions = array_intersect_key($this->options, array_flip($this->passedOptionKeys($input))); |
129
|
|
|
$userOptions['verbosity'] = $output->getVerbosity(); |
130
|
|
|
$userOptions['seed'] = (int)$this->options['seed'] ?: mt_rand(); |
131
|
|
|
$userOptions['colors'] = $this->options['no-colors'] || ($input->hasOption('no-ansi') && $input->getOption('no-ansi')) ? false : $config['settings']['colors']; |
132
|
|
|
|
133
|
|
|
if ($this->options['group'] !== []) { |
134
|
|
|
$userOptions['groups'] = $this->options['group']; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
if ($this->options['skip-group'] !== []) { |
138
|
|
|
$userOptions['excludeGroups'] = $this->options['skip-group']; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
$this->codecept = new FixturesRunner($userOptions); |
|
|
|
|
142
|
|
|
|
143
|
|
|
$suites = Configuration::suites(); |
144
|
|
|
$this->executed = $this->runSuites($suites); |
|
|
|
|
145
|
|
|
|
146
|
|
|
if (!empty($config['include'])) { |
147
|
|
|
$current_dir = Configuration::projectDir(); |
148
|
|
|
$suites += $config['include']; |
149
|
|
|
$this->runIncludedSuites($config['include'], $current_dir); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
if ($this->executed === 0) { |
153
|
|
|
throw new TestRuntimeException( |
154
|
|
|
sprintf("Suite '%s' could not be found", implode(', ', $suites)), |
155
|
|
|
); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
$this->codecept->printResult(); |
159
|
|
|
|
160
|
|
|
if (!$input->getOption('no-exit') && !$this->codecept->getResultAggregator()->wasSuccessful()) { |
161
|
|
|
exit(1); |
|
|
|
|
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
return static::CODE_SUCCESS; |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|