Skip to content

Commit

Permalink
33299: code refactoring after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdan-harniuk committed Jul 23, 2021
1 parent 73416f0 commit 74a0892
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
class SuiteGeneratorTest extends MagentoTestCase
{
/**
* Before test functionality
* Before test functionality.
*
* @return void
*/
protected function setUp(): void
Expand Down Expand Up @@ -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);
Expand All @@ -324,7 +333,6 @@ private function setMockTestAndSuiteParserOutput(array $testData, array $suiteDa
->willReturn('namespace');

$objectManager = ObjectManagerFactory::getObjectManager();

$objectManagerMockInstance = $this->createMock(ObjectManager::class);
$objectManagerMockInstance
->method('create')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
Expand All @@ -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]);
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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.
*
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 74a0892

Please sign in to comment.