|
| 1 | +<?php |
| 2 | +// @codingStandardsIgnoreFile |
| 3 | +/** |
| 4 | + * Copyright © Magento, Inc. All rights reserved. |
| 5 | + * See COPYING.txt for license details. |
| 6 | + */ |
| 7 | +declare(strict_types = 1); |
| 8 | + |
| 9 | +namespace Magento\FunctionalTestingFramework\Console; |
| 10 | + |
| 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; |
| 18 | +use Magento\FunctionalTestingFramework\Util\Env\EnvProcessor; |
| 19 | + |
| 20 | +class BuildProjectCommand extends Command |
| 21 | +{ |
| 22 | + /** |
| 23 | + * Env processor manages .env files. |
| 24 | + * |
| 25 | + * @var \Magento\FunctionalTestingFramework\Util\Env\EnvProcessor |
| 26 | + */ |
| 27 | + private $envProcessor; |
| 28 | + |
| 29 | + /** |
| 30 | + * Configures the current command. |
| 31 | + * |
| 32 | + * @return void |
| 33 | + */ |
| 34 | + protected function configure() |
| 35 | + { |
| 36 | + $this->setName('build:project'); |
| 37 | + $this->setDescription('Generate configuration files for the project. Build the Codeception project.'); |
| 38 | + $this->envProcessor = new EnvProcessor(BP . DIRECTORY_SEPARATOR . '.env'); |
| 39 | + $env = $this->envProcessor->getEnv(); |
| 40 | + foreach ($env as $key => $value) { |
| 41 | + $this->addOption($key, null, InputOption::VALUE_REQUIRED, '', $value); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Executes the current command. |
| 47 | + * |
| 48 | + * @param InputInterface $input |
| 49 | + * @param OutputInterface $output |
| 50 | + * @return void |
| 51 | + * @throws \Symfony\Component\Console\Exception\LogicException |
| 52 | + */ |
| 53 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 54 | + { |
| 55 | + $fileSystem = new Filesystem(); |
| 56 | + $fileSystem->copy( |
| 57 | + BP . DIRECTORY_SEPARATOR . 'codeception.dist.yml', |
| 58 | + BP . DIRECTORY_SEPARATOR . 'codeception.yml' |
| 59 | + ); |
| 60 | + $output->writeln("codeception.yml configuration successfully applied.\n"); |
| 61 | + $fileSystem->copy( |
| 62 | + BP . DIRECTORY_SEPARATOR . 'dev' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . |
| 63 | + 'functional' . DIRECTORY_SEPARATOR . 'MFTF.suite.dist.yml', |
| 64 | + BP . DIRECTORY_SEPARATOR . 'dev' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . |
| 65 | + 'functional' . DIRECTORY_SEPARATOR . 'MFTF.suite.yml' |
| 66 | + ); |
| 67 | + $output->writeln("MFTF.suite.yml configuration successfully applied.\n"); |
| 68 | + |
| 69 | + $setupEnvCommand = new SetupEnvCommand(); |
| 70 | + $commandInput = []; |
| 71 | + $options = $input->getOptions(); |
| 72 | + $env = array_keys($this->envProcessor->getEnv()); |
| 73 | + foreach ($options as $key => $value) { |
| 74 | + if (in_array($key, $env)) { |
| 75 | + $commandInput['--' . $key] = $value; |
| 76 | + } |
| 77 | + } |
| 78 | + $commandInput = new ArrayInput($commandInput); |
| 79 | + $setupEnvCommand->run($commandInput, $output); |
| 80 | + |
| 81 | + $process = new Process('vendor/bin/codecept build'); |
| 82 | + $process->run(); |
| 83 | + if ($process->isSuccessful()) { |
| 84 | + $output->writeln("Codeception build run successfully.\n"); |
| 85 | + } |
| 86 | + |
| 87 | + $output->writeln('<info>The project built successfully.</info>'); |
| 88 | + } |
| 89 | +} |
0 commit comments