6 declare(strict_types = 1);
17 use Symfony\Component\Console\Input\InputArgument;
18 use Symfony\Component\Console\Input\InputInterface;
19 use Symfony\Component\Console\Input\InputOption;
20 use Symfony\Component\Console\Output\OutputInterface;
31 $this->setName(
'generate:tests')
32 ->setDescription(
'This command generates all test files and suites based on xml declarations')
35 InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
36 'name(s) of specific tests to generate' 37 )->addOption(
"config",
'c', InputOption::VALUE_REQUIRED,
'default, singleRun, or parallel',
'default')
41 InputOption::VALUE_NONE,
42 'force generation of tests regardless of Magento Instance Configuration' 46 InputOption::VALUE_REQUIRED,
47 'Used in combination with a parallel configuration, determines desired group size (in minutes)',
52 InputOption::VALUE_REQUIRED,
53 'A parameter accepting a JSON string used to determine the test configuration' 57 InputOption::VALUE_NONE,
58 'run extra validation when generating tests' 74 protected function execute(InputInterface $input, OutputInterface
$output)
76 $tests = $input->getArgument(
'name');
77 $config = $input->getOption(
'config');
78 $json = $input->getOption(
'tests');
79 $force = $input->getOption(
'force');
80 $time = $input->getOption(
'time') * 60 * 1000;
81 $debug = $input->getOption(
'debug');
82 $remove = $input->getOption(
'remove');
84 $verbose =
$output->isVerbose();
86 if ($json !==
null && !json_decode($json)) {
91 if (
$config ===
'parallel' && $time <= 0) {
93 throw new TestFrameworkException(
"time option cannot be less than or equal to 0");
101 $testConfiguration = $this->createTestConfiguration($json, $tests, $force,
$debug, $verbose);
109 $testManifest->createTestGroups($time);
116 $testManifest->generate();
118 $output->writeln(
"Generate Tests Command Run");
133 private function createTestConfiguration($json, array $tests,
bool $force,
bool $debug,
bool $verbose)
143 $testConfiguration = [];
144 $testConfiguration[
'tests'] = $tests;
145 $testConfiguration[
'suites'] = [];
147 $testConfiguration = $this->parseTestsConfigJson($json, $testConfiguration);
150 if (!empty($testConfiguration[
'tests'])) {
153 foreach ($testConfiguration[
'tests'] as $test) {
157 $testConfiguration[
'tests'] = $testObjects;
160 return $testConfiguration;
171 private function parseTestsConfigJson($json, array $testConfiguration)
173 if ($json ===
null) {
174 return $testConfiguration;
177 $jsonTestConfiguration = [];
178 $testConfigArray = json_decode($json,
true);
180 $jsonTestConfiguration[
'tests'] = $testConfigArray[
'tests'] ??
null;
182 $jsonTestConfiguration[
'suites'] = $testConfigArray[
'suites'] ??
null;
183 return $jsonTestConfiguration;
removeGeneratedDirectory(OutputInterface $output, bool $verbose)
static getInstance($dir=null, $tests=[], $debug=false)
static create($forceGenerate, $phase, $verboseEnabled, $debugEnabled)
static makeManifest($runConfig, $suiteConfiguration, $testPath=TestGenerator::DEFAULT_DIR)