Skip to content

Commit 652b599

Browse files
authored
Merge pull request #215 from magento/MQE-1009
MQE-1009: Generated Suites Are Not Cleaned Up When Regenerating
2 parents 928c5b8 + 33743fa commit 652b599

File tree

5 files changed

+106
-13
lines changed

5 files changed

+106
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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\InputOption;
13+
use Symfony\Component\Console\Output\OutputInterface;
14+
use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil;
15+
use Magento\FunctionalTestingFramework\Util\TestGenerator;
16+
17+
class BaseGenerateCommand extends Command
18+
{
19+
/**
20+
* Configures the base command.
21+
*
22+
* @return void
23+
*/
24+
protected function configure()
25+
{
26+
$this->addOption(
27+
'remove',
28+
'r',
29+
InputOption::VALUE_NONE,
30+
'remove previous generated suites and tests'
31+
);
32+
}
33+
34+
/**
35+
* Remove GENERATED_DIR if exists when running generate:tests.
36+
*
37+
* @param OutputInterface $output
38+
* @param bool $verbose
39+
* @return void
40+
*/
41+
protected function removeGeneratedDirectory(OutputInterface $output, bool $verbose)
42+
{
43+
$generatedDirectory = TESTS_MODULE_PATH . DIRECTORY_SEPARATOR . TestGenerator::GENERATED_DIR;
44+
45+
if (file_exists($generatedDirectory)) {
46+
DirSetupUtil::rmdirRecursive($generatedDirectory);
47+
if ($verbose) {
48+
$output->writeln("removed files and directory $generatedDirectory");
49+
}
50+
}
51+
}
52+
}

src/Magento/FunctionalTestingFramework/Console/GenerateSuiteCommand.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
namespace Magento\FunctionalTestingFramework\Console;
99

1010
use Magento\FunctionalTestingFramework\Suite\SuiteGenerator;
11-
use Symfony\Component\Console\Command\Command;
1211
use Symfony\Component\Console\Input\InputArgument;
1312
use Symfony\Component\Console\Input\InputInterface;
1413
use Symfony\Component\Console\Output\OutputInterface;
1514

16-
class GenerateSuiteCommand extends Command
15+
class GenerateSuiteCommand extends BaseGenerateCommand
1716
{
1817
/**
1918
* Configures the current command.
@@ -29,6 +28,8 @@ protected function configure()
2928
InputArgument::IS_ARRAY | InputArgument::REQUIRED,
3029
'argument which indicates suite names for generation (separated by space)'
3130
);
31+
32+
parent::configure();
3233
}
3334

3435
/**
@@ -41,6 +42,13 @@ protected function configure()
4142
*/
4243
protected function execute(InputInterface $input, OutputInterface $output)
4344
{
45+
$remove = $input->getOption('remove');
46+
47+
// Remove previous GENERATED_DIR if --remove option is used
48+
if ($remove) {
49+
$this->removeGeneratedDirectory($output, $output->isVerbose());
50+
}
51+
4452
$suites = $input->getArgument('suites');
4553

4654
foreach ($suites as $suite) {

src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414
use Magento\FunctionalTestingFramework\Util\Manifest\ParallelTestManifest;
1515
use Magento\FunctionalTestingFramework\Util\Manifest\TestManifestFactory;
1616
use Magento\FunctionalTestingFramework\Util\TestGenerator;
17-
use Symfony\Component\Console\Command\Command;
1817
use Symfony\Component\Console\Input\InputArgument;
1918
use Symfony\Component\Console\Input\InputInterface;
2019
use Symfony\Component\Console\Input\InputOption;
2120
use Symfony\Component\Console\Output\OutputInterface;
2221

23-
class GenerateTestsCommand extends Command
22+
class GenerateTestsCommand extends BaseGenerateCommand
2423
{
2524
/**
2625
* Configures the current command.
@@ -52,7 +51,14 @@ protected function configure()
5251
't',
5352
InputOption::VALUE_REQUIRED,
5453
'A parameter accepting a JSON string used to determine the test configuration'
55-
)->addOption('debug', 'd', InputOption::VALUE_NONE, 'run extra validation when generating tests');
54+
)->addOption(
55+
'debug',
56+
'd',
57+
InputOption::VALUE_NONE,
58+
'run extra validation when generating tests'
59+
);
60+
61+
parent::configure();
5662
}
5763

5864
/**
@@ -73,6 +79,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
7379
$force = $input->getOption('force');
7480
$time = $input->getOption('time') * 60 * 1000; // convert from minutes to milliseconds
7581
$debug = $input->getOption('debug');
82+
$remove = $input->getOption('remove');
83+
7684
$verbose = $output->isVerbose();
7785

7886
if ($json !== null && !json_decode($json)) {
@@ -85,6 +93,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
8593
throw new TestFrameworkException("time option cannot be less than or equal to 0");
8694
}
8795

96+
// Remove previous GENERATED_DIR if --remove option is used
97+
if ($remove) {
98+
$this->removeGeneratedDirectory($output, $verbose || $debug);
99+
}
100+
88101
$testConfiguration = $this->createTestConfiguration($json, $tests, $force, $debug, $verbose);
89102

90103
// create our manifest file here
@@ -153,7 +166,6 @@ private function createTestConfiguration($json, array $tests, bool $force, bool
153166
*
154167
* @param string $json
155168
* @param array $testConfiguration
156-
* @throws TestFrameworkException
157169
* @return array
158170
*/
159171
private function parseTestsConfigJson($json, array $testConfiguration)

src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77

88
namespace Magento\FunctionalTestingFramework\Console;
99

10-
use Symfony\Component\Console\Command\Command;
1110
use Symfony\Component\Console\Input\ArrayInput;
1211
use Symfony\Component\Console\Input\InputArgument;
1312
use Symfony\Component\Console\Input\InputInterface;
1413
use Symfony\Component\Console\Input\InputOption;
1514
use Symfony\Component\Console\Output\OutputInterface;
16-
use Symfony\Component\Debug\Debug;
1715
use Symfony\Component\Process\Process;
16+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1817

19-
class RunTestCommand extends Command
18+
class RunTestCommand extends BaseGenerateCommand
2019
{
2120
/**
2221
* Configures the current command.
@@ -38,6 +37,8 @@ protected function configure()
3837
InputOption::VALUE_NONE,
3938
'force generation of tests regardless of Magento Instance Configuration'
4039
);
40+
41+
parent::configure();
4142
}
4243

4344
/**
@@ -55,6 +56,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
5556
$tests = $input->getArgument('name');
5657
$skipGeneration = $input->getOption('skip-generate');
5758
$force = $input->getOption('force');
59+
$remove = $input->getOption('remove');
60+
61+
if ($skipGeneration and $remove) {
62+
// "skip-generate" and "remove" options cannot be used at the same time
63+
throw new TestFrameworkException(
64+
"\"skip-generate\" and \"remove\" options can not be used at the same time."
65+
);
66+
}
5867

5968
if (!$skipGeneration) {
6069
$command = $this->getApplication()->find('generate:tests');
@@ -63,7 +72,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
6372
'tests' => $tests,
6473
'suites' => null
6574
]),
66-
'--force' => $force
75+
'--force' => $force,
76+
'--remove' => $remove
6777
];
6878
$command->run(new ArrayInput($args), $output);
6979
}

src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
1111
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
1212
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
13-
use Symfony\Component\Console\Command\Command;
1413
use Symfony\Component\Console\Input\ArrayInput;
1514
use Symfony\Component\Console\Input\InputArgument;
1615
use Symfony\Component\Console\Input\InputInterface;
1716
use Symfony\Component\Console\Input\InputOption;
1817
use Symfony\Component\Console\Output\OutputInterface;
1918
use Symfony\Component\Process\Process;
19+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
2020

21-
class RunTestGroupCommand extends Command
21+
class RunTestGroupCommand extends BaseGenerateCommand
2222
{
2323
/**
2424
* Configures the current command.
@@ -44,6 +44,8 @@ protected function configure()
4444
InputArgument::IS_ARRAY | InputArgument::REQUIRED,
4545
'group names to be executed via codeception'
4646
);
47+
48+
parent::configure();
4749
}
4850

4951
/**
@@ -61,6 +63,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
6163
$skipGeneration = $input->getOption('skip-generate');
6264
$force = $input->getOption('force');
6365
$groups = $input->getArgument('groups');
66+
$remove = $input->getOption('remove');
67+
68+
if ($skipGeneration and $remove) {
69+
// "skip-generate" and "remove" options cannot be used at the same time
70+
throw new TestFrameworkException(
71+
"\"skip-generate\" and \"remove\" options can not be used at the same time."
72+
);
73+
}
6474

6575
// Create Mftf Configuration
6676
MftfApplicationConfig::create(
@@ -75,7 +85,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
7585
$command = $this->getApplication()->find('generate:tests');
7686
$args = [
7787
'--tests' => $testConfiguration,
78-
'--force' => $force
88+
'--force' => $force,
89+
'--remove' => $remove
7990
];
8091

8192
$command->run(new ArrayInput($args), $output);

0 commit comments

Comments
 (0)