From 89648632448a22fbcbf36dd0d2ac062795d4c717 Mon Sep 17 00:00:00 2001 From: Alex Calandra Date: Wed, 10 Oct 2018 10:54:47 -0500 Subject: [PATCH 1/9] MQE-1260: Create RERUN_COUNT field in Jenkins MFTF Parameters section same as MTF parameters section - Adding run:failed command --- .../Console/CommandList.php | 3 + .../Console/RunTestFailedCommand.php | 145 ++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php diff --git a/src/Magento/FunctionalTestingFramework/Console/CommandList.php b/src/Magento/FunctionalTestingFramework/Console/CommandList.php index 362b29296..ba167de86 100644 --- a/src/Magento/FunctionalTestingFramework/Console/CommandList.php +++ b/src/Magento/FunctionalTestingFramework/Console/CommandList.php @@ -8,6 +8,8 @@ namespace Magento\FunctionalTestingFramework\Console; +use Codeception\Extension\RunFailed; + /** * Class CommandList has a list of commands. * @codingStandardsIgnoreFile @@ -35,6 +37,7 @@ public function __construct(array $commands = []) 'generate:tests' => new GenerateTestsCommand(), 'run:test' => new RunTestCommand(), 'run:group' => new RunTestGroupCommand(), + 'run:failed' => new RunTestFailedCommand(), 'setup:env' => new SetupEnvCommand(), 'upgrade:tests' => new UpgradeTestsCommand(), ] + $commands; diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php new file mode 100644 index 000000000..62954567d --- /dev/null +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php @@ -0,0 +1,145 @@ +setName('run:failed') + ->setDescription('Execute a set of tests referenced via group annotations') + ->addOption( + 'skip-generate', + 'k', + InputOption::VALUE_NONE, + "only execute a group of tests without generating from source xml" + )->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) + { + $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( + $force, + MftfApplicationConfig::GENERATION_PHASE, + false, + false + ); + + if (!$skipGeneration) { + $testConfiguration = $this->getFailedTestList(); + $command = $this->getApplication()->find('generate:tests'); + $args = [ + '--tests' => $testConfiguration, + '--force' => $force, + '--remove' => $remove + ]; + + $command->run(new ArrayInput($args), $output); + } + + $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); + } + ); + } + + /** + * Returns a json string of tests that failed on the last run + * + * @return string[] + */ + private function getFailedTestList() + { + $failedTestPath = TESTS_BP . + DIRECTORY_SEPARATOR . + "tests" . + DIRECTORY_SEPARATOR . + "_output" . + DIRECTORY_SEPARATOR . + "failed"; + + $failedTestDetails = ['tests' => [], 'suites' => []]; + + if (realpath($failedTestPath)) { + + $testList = file($failedTestPath,FILE_IGNORE_NEW_LINES); + + foreach ($testList as $test) { + $testInfo = explode(DIRECTORY_SEPARATOR, $test); + $testName = explode(":", $testInfo[count($testInfo) - 1])[1]; + $suiteName = $testInfo[count($testInfo) - 2]; + + if ($suiteName == self::DEFAULT_TEST_GROUP) { + array_push($failedTestDetails['tests'], $testName); + } else { + $failedTestDetails['suites'] = array_merge_recursive( + $failedTestDetails['suites'], + [$suiteName => $testName] + ); + } + } + } + $testConfigurationJson = json_encode($failedTestDetails); + return $testConfigurationJson; + } +} From 8d2e278c61ef800c1e95797eff31180004f5d3d6 Mon Sep 17 00:00:00 2001 From: Alex Calandra Date: Wed, 10 Oct 2018 11:20:54 -0500 Subject: [PATCH 2/9] MQE-1260: Create RERUN_COUNT field in Jenkins MFTF Parameters section same as MTF parameters section - Changing Suite Test Information to an array --- .../FunctionalTestingFramework/Console/RunTestFailedCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php index 62954567d..34831b6e9 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php @@ -134,7 +134,7 @@ private function getFailedTestList() } else { $failedTestDetails['suites'] = array_merge_recursive( $failedTestDetails['suites'], - [$suiteName => $testName] + [$suiteName => [$testName]] ); } } From ae505fb27ded28732bfd0f478898e10428aa034f Mon Sep 17 00:00:00 2001 From: Alex Calandra Date: Thu, 11 Oct 2018 10:55:54 -0500 Subject: [PATCH 3/9] MQE-1260: Create RERUN_COUNT field in Jenkins MFTF Parameters section same as MTF parameters section - Added rerun file generation - Cleaned up test generation --- .../Console/RunTestFailedCommand.php | 105 +++++++++++------- 1 file changed, 64 insertions(+), 41 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php index 34831b6e9..e64db5778 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php @@ -7,21 +7,30 @@ namespace Magento\FunctionalTestingFramework\Console; -use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler; use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig; -use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler; 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 RunTestFailedCommand extends BaseGenerateCommand { + /** + * Default Test group to signify not in suite + */ const DEFAULT_TEST_GROUP = 'default'; + const TESTS_OUTPUT_DIR = TESTS_BP . + DIRECTORY_SEPARATOR . + "tests" . + DIRECTORY_SEPARATOR . + "_output" . + DIRECTORY_SEPARATOR; + + const TESTS_FAILED_FILE = self::TESTS_OUTPUT_DIR . "failed"; + const TESTS_RERUN_FILE = self::TESTS_OUTPUT_DIR . "rerun_tests"; + /** * Configures the current command. * @@ -30,18 +39,7 @@ class RunTestFailedCommand extends BaseGenerateCommand protected function configure() { $this->setName('run:failed') - ->setDescription('Execute a set of tests referenced via group annotations') - ->addOption( - 'skip-generate', - 'k', - InputOption::VALUE_NONE, - "only execute a group of tests without generating from source xml" - )->addOption( - "force", - 'f', - InputOption::VALUE_NONE, - 'force generation of tests regardless of Magento Instance Configuration' - ); + ->setDescription('Execute a set of tests referenced via failed file'); parent::configure(); } @@ -55,41 +53,29 @@ protected function configure() * @throws \Exception * * @SuppressWarnings(PHPMD.UnusedLocalVariable) + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ 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( - $force, + false, MftfApplicationConfig::GENERATION_PHASE, false, false ); - if (!$skipGeneration) { - $testConfiguration = $this->getFailedTestList(); - $command = $this->getApplication()->find('generate:tests'); - $args = [ - '--tests' => $testConfiguration, - '--force' => $force, - '--remove' => $remove - ]; + $testConfiguration = $this->getFailedTestList(); - $command->run(new ArrayInput($args), $output); + if ($testConfiguration === null) { + return null; } + $command = $this->getApplication()->find('generate:tests'); + $args = ['--tests' => $testConfiguration, '--remove' => true]; + + $command->run(new ArrayInput($args), $output); + $codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . ' run functional --verbose --steps'; $process = new Process($codeceptionCommand); @@ -106,7 +92,7 @@ function ($type, $buffer) use ($output) { /** * Returns a json string of tests that failed on the last run * - * @return string[] + * @return string */ private function getFailedTestList() { @@ -121,10 +107,10 @@ private function getFailedTestList() $failedTestDetails = ['tests' => [], 'suites' => []]; if (realpath($failedTestPath)) { - - $testList = file($failedTestPath,FILE_IGNORE_NEW_LINES); + $testList = $this->readFailedTestFile($failedTestPath); foreach ($testList as $test) { + $this->writeFailedTestToFile($test); $testInfo = explode(DIRECTORY_SEPARATOR, $test); $testName = explode(":", $testInfo[count($testInfo) - 1])[1]; $suiteName = $testInfo[count($testInfo) - 2]; @@ -139,7 +125,44 @@ private function getFailedTestList() } } } + if (empty($failedTestDetails['tests']) & empty($failedTestDetails['suites'])) { + return null; + } + if (empty($failedTestDetails['tests'])) { + $failedTestDetails['tests'] = null; + } + if (empty($failedTestDetails['suites'])) { + $failedTestDetails['suites'] = null; + } $testConfigurationJson = json_encode($failedTestDetails); return $testConfigurationJson; } + + /** + * Returns an array of tests read from the failed test file in _output + * + * @param string $filePath + * @return array|boolean + */ + private function readFailedTestFile($filePath) + { + return file($filePath, FILE_IGNORE_NEW_LINES); + } + + /** + * Writes the test name to a file if it does not already exist + * + * @param string $test + * @return void + */ + private function writeFailedTestToFile($test) + { + if (realpath(self::TESTS_RERUN_FILE)) { + if (strpos(file_get_contents(self::TESTS_RERUN_FILE), $test) == false) { + file_put_contents(self::TESTS_RERUN_FILE, $test . "\n", FILE_APPEND); + } + } else { + file_put_contents(self::TESTS_RERUN_FILE, $test . "\n"); + } + } } From af01a97f62c7856a0676ce5860c6877671e2b703 Mon Sep 17 00:00:00 2001 From: Alex Calandra Date: Thu, 11 Oct 2018 12:49:40 -0500 Subject: [PATCH 4/9] MQE-1260: Create RERUN_COUNT field in Jenkins MFTF Parameters section same as MTF parameters section - Removing unused use statement --- src/Magento/FunctionalTestingFramework/Console/CommandList.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/CommandList.php b/src/Magento/FunctionalTestingFramework/Console/CommandList.php index ba167de86..ce971146e 100644 --- a/src/Magento/FunctionalTestingFramework/Console/CommandList.php +++ b/src/Magento/FunctionalTestingFramework/Console/CommandList.php @@ -8,8 +8,6 @@ namespace Magento\FunctionalTestingFramework\Console; -use Codeception\Extension\RunFailed; - /** * Class CommandList has a list of commands. * @codingStandardsIgnoreFile From d24d74cf64863e77d5a9a0638bc33d0d5e2e5018 Mon Sep 17 00:00:00 2001 From: Alex Calandra Date: Fri, 12 Oct 2018 15:14:36 -0500 Subject: [PATCH 5/9] MQE-1260: Create RERUN_COUNT field in Jenkins MFTF Parameters section same as MTF parameters section - Restructured Codeception command to grab suite names properly --- .../Console/RunTestFailedCommand.php | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php index e64db5778..03bd4e52f 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php @@ -30,6 +30,11 @@ class RunTestFailedCommand extends BaseGenerateCommand const TESTS_FAILED_FILE = self::TESTS_OUTPUT_DIR . "failed"; const TESTS_RERUN_FILE = self::TESTS_OUTPUT_DIR . "rerun_tests"; + const TESTS_MANIFEST_FILE= TESTS_MODULE_PATH . + DIRECTORY_SEPARATOR . + "_generated" . + DIRECTORY_SEPARATOR . + "testManifest.txt"; /** * Configures the current command. @@ -76,17 +81,23 @@ protected function execute(InputInterface $input, OutputInterface $output) $command->run(new ArrayInput($args), $output); - $codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . ' run functional --verbose --steps'; + $testManifestList = $this->readTestManifestFile(); - $process = new Process($codeceptionCommand); - $process->setWorkingDirectory(TESTS_BP); - $process->setIdleTimeout(600); - $process->setTimeout(0); - $process->run( - function ($type, $buffer) use ($output) { - $output->write($buffer); - } - ); + foreach ($testManifestList as $testCommand) + { + $codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . ' run functional '; + $codeceptionCommand .= $testCommand; + + $process = new Process($codeceptionCommand); + $process->setWorkingDirectory(TESTS_BP); + $process->setIdleTimeout(600); + $process->setTimeout(0); + $process->run( + function ($type, $buffer) use ($output) { + $output->write($buffer); + } + ); + } } /** @@ -138,6 +149,17 @@ private function getFailedTestList() return $testConfigurationJson; } + /** + * Returns an array of tests read from the failed test file in _output + * + * @param string $filePath + * @return array|boolean + */ + private function readTestManifestFile() + { + return file(self::TESTS_MANIFEST_FILE, FILE_IGNORE_NEW_LINES); + } + /** * Returns an array of tests read from the failed test file in _output * From ff1a22eb138279d0fbe280edb2299c4a9afd8d04 Mon Sep 17 00:00:00 2001 From: Alex Calandra Date: Mon, 15 Oct 2018 13:23:19 -0500 Subject: [PATCH 6/9] MQE-1260: Create RERUN_COUNT field in Jenkins MFTF Parameters section same as MTF parameters section - Updated to prevent write correct tests to file after a rerun with multiple failures --- .../Console/RunTestFailedCommand.php | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php index 03bd4e52f..9fe88a767 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php @@ -36,6 +36,11 @@ class RunTestFailedCommand extends BaseGenerateCommand DIRECTORY_SEPARATOR . "testManifest.txt"; + /** + * @var array + */ + private $failedList = []; + /** * Configures the current command. * @@ -83,8 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $testManifestList = $this->readTestManifestFile(); - foreach ($testManifestList as $testCommand) - { + foreach ($testManifestList as $testCommand) { $codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . ' run functional '; $codeceptionCommand .= $testCommand; @@ -97,6 +101,13 @@ function ($type, $buffer) use ($output) { $output->write($buffer); } ); + $this->failedList = array_merge( + $this->failedList, + $this->readFailedTestFile(self::TESTS_FAILED_FILE) + ); + } + foreach ($this->failedList as $test) { + $this->writeFailedTestToFile($test, self::TESTS_FAILED_FILE); } } @@ -107,21 +118,13 @@ function ($type, $buffer) use ($output) { */ private function getFailedTestList() { - $failedTestPath = TESTS_BP . - DIRECTORY_SEPARATOR . - "tests" . - DIRECTORY_SEPARATOR . - "_output" . - DIRECTORY_SEPARATOR . - "failed"; - $failedTestDetails = ['tests' => [], 'suites' => []]; - if (realpath($failedTestPath)) { - $testList = $this->readFailedTestFile($failedTestPath); + if (realpath(self::TESTS_FAILED_FILE)) { + $testList = $this->readFailedTestFile(self::TESTS_FAILED_FILE); foreach ($testList as $test) { - $this->writeFailedTestToFile($test); + $this->writeFailedTestToFile($test, self::TESTS_RERUN_FILE); $testInfo = explode(DIRECTORY_SEPARATOR, $test); $testName = explode(":", $testInfo[count($testInfo) - 1])[1]; $suiteName = $testInfo[count($testInfo) - 2]; @@ -150,9 +153,8 @@ private function getFailedTestList() } /** - * Returns an array of tests read from the failed test file in _output + * Returns an array of run commands read from the manifest file created post generation * - * @param string $filePath * @return array|boolean */ private function readTestManifestFile() @@ -177,14 +179,14 @@ private function readFailedTestFile($filePath) * @param string $test * @return void */ - private function writeFailedTestToFile($test) + private function writeFailedTestToFile($test, $filePath) { - if (realpath(self::TESTS_RERUN_FILE)) { - if (strpos(file_get_contents(self::TESTS_RERUN_FILE), $test) == false) { - file_put_contents(self::TESTS_RERUN_FILE, $test . "\n", FILE_APPEND); + if (realpath($filePath)) { + if (strpos(file_get_contents($filePath), $test) === false) { + file_put_contents($filePath, "\n" . $test, FILE_APPEND); } } else { - file_put_contents(self::TESTS_RERUN_FILE, $test . "\n"); + file_put_contents($filePath, $test . "\n"); } } } From f01995cc331a0e9a49862be4981a49559a30d13f Mon Sep 17 00:00:00 2001 From: Alex Calandra Date: Mon, 15 Oct 2018 14:26:12 -0500 Subject: [PATCH 7/9] MQE-1260: Create RERUN_COUNT field in Jenkins MFTF Parameters section same as MTF parameters section - Prevented after from failing in the case of a passed test on rerun --- .../Console/RunTestFailedCommand.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php index 9fe88a767..eb4bbc6db 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php @@ -101,10 +101,12 @@ function ($type, $buffer) use ($output) { $output->write($buffer); } ); - $this->failedList = array_merge( - $this->failedList, - $this->readFailedTestFile(self::TESTS_FAILED_FILE) - ); + if (realpath(self::TESTS_FAILED_FILE)) { + $this->failedList = array_merge( + $this->failedList, + $this->readFailedTestFile(self::TESTS_FAILED_FILE) + ); + } } foreach ($this->failedList as $test) { $this->writeFailedTestToFile($test, self::TESTS_FAILED_FILE); From 82ed2ba5e25838706f4d34b734973a452da7fce7 Mon Sep 17 00:00:00 2001 From: Alex Calandra Date: Tue, 16 Oct 2018 09:46:24 -0500 Subject: [PATCH 8/9] MQE-1260: Create RERUN_COUNT field in Jenkins MFTF Parameters section same as MTF parameters section - Used shorter method for preventing test failure --- .../FunctionalTestingFramework/Console/RunTestFailedCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php index eb4bbc6db..05830187a 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php @@ -101,7 +101,7 @@ function ($type, $buffer) use ($output) { $output->write($buffer); } ); - if (realpath(self::TESTS_FAILED_FILE)) { + if (file_exists(self::TESTS_FAILED_FILE)) { $this->failedList = array_merge( $this->failedList, $this->readFailedTestFile(self::TESTS_FAILED_FILE) From 7543050b406a6af8378a3788f87963d69d67a479 Mon Sep 17 00:00:00 2001 From: Alex Calandra Date: Tue, 16 Oct 2018 16:58:09 -0500 Subject: [PATCH 9/9] MQE-1260: Create RERUN_COUNT field in Jenkins MFTF Parameters section same as MTF parameters section - Protecting on missing testname and filepath --- .../Console/RunTestFailedCommand.php | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php index 05830187a..63fa4261e 100644 --- a/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php @@ -126,18 +126,20 @@ private function getFailedTestList() $testList = $this->readFailedTestFile(self::TESTS_FAILED_FILE); foreach ($testList as $test) { - $this->writeFailedTestToFile($test, self::TESTS_RERUN_FILE); - $testInfo = explode(DIRECTORY_SEPARATOR, $test); - $testName = explode(":", $testInfo[count($testInfo) - 1])[1]; - $suiteName = $testInfo[count($testInfo) - 2]; - - if ($suiteName == self::DEFAULT_TEST_GROUP) { - array_push($failedTestDetails['tests'], $testName); - } else { - $failedTestDetails['suites'] = array_merge_recursive( - $failedTestDetails['suites'], - [$suiteName => [$testName]] - ); + if (!empty($test)) { + $this->writeFailedTestToFile($test, self::TESTS_RERUN_FILE); + $testInfo = explode(DIRECTORY_SEPARATOR, $test); + $testName = explode(":", $testInfo[count($testInfo) - 1])[1]; + $suiteName = $testInfo[count($testInfo) - 2]; + + if ($suiteName == self::DEFAULT_TEST_GROUP) { + array_push($failedTestDetails['tests'], $testName); + } else { + $failedTestDetails['suites'] = array_merge_recursive( + $failedTestDetails['suites'], + [$suiteName => [$testName]] + ); + } } } } @@ -183,7 +185,7 @@ private function readFailedTestFile($filePath) */ private function writeFailedTestToFile($test, $filePath) { - if (realpath($filePath)) { + if (file_exists($filePath)) { if (strpos(file_get_contents($filePath), $test) === false) { file_put_contents($filePath, "\n" . $test, FILE_APPEND); }