Skip to content

Commit 74a0892

Browse files
33299: code refactoring after code review
1 parent 73416f0 commit 74a0892

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Suite/SuiteGeneratorTest.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
class SuiteGeneratorTest extends MagentoTestCase
3232
{
3333
/**
34-
* Before test functionality
34+
* Before test functionality.
35+
*
3536
* @return void
3637
*/
3738
protected function setUp(): void
@@ -290,19 +291,27 @@ public function testGenerateSplitSuiteFromTest(): void
290291
*
291292
* @param array $testData
292293
* @param array $suiteData
294+
*
295+
* @return void
293296
* @throws Exception
294297
*/
295298
private function setMockTestAndSuiteParserOutput(array $testData, array $suiteData): void
296299
{
297300
$this->clearMockResolverProperties();
298301
$mockSuiteGeneratorService = $this->createMock(SuiteGeneratorService::class);
302+
$mockVoidReturnCallback = function () {};// phpcs:ignore
303+
299304
$mockSuiteGeneratorService
300305
->method('clearPreviousSessionConfigEntries')
301-
->willReturn(null);
306+
->will($this->returnCallback($mockVoidReturnCallback));
302307

303308
$mockSuiteGeneratorService
304309
->method('appendEntriesToConfig')
305-
->willReturn(null);
310+
->will($this->returnCallback($mockVoidReturnCallback));
311+
312+
$mockSuiteGeneratorService
313+
->method('generateRelevantGroupTests')
314+
->will($this->returnCallback($mockVoidReturnCallback));
306315

307316
$suiteGeneratorServiceProperty = new ReflectionProperty(SuiteGeneratorService::class, 'INSTANCE');
308317
$suiteGeneratorServiceProperty->setAccessible(true);
@@ -324,7 +333,6 @@ private function setMockTestAndSuiteParserOutput(array $testData, array $suiteDa
324333
->willReturn('namespace');
325334

326335
$objectManager = ObjectManagerFactory::getObjectManager();
327-
328336
$objectManagerMockInstance = $this->createMock(ObjectManager::class);
329337
$objectManagerMockInstance
330338
->method('create')

src/Magento/FunctionalTestingFramework/Suite/Service/SuiteGeneratorService.php

+22-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
namespace Magento\FunctionalTestingFramework\Suite\Service;
99

1010
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
11+
use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException;
1112
use Magento\FunctionalTestingFramework\Suite\SuiteGenerator;
1213
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
14+
use Magento\FunctionalTestingFramework\Util\TestGenerator;
1315
use Symfony\Component\Yaml\Yaml;
1416

1517
/**
@@ -52,7 +54,7 @@ public static function getInstance(): SuiteGeneratorService
5254
* @return void
5355
* @throws TestFrameworkException
5456
*/
55-
public function clearPreviousSessionConfigEntries()
57+
public function clearPreviousSessionConfigEntries(): void
5658
{
5759
$ymlArray = self::getYamlFileContents();
5860
$newYmlArray = $ymlArray;
@@ -65,7 +67,6 @@ public function clearPreviousSessionConfigEntries()
6567
unset($newYmlArray[SuiteGenerator::YAML_EXTENSIONS_TAG][SuiteGenerator::YAML_ENABLED_TAG][$key]);
6668
}
6769
}
68-
6970
// needed for proper yml file generation based on indices
7071
$newYmlArray[SuiteGenerator::YAML_EXTENSIONS_TAG][SuiteGenerator::YAML_ENABLED_TAG] =
7172
array_values($newYmlArray[SuiteGenerator::YAML_EXTENSIONS_TAG][SuiteGenerator::YAML_ENABLED_TAG]);
@@ -74,7 +75,6 @@ public function clearPreviousSessionConfigEntries()
7475
if (array_key_exists(SuiteGenerator::YAML_GROUPS_TAG, $newYmlArray)) {
7576
unset($newYmlArray[SuiteGenerator::YAML_GROUPS_TAG]);
7677
}
77-
7878
$ymlText = SuiteGenerator::YAML_COPYRIGHT_TEXT . Yaml::dump($newYmlArray, 10);
7979
file_put_contents(self::getYamlConfigFilePath() . SuiteGenerator::YAML_CODECEPTION_CONFIG_FILENAME, $ymlText);
8080
}
@@ -91,7 +91,7 @@ public function clearPreviousSessionConfigEntries()
9191
* @return void
9292
* @throws TestFrameworkException
9393
*/
94-
public function appendEntriesToConfig(string $suiteName, string $suitePath, ?string $groupNamespace)
94+
public function appendEntriesToConfig(string $suiteName, string $suitePath, ?string $groupNamespace): void
9595
{
9696
$relativeSuitePath = substr($suitePath, strlen(TESTS_BP));
9797
$relativeSuitePath = ltrim($relativeSuitePath, DIRECTORY_SEPARATOR);
@@ -110,6 +110,23 @@ public function appendEntriesToConfig(string $suiteName, string $suitePath, ?str
110110
file_put_contents(self::getYamlConfigFilePath() . SuiteGenerator::YAML_CODECEPTION_CONFIG_FILENAME, $ymlText);
111111
}
112112

113+
/**
114+
* Function which takes a string which is the desired output directory (under _generated) and an array of tests
115+
* relevant to the suite to be generated. The function takes this information and creates a new instance of the
116+
* test generator which is then called to create all the test files for the suite.
117+
*
118+
* @param string $path
119+
* @param array $tests
120+
*
121+
* @return void
122+
* @throws TestReferenceException
123+
*/
124+
public function generateRelevantGroupTests(string $path, array $tests): void
125+
{
126+
$testGenerator = TestGenerator::getInstance($path, $tests);
127+
$testGenerator->createAllTestFiles(null, []);
128+
}
129+
113130
/**
114131
* Function to return contents of codeception.yml file for config changes.
115132
*
@@ -120,7 +137,6 @@ private static function getYamlFileContents(): array
120137
{
121138
$configYmlFile = self::getYamlConfigFilePath() . SuiteGenerator::YAML_CODECEPTION_CONFIG_FILENAME;
122139
$defaultConfigYmlFile = self::getYamlConfigFilePath() . SuiteGenerator::YAML_CODECEPTION_DIST_FILENAME;
123-
$ymlContents = null;
124140

125141
if (file_exists($configYmlFile)) {
126142
$ymlContents = file_get_contents($configYmlFile);
@@ -137,7 +153,7 @@ private static function getYamlFileContents(): array
137153
* @return string
138154
* @throws TestFrameworkException
139155
*/
140-
private static function getYamlConfigFilePath()
156+
private static function getYamlConfigFilePath(): string
141157
{
142158
return FilePathFormatter::format(TESTS_BP);
143159
}

src/Magento/FunctionalTestingFramework/Suite/SuiteGenerator.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -346,18 +346,18 @@ private static function clearPreviousSessionConfigEntries()
346346

347347
/**
348348
* Function which takes a string which is the desired output directory (under _generated) and an array of tests
349-
* relevant to the suite to be generated. The function takes this information and creates a new instance of the test
350-
* generator which is then called to create all the test files for the suite.
349+
* relevant to the suite to be generated. The function takes this information and creates a new instance of the
350+
* test generator which is then called to create all the test files for the suite.
351351
*
352352
* @param string $path
353353
* @param array $tests
354+
*
354355
* @return void
355356
* @throws TestReferenceException
356357
*/
357358
private function generateRelevantGroupTests($path, $tests)
358359
{
359-
$testGenerator = TestGenerator::getInstance($path, $tests);
360-
$testGenerator->createAllTestFiles(null, []);
360+
SuiteGeneratorService::getInstance()->generateRelevantGroupTests($path, $tests);
361361
}
362362

363363
/**

0 commit comments

Comments
 (0)