diff --git a/docs/commands/mftf.md b/docs/commands/mftf.md index ac029779e..58be6501e 100644 --- a/docs/commands/mftf.md +++ b/docs/commands/mftf.md @@ -181,7 +181,7 @@ Complex configuration to generate a few non-suite tests, a single test in a suit The command that encodes this complex configuration: ```bash -vendor/bin/mftf generate:tests --tests "{\r\n\"tests\":[\r\n\"general_test1\",\r\n\"general_test2\",\r\n\"general_test3\"\r\n],\r\n\"suites\":{\r\n\"sample\":[\r\n\"suite_test1\"\r\n],\r\n\"sample2\":null\r\n}\r\n}" +vendor/bin/mftf generate:tests --tests '{"tests":["general_test1","general_test2","general_test3"],"suites":{"sample":["suite_test1"],"sample2":null}}' ``` Note that the strings must be escaped and surrounded in quotes. diff --git a/src/Magento/FunctionalTestingFramework/Config/MftfApplicationConfig.php b/src/Magento/FunctionalTestingFramework/Config/MftfApplicationConfig.php index 6faf322bc..80db27de0 100644 --- a/src/Magento/FunctionalTestingFramework/Config/MftfApplicationConfig.php +++ b/src/Magento/FunctionalTestingFramework/Config/MftfApplicationConfig.php @@ -115,8 +115,13 @@ private function __construct( * @return void * @throws TestFrameworkException */ - public static function create($forceGenerate, $phase, $verboseEnabled, $debugLevel, $allowSkipped) - { + public static function create( + $forceGenerate = false, + $phase = self::EXECUTION_PHASE, + $verboseEnabled = null, + $debugLevel = self::LEVEL_NONE, + $allowSkipped = false + ) { if (self::$MFTF_APPLICATION_CONTEXT == null) { self::$MFTF_APPLICATION_CONTEXT = new MftfApplicationConfig($forceGenerate, $phase, $verboseEnabled, $debugLevel, $allowSkipped); diff --git a/src/Magento/FunctionalTestingFramework/Console/GenerateDocsCommand.php b/src/Magento/FunctionalTestingFramework/Console/GenerateDocsCommand.php index 4ed2b6b29..7def3894f 100644 --- a/src/Magento/FunctionalTestingFramework/Console/GenerateDocsCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/GenerateDocsCommand.php @@ -67,7 +67,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $force, MftfApplicationConfig::GENERATION_PHASE, false, - MftfApplicationConfig::LEVEL_NONE + MftfApplicationConfig::LEVEL_NONE, + true ); $allActionGroups = ActionGroupObjectHandler::getInstance()->getAllObjects(); diff --git a/src/Magento/FunctionalTestingFramework/Console/GenerateSuiteCommand.php b/src/Magento/FunctionalTestingFramework/Console/GenerateSuiteCommand.php index 815133e4d..7dd3b8cb4 100644 --- a/src/Magento/FunctionalTestingFramework/Console/GenerateSuiteCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/GenerateSuiteCommand.php @@ -42,7 +42,20 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $force = $input->getOption('force'); + $debug = $input->getOption('debug') ?? MftfApplicationConfig::LEVEL_DEVELOPER; // for backward compatibility $remove = $input->getOption('remove'); + $verbose = $output->isVerbose(); + $allowSkipped = $input->getOption('allowSkipped'); + + // Set application configuration so we can references the user options in our framework + MftfApplicationConfig::create( + $force, + MftfApplicationConfig::GENERATION_PHASE, + $verbose, + $debug, + $allowSkipped + ); // Remove previous GENERATED_DIR if --remove option is used if ($remove) { diff --git a/src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php b/src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php index c410973c7..64c7c01d5 100644 --- a/src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php @@ -73,6 +73,15 @@ protected function execute(InputInterface $input, OutputInterface $output) $verbose = $output->isVerbose(); $allowSkipped = $input->getOption('allowSkipped'); + // Set application configuration so we can references the user options in our framework + MftfApplicationConfig::create( + $force, + MftfApplicationConfig::GENERATION_PHASE, + $verbose, + $debug, + $allowSkipped + ); + if (!empty($tests)) { $json = $this->getTestAndSuiteConfiguration($tests); } @@ -93,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ($debug !== MftfApplicationConfig::LEVEL_NONE)); } - $testConfiguration = $this->createTestConfiguration($json, $tests, $force, $debug, $verbose, $allowSkipped); + $testConfiguration = $this->createTestConfiguration($json, $tests); // create our manifest file here $testManifest = TestManifestFactory::makeManifest($config, $testConfiguration['suites']); @@ -114,33 +123,16 @@ protected function execute(InputInterface $input, OutputInterface $output) /** * Function which builds up a configuration including test and suites for consumption of Magento generation methods. * - * @param string $json - * @param array $tests - * @param boolean $force - * @param string $debug - * @param boolean $verbose - * @param boolean $allowSkipped + * @param string $json + * @param array $tests * @return array * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException * @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException */ private function createTestConfiguration( $json, - array $tests, - bool $force, - string $debug, - bool $verbose, - bool $allowSkipped + array $tests ) { - // set our application configuration so we can references the user options in our framework - MftfApplicationConfig::create( - $force, - MftfApplicationConfig::GENERATION_PHASE, - $verbose, - $debug, - $allowSkipped - ); - $testConfiguration = []; $testConfiguration['tests'] = $tests; $testConfiguration['suites'] = []; diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php index e1e30589d..b83953dce 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php @@ -32,7 +32,12 @@ protected function configure() '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( + 'skip-generate', + 'k', + InputOption::VALUE_NONE, + "skip generation and execute existing test" + ); parent::configure(); } @@ -55,6 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $remove = $input->getOption('remove'); $debug = $input->getOption('debug') ?? MftfApplicationConfig::LEVEL_DEVELOPER; // for backward compatibility $allowSkipped = $input->getOption('allowSkipped'); + $verbose = $output->isVerbose(); if ($skipGeneration and $remove) { // "skip-generate" and "remove" options cannot be used at the same time @@ -63,6 +69,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int ); } + // Set application configuration so we can references the user options in our framework + MftfApplicationConfig::create( + $force, + MftfApplicationConfig::EXECUTION_PHASE, + $verbose, + $debug, + $allowSkipped + ); + $testConfiguration = $this->getTestAndSuiteConfiguration($tests); if (!$skipGeneration) { @@ -72,7 +87,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int '--force' => $force, '--remove' => $remove, '--debug' => $debug, - '--allowSkipped' => $allowSkipped + '--allowSkipped' => $allowSkipped, + '-v' => $verbose ]; $command->run(new ArrayInput($args), $output); } diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php index ed00322ff..15ba723e6 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php @@ -71,12 +71,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $force = $input->getOption('force'); $debug = $input->getOption('debug') ?? MftfApplicationConfig::LEVEL_DEVELOPER; // for backward compatibility $allowSkipped = $input->getOption('allowSkipped'); + $verbose = $output->isVerbose(); // Create Mftf Configuration MftfApplicationConfig::create( $force, - MftfApplicationConfig::GENERATION_PHASE, - false, + MftfApplicationConfig::EXECUTION_PHASE, + $verbose, $debug, $allowSkipped ); @@ -91,9 +92,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $command = $this->getApplication()->find('generate:tests'); $args = [ '--tests' => $testConfiguration, + '--force' => $force, '--remove' => true, '--debug' => $debug, - '--allowSkipped' => $allowSkipped + '--allowSkipped' => $allowSkipped, + '-v' => $verbose ]; $command->run(new ArrayInput($args), $output); diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php index 81a6b864f..20d290af9 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php @@ -61,6 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $remove = $input->getOption('remove'); $debug = $input->getOption('debug') ?? MftfApplicationConfig::LEVEL_DEVELOPER; // for backward compatibility $allowSkipped = $input->getOption('allowSkipped'); + $verbose = $output->isVerbose(); if ($skipGeneration and $remove) { // "skip-generate" and "remove" options cannot be used at the same time @@ -72,8 +73,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int // Create Mftf Configuration MftfApplicationConfig::create( $force, - MftfApplicationConfig::GENERATION_PHASE, - false, + MftfApplicationConfig::EXECUTION_PHASE, + $verbose, $debug, $allowSkipped ); @@ -86,7 +87,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int '--force' => $force, '--remove' => $remove, '--debug' => $debug, - '--allowSkipped' => $allowSkipped + '--allowSkipped' => $allowSkipped, + '-v' => $verbose ]; $command->run(new ArrayInput($args), $output);