-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathRunTestCommand.php
94 lines (85 loc) · 3.09 KB
/
RunTestCommand.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
90
91
92
93
94
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types = 1);
namespace Magento\FunctionalTestingFramework\Console;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
class RunTestCommand extends BaseGenerateCommand
{
/**
* Configures the current command.
*
* @return void
*/
protected function configure()
{
$this->setName("run:test")
->setDescription("generation and execution of test(s) defined in xml")
->addArgument(
'name',
InputArgument::REQUIRED | InputArgument::IS_ARRAY,
"name of tests to generate and execute"
)->addOption('skip-generate', 'k', InputOption::VALUE_NONE, "skip generation and execute existing test")
->addOption(
"force",
'f',
InputOption::VALUE_NONE,
'force generation of tests regardless of Magento Instance Configuration'
);
parent::configure();
}
/**
* Executes the current command.
*
* @param InputInterface $input
* @param OutputInterface $output
* @return integer|null|void
* @throws \Exception
*
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$tests = $input->getArgument('name');
$skipGeneration = $input->getOption('skip-generate');
$force = $input->getOption('force');
$remove = $input->getOption('remove');
if ($skipGeneration and $remove) {
// "skip-generate" and "remove" options cannot be used at the same time
throw new TestFrameworkException(
"\"skip-generate\" and \"remove\" options can not be used at the same time."
);
}
if (!$skipGeneration) {
$command = $this->getApplication()->find('generate:tests');
$args = [
'--tests' => json_encode([
'tests' => $tests,
'suites' => null
]),
'--force' => $force,
'--remove' => $remove
];
$command->run(new ArrayInput($args), $output);
}
// we only generate relevant tests here so we can execute "all tests"
$codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . " run functional --verbose --steps";
$process = new Process($codeceptionCommand);
$process->setWorkingDirectory(TESTS_BP);
$process->setIdleTimeout(600);
$process->setTimeout(0);
$process->run(
function ($type, $buffer) use ($output) {
$output->write($buffer);
}
);
}
}