Skip to content

Commit 9c1f44e

Browse files
committed
MQE-453:[DevOps] Add optional arg for consolidated test run
- add param for config flag and env to TestManifest Constructor - change generate tests signature for new flags
1 parent d0230bf commit 9c1f44e

File tree

2 files changed

+82
-10
lines changed

2 files changed

+82
-10
lines changed

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

+18-8
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,33 @@ private function createCestFile($cestPhp, $filename)
120120
* Assemble ALL PHP strings using the assembleAllCestPhp function. Loop over and pass each array item
121121
* to the createCestFile function.
122122
*
123+
* @param string $runConfig
124+
* @param string $env
123125
* @return void
124126
*/
125-
public function createAllCestFiles()
127+
public function createAllCestFiles($runConfig = null, $env = null)
126128
{
127129
DirSetupUtil::createGroupDir($this->exportDirectory);
128-
$cestPhpArray = $this->assembleAllCestPhp();
130+
131+
// create our manifest file here
132+
$testManifest = new TestManifest($this->exportDirectory, $runConfig, $env);
133+
$cestPhpArray = $this->assembleAllCestPhp($testManifest);
129134

130135
foreach ($cestPhpArray as $cestPhpFile) {
131136
$this->createCestFile($cestPhpFile[1], $cestPhpFile[0]);
132137
}
138+
139+
if ($testManifest->getManifestConfig() === TestManifest::SINGLE_RUN_CONFIG) {
140+
$testManifest->recordPathToExportDir();
141+
}
133142
}
134143

135144
/**
136145
* Assemble the entire PHP string for a single Test based on a Cest Object.
137146
* Create all of the PHP strings for a Test. Concatenate the strings together.
138147
*
139148
* @param \Magento\FunctionalTestingFramework\Test\Objects\CestObject $cestObject
149+
* @throws TestReferenceException
140150
* @return string
141151
*/
142152
private function assembleCestPhp($cestObject)
@@ -168,24 +178,24 @@ private function assembleCestPhp($cestObject)
168178
/**
169179
* Load ALL Cest objects. Loop over and pass each to the assembleCestPhp function.
170180
*
181+
* @param TestManifest $testManifest
171182
* @return array
172183
*/
173-
private function assembleAllCestPhp()
184+
private function assembleAllCestPhp($testManifest)
174185
{
175186
$cestObjects = $this->loadAllCestObjects();
176187
$cestPhpArray = [];
177188

178-
// create our manifest file here
179-
$testManifest = new TestManifest($this->exportDirectory);
180-
181189
foreach ($cestObjects as $cest) {
182190
$name = $cest->getName();
183191
$name = $string = str_replace(' ', '', $name);
184192
$php = $this->assembleCestPhp($cest);
185193
$cestPhpArray[] = [$name, $php];
186194

187-
//write to manifest here
188-
$testManifest->recordCest($cest->getName(), $cest->getTests());
195+
//write to manifest here if config is not single run
196+
if ($testManifest->getManifestConfig() != TestManifest::SINGLE_RUN_CONFIG) {
197+
$testManifest->recordCest($cest->getName(), $cest->getTests());
198+
}
189199
}
190200

191201
return $cestPhpArray;

src/Magento/FunctionalTestingFramework/Util/TestManifest.php

+64-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,30 @@
1010

1111
class TestManifest
1212
{
13+
const SINGLE_RUN_CONFIG = 'singleRun';
14+
const DEFAULT_BROWSER = 'chrome';
15+
1316
/**
1417
* Test Manifest file path.
1518
*
1619
* @var string
1720
*/
1821
private $filePath;
1922

23+
/**
24+
* Test Manifest environment flag. This is added to each dir or file in order for tests to execute properly.
25+
*
26+
* @var string $environment
27+
*/
28+
private $environment = self::DEFAULT_BROWSER;
29+
30+
/**
31+
* Type of manifest to generate. (Currently describes whether to path to a dir or for each test).
32+
*
33+
* @var string
34+
*/
35+
private $runTypeConfig;
36+
2037
/**
2138
* Relative dir path from functional yml file. For devOps execution flexibility.
2239
*
@@ -28,14 +45,32 @@ class TestManifest
2845
* TestManifest constructor.
2946
*
3047
* @param string $path
48+
* @param string $runConfig
49+
* @param string $env
3150
*/
32-
public function __construct($path)
51+
public function __construct($path, $runConfig, $env)
3352
{
3453
$this->relativeDirPath = substr($path, strlen(dirname(dirname(TESTS_BP))) + 1);
3554
$filePath = $path . DIRECTORY_SEPARATOR . 'testManifest.txt';
3655
$this->filePath = $filePath;
3756
$fileResource = fopen($filePath, 'w');
3857
fclose($fileResource);
58+
59+
$this->runTypeConfig = $runConfig;
60+
61+
if ($env) {
62+
$this->environment = $env;
63+
}
64+
}
65+
66+
/**
67+
* Returns a string indicating the generation config (e.g. singleRun).
68+
*
69+
* @return string
70+
*/
71+
public function getManifestConfig()
72+
{
73+
return $this->runTypeConfig;
3974
}
4075

4176
/**
@@ -51,9 +86,36 @@ public function recordCest($cestName, $tests)
5186

5287
foreach ($tests as $test) {
5388
$line = $this->relativeDirPath . DIRECTORY_SEPARATOR . $cestName . '.php:' . $test->getName();
54-
fwrite($fileResource, $line ."\n");
89+
fwrite($fileResource, $this->appendDefaultBrowser($line) ."\n");
5590
}
5691

5792
fclose($fileResource);
5893
}
94+
95+
/**
96+
* Function which simple prints the export dir as part of the manifest file rather than an itemized list of
97+
* cestFile:testname.
98+
*
99+
* @return void
100+
*/
101+
public function recordPathToExportDir()
102+
{
103+
$fileResource = fopen($this->filePath, 'a');
104+
105+
$line = $this->relativeDirPath . DIRECTORY_SEPARATOR;
106+
fwrite($fileResource, $this->appendDefaultBrowser($line) ."\n");
107+
108+
fclose($fileResource);
109+
}
110+
111+
/**
112+
* Function which appends the --env flag to the test. This is needed to properly execute all tests in codeception.
113+
*
114+
* @param string $line
115+
* @return string
116+
*/
117+
private function appendDefaultBrowser($line)
118+
{
119+
return "${line} --env " . $this->environment;
120+
}
59121
}

0 commit comments

Comments
 (0)