Skip to content

MQE-1009: Generated Suites Are Not Cleaned Up When Regenerating #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil;
use Magento\FunctionalTestingFramework\Util\TestGenerator;

class BaseGenerateCommand extends Command
{
/**
* Configures the base command.
*
* @return void
*/
protected function configure()
{
$this->addOption(
'remove',
'r',
InputOption::VALUE_NONE,
'remove previous generated suites and tests'
);
}

/**
* Remove GENERATED_DIR if exists when running generate:tests.
*
* @param OutputInterface $output
* @param bool $verbose
* @return void
*/
protected function removeGeneratedDirectory(OutputInterface $output, bool $verbose)
{
$generatedDirectory = TESTS_MODULE_PATH . DIRECTORY_SEPARATOR . TestGenerator::GENERATED_DIR;

if (file_exists($generatedDirectory)) {
DirSetupUtil::rmdirRecursive($generatedDirectory);
if ($verbose) {
$output->writeln("removed files and directory $generatedDirectory");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
namespace Magento\FunctionalTestingFramework\Console;

use Magento\FunctionalTestingFramework\Suite\SuiteGenerator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class GenerateSuiteCommand extends Command
class GenerateSuiteCommand extends BaseGenerateCommand
{
/**
* Configures the current command.
Expand All @@ -29,6 +28,8 @@ protected function configure()
InputArgument::IS_ARRAY | InputArgument::REQUIRED,
'argument which indicates suite names for generation (separated by space)'
);

parent::configure();
}

/**
Expand All @@ -41,6 +42,13 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$remove = $input->getOption('remove');

// Remove previous GENERATED_DIR if --remove option is used
if ($remove) {
$this->removeGeneratedDirectory($output, $output->isVerbose());
}

$suites = $input->getArgument('suites');

foreach ($suites as $suite) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
use Magento\FunctionalTestingFramework\Util\Manifest\ParallelTestManifest;
use Magento\FunctionalTestingFramework\Util\Manifest\TestManifestFactory;
use Magento\FunctionalTestingFramework\Util\TestGenerator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class GenerateTestsCommand extends Command
class GenerateTestsCommand extends BaseGenerateCommand
{
/**
* Configures the current command.
Expand Down Expand Up @@ -52,7 +51,14 @@ protected function configure()
't',
InputOption::VALUE_REQUIRED,
'A parameter accepting a JSON string used to determine the test configuration'
)->addOption('debug', 'd', InputOption::VALUE_NONE, 'run extra validation when generating tests');
)->addOption(
'debug',
'd',
InputOption::VALUE_NONE,
'run extra validation when generating tests'
);

parent::configure();
}

/**
Expand All @@ -73,6 +79,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$force = $input->getOption('force');
$time = $input->getOption('time') * 60 * 1000; // convert from minutes to milliseconds
$debug = $input->getOption('debug');
$remove = $input->getOption('remove');

$verbose = $output->isVerbose();

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

// Remove previous GENERATED_DIR if --remove option is used
if ($remove) {
$this->removeGeneratedDirectory($output, $verbose || $debug);
}

$testConfiguration = $this->createTestConfiguration($json, $tests, $force, $debug, $verbose);

// create our manifest file here
Expand Down Expand Up @@ -153,7 +166,6 @@ private function createTestConfiguration($json, array $tests, bool $force, bool
*
* @param string $json
* @param array $testConfiguration
* @throws TestFrameworkException
* @return array
*/
private function parseTestsConfigJson($json, array $testConfiguration)
Expand Down
18 changes: 14 additions & 4 deletions src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@

namespace Magento\FunctionalTestingFramework\Console;

use Symfony\Component\Console\Command\Command;
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\Debug\Debug;
use Symfony\Component\Process\Process;
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;

class RunTestCommand extends Command
class RunTestCommand extends BaseGenerateCommand
{
/**
* Configures the current command.
Expand All @@ -38,6 +37,8 @@ protected function configure()
InputOption::VALUE_NONE,
'force generation of tests regardless of Magento Instance Configuration'
);

parent::configure();
}

/**
Expand All @@ -55,6 +56,14 @@ 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');
Expand All @@ -63,7 +72,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
'tests' => $tests,
'suites' => null
]),
'--force' => $force
'--force' => $force,
'--remove' => $remove
];
$command->run(new ArrayInput($args), $output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
use Symfony\Component\Console\Command\Command;
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 RunTestGroupCommand extends Command
class RunTestGroupCommand extends BaseGenerateCommand
{
/**
* Configures the current command.
Expand All @@ -44,6 +44,8 @@ protected function configure()
InputArgument::IS_ARRAY | InputArgument::REQUIRED,
'group names to be executed via codeception'
);

parent::configure();
}

/**
Expand All @@ -61,6 +63,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
$skipGeneration = $input->getOption('skip-generate');
$force = $input->getOption('force');
$groups = $input->getArgument('groups');
$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."
);
}

// Create Mftf Configuration
MftfApplicationConfig::create(
Expand All @@ -75,7 +85,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$command = $this->getApplication()->find('generate:tests');
$args = [
'--tests' => $testConfiguration,
'--force' => $force
'--force' => $force,
'--remove' => $remove
];

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