6 declare(strict_types = 1);
11 use Symfony\Component\Console\Command\Command;
12 use Symfony\Component\Console\Input\ArrayInput;
13 use Symfony\Component\Filesystem\Filesystem;
14 use Symfony\Component\Console\Input\InputOption;
15 use Symfony\Component\Console\Input\InputInterface;
16 use Symfony\Component\Console\Output\OutputInterface;
17 use Symfony\Component\Process\Process;
19 use Symfony\Component\Yaml\Yaml;
37 private $envProcessor;
46 $this->setName(
'build:project')
47 ->setDescription(
'Generate configuration files for the project. Build the Codeception project.')
51 InputOption::VALUE_NONE,
52 'upgrade existing MFTF tests according to last major release requiements' 54 $this->envProcessor =
new EnvProcessor(TESTS_BP . DIRECTORY_SEPARATOR .
'.env');
55 $env = $this->envProcessor->getEnv();
56 foreach ($env as $key =>
$value) {
57 $this->addOption($key,
null, InputOption::VALUE_REQUIRED,
'',
$value);
74 $resetOptions =
new ArrayInput([]);
75 $resetCommand->run($resetOptions,
$output);
77 $this->generateConfigFiles(
$output);
82 $env = array_keys($this->envProcessor->getEnv());
84 if (in_array($key, $env)) {
85 $commandInput[
'--' . $key] =
$value;
88 $commandInput =
new ArrayInput($commandInput);
89 $setupEnvCommand->run($commandInput,
$output);
92 $codeceptBuildCommand = realpath(
PROJECT_ROOT .
'/vendor/bin/codecept') .
' build';
93 $process =
new Process($codeceptBuildCommand);
94 $process->setWorkingDirectory(TESTS_BP);
95 $process->setIdleTimeout(600);
96 $process->setTimeout(0);
105 if ($input->getOption(
'upgrade')) {
107 $upgradeOptions =
new ArrayInput([
'path' => TESTS_MODULE_PATH]);
108 $upgradeCommand->run($upgradeOptions,
$output);
118 private function generateConfigFiles(OutputInterface
$output)
120 $fileSystem =
new Filesystem();
122 $relativePath = $fileSystem->makePathRelative(FW_BP, TESTS_BP);
124 if (!$fileSystem->exists(TESTS_BP . DIRECTORY_SEPARATOR .
'codeception.yml')) {
126 $configDistYml = Yaml::parse(
file_get_contents(realpath(FW_BP .
"/etc/config/codeception.dist.yml")));
127 $configDistYml[
'paths'][
'support'] =
$relativePath .
'src/Magento/FunctionalTestingFramework';
128 $configDistYml[
'paths'][
'envs'] =
$relativePath .
'etc/_envs';
129 $configYmlText = Yaml::dump($configDistYml, self::DEFAULT_YAML_INLINE_DEPTH);
132 file_put_contents(TESTS_BP . DIRECTORY_SEPARATOR .
'codeception.yml', $configYmlText);
133 $output->writeln(
"codeception.yml configuration successfully applied.");
137 $output->writeln(
"codeception.yml applied to " . TESTS_BP . DIRECTORY_SEPARATOR .
'codeception.yml');
142 realpath(FW_BP .
'/etc/config/functional.suite.dist.yml'),
143 TESTS_BP . DIRECTORY_SEPARATOR .
'tests' . DIRECTORY_SEPARATOR .
'functional.suite.yml' 145 $output->writeln(
'functional.suite.yml configuration successfully applied.');
148 $output->writeln(
"functional.suite.yml applied to " .
149 TESTS_BP . DIRECTORY_SEPARATOR .
'tests' . DIRECTORY_SEPARATOR .
'functional.suite.yml');
153 FW_BP .
'/etc/config/.credentials.example',
154 self::CREDENTIALS_FILE_PATH
158 if (MAGENTO_BP === FW_BP) {
159 $output->writeln(
'MFTF standalone detected, command.php copy not applied.');
162 realpath(FW_BP .
'/etc/config/command.php'),
163 TESTS_BP . DIRECTORY_SEPARATOR .
"utils" . DIRECTORY_SEPARATOR .
'command.php' 165 $output->writeln(
'command.php copied to ' .
166 TESTS_BP . DIRECTORY_SEPARATOR .
"utils" . DIRECTORY_SEPARATOR .
'command.php');
171 $fileSystem->remove($logPath);
172 $fileSystem->touch($logPath);
173 $fileSystem->chmod($logPath, 0777);
175 $output->writeln(
'.credentials.example successfully applied.');
const CREDENTIALS_FILE_PATH
const DEFAULT_YAML_INLINE_DEPTH
execute(InputInterface $input, OutputInterface $output)