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