diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Suite/SuiteGeneratorTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Suite/SuiteGeneratorTest.php index 85afe7cde..15d6b4a5f 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/Suite/SuiteGeneratorTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Suite/SuiteGeneratorTest.php @@ -31,7 +31,8 @@ class SuiteGeneratorTest extends MagentoTestCase { /** - * Before test functionality + * Before test functionality. + * * @return void */ protected function setUp(): void @@ -290,19 +291,27 @@ public function testGenerateSplitSuiteFromTest(): void * * @param array $testData * @param array $suiteData + * + * @return void * @throws Exception */ private function setMockTestAndSuiteParserOutput(array $testData, array $suiteData): void { $this->clearMockResolverProperties(); $mockSuiteGeneratorService = $this->createMock(SuiteGeneratorService::class); + $mockVoidReturnCallback = function () {};// phpcs:ignore + $mockSuiteGeneratorService ->method('clearPreviousSessionConfigEntries') - ->willReturn(null); + ->will($this->returnCallback($mockVoidReturnCallback)); $mockSuiteGeneratorService ->method('appendEntriesToConfig') - ->willReturn(null); + ->will($this->returnCallback($mockVoidReturnCallback)); + + $mockSuiteGeneratorService + ->method('generateRelevantGroupTests') + ->will($this->returnCallback($mockVoidReturnCallback)); $suiteGeneratorServiceProperty = new ReflectionProperty(SuiteGeneratorService::class, 'INSTANCE'); $suiteGeneratorServiceProperty->setAccessible(true); @@ -324,7 +333,6 @@ private function setMockTestAndSuiteParserOutput(array $testData, array $suiteDa ->willReturn('namespace'); $objectManager = ObjectManagerFactory::getObjectManager(); - $objectManagerMockInstance = $this->createMock(ObjectManager::class); $objectManagerMockInstance ->method('create') diff --git a/src/Magento/FunctionalTestingFramework/Suite/Service/SuiteGeneratorService.php b/src/Magento/FunctionalTestingFramework/Suite/Service/SuiteGeneratorService.php index 9aed81c5c..58823e195 100644 --- a/src/Magento/FunctionalTestingFramework/Suite/Service/SuiteGeneratorService.php +++ b/src/Magento/FunctionalTestingFramework/Suite/Service/SuiteGeneratorService.php @@ -8,8 +8,10 @@ namespace Magento\FunctionalTestingFramework\Suite\Service; use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException; +use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException; use Magento\FunctionalTestingFramework\Suite\SuiteGenerator; use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter; +use Magento\FunctionalTestingFramework\Util\TestGenerator; use Symfony\Component\Yaml\Yaml; /** @@ -52,7 +54,7 @@ public static function getInstance(): SuiteGeneratorService * @return void * @throws TestFrameworkException */ - public function clearPreviousSessionConfigEntries() + public function clearPreviousSessionConfigEntries(): void { $ymlArray = self::getYamlFileContents(); $newYmlArray = $ymlArray; @@ -65,7 +67,6 @@ public function clearPreviousSessionConfigEntries() unset($newYmlArray[SuiteGenerator::YAML_EXTENSIONS_TAG][SuiteGenerator::YAML_ENABLED_TAG][$key]); } } - // needed for proper yml file generation based on indices $newYmlArray[SuiteGenerator::YAML_EXTENSIONS_TAG][SuiteGenerator::YAML_ENABLED_TAG] = array_values($newYmlArray[SuiteGenerator::YAML_EXTENSIONS_TAG][SuiteGenerator::YAML_ENABLED_TAG]); @@ -74,7 +75,6 @@ public function clearPreviousSessionConfigEntries() if (array_key_exists(SuiteGenerator::YAML_GROUPS_TAG, $newYmlArray)) { unset($newYmlArray[SuiteGenerator::YAML_GROUPS_TAG]); } - $ymlText = SuiteGenerator::YAML_COPYRIGHT_TEXT . Yaml::dump($newYmlArray, 10); file_put_contents(self::getYamlConfigFilePath() . SuiteGenerator::YAML_CODECEPTION_CONFIG_FILENAME, $ymlText); } @@ -91,7 +91,7 @@ public function clearPreviousSessionConfigEntries() * @return void * @throws TestFrameworkException */ - public function appendEntriesToConfig(string $suiteName, string $suitePath, ?string $groupNamespace) + public function appendEntriesToConfig(string $suiteName, string $suitePath, ?string $groupNamespace): void { $relativeSuitePath = substr($suitePath, strlen(TESTS_BP)); $relativeSuitePath = ltrim($relativeSuitePath, DIRECTORY_SEPARATOR); @@ -110,6 +110,23 @@ public function appendEntriesToConfig(string $suiteName, string $suitePath, ?str file_put_contents(self::getYamlConfigFilePath() . SuiteGenerator::YAML_CODECEPTION_CONFIG_FILENAME, $ymlText); } + /** + * Function which takes a string which is the desired output directory (under _generated) and an array of tests + * relevant to the suite to be generated. The function takes this information and creates a new instance of the + * test generator which is then called to create all the test files for the suite. + * + * @param string $path + * @param array $tests + * + * @return void + * @throws TestReferenceException + */ + public function generateRelevantGroupTests(string $path, array $tests): void + { + $testGenerator = TestGenerator::getInstance($path, $tests); + $testGenerator->createAllTestFiles(null, []); + } + /** * Function to return contents of codeception.yml file for config changes. * @@ -120,7 +137,6 @@ private static function getYamlFileContents(): array { $configYmlFile = self::getYamlConfigFilePath() . SuiteGenerator::YAML_CODECEPTION_CONFIG_FILENAME; $defaultConfigYmlFile = self::getYamlConfigFilePath() . SuiteGenerator::YAML_CODECEPTION_DIST_FILENAME; - $ymlContents = null; if (file_exists($configYmlFile)) { $ymlContents = file_get_contents($configYmlFile); @@ -137,7 +153,7 @@ private static function getYamlFileContents(): array * @return string * @throws TestFrameworkException */ - private static function getYamlConfigFilePath() + private static function getYamlConfigFilePath(): string { return FilePathFormatter::format(TESTS_BP); } diff --git a/src/Magento/FunctionalTestingFramework/Suite/SuiteGenerator.php b/src/Magento/FunctionalTestingFramework/Suite/SuiteGenerator.php index 37e370242..ced0ac552 100644 --- a/src/Magento/FunctionalTestingFramework/Suite/SuiteGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Suite/SuiteGenerator.php @@ -346,18 +346,18 @@ private static function clearPreviousSessionConfigEntries() /** * Function which takes a string which is the desired output directory (under _generated) and an array of tests - * relevant to the suite to be generated. The function takes this information and creates a new instance of the test - * generator which is then called to create all the test files for the suite. + * relevant to the suite to be generated. The function takes this information and creates a new instance of the + * test generator which is then called to create all the test files for the suite. * * @param string $path * @param array $tests + * * @return void * @throws TestReferenceException */ private function generateRelevantGroupTests($path, $tests) { - $testGenerator = TestGenerator::getInstance($path, $tests); - $testGenerator->createAllTestFiles(null, []); + SuiteGeneratorService::getInstance()->generateRelevantGroupTests($path, $tests); } /**