Skip to content

Commit 1e8fbd3

Browse files
committed
MQE-893: Add flag to robo generate: tests which accepts a specific set of tests to execute
- add validation around custom test configuration
1 parent dd7ff14 commit 1e8fbd3

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/Magento/FunctionalTestingFramework/Suite/SuiteGenerator.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\FunctionalTestingFramework\Suite;
88

9+
use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException;
910
use Magento\FunctionalTestingFramework\Suite\Generators\GroupClassGenerator;
1011
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
1112
use Magento\FunctionalTestingFramework\Suite\Objects\SuiteObject;
@@ -156,6 +157,7 @@ private function generateSuiteFromTest($suiteName, $tests = [], $originalSuiteNa
156157

157158
$relevantTests = [];
158159
if (!empty($tests)) {
160+
$this->validateTestsReferencedInSuite($suiteName, $tests, $originalSuiteName);
159161
foreach ($tests as $testName) {
160162
$relevantTests[$testName] = TestObjectHandler::getInstance()->getObject($testName);
161163
}
@@ -170,6 +172,34 @@ private function generateSuiteFromTest($suiteName, $tests = [], $originalSuiteNa
170172
print "Suite ${suiteName} generated to ${relativePath}.\n";
171173
}
172174

175+
/**
176+
* Function which validates tests passed in as custom configuration against the configuration defined by the user to
177+
* prevent possible invalid test configurations from executing.
178+
*
179+
* @param string $suiteName
180+
* @param array $testsReferenced
181+
* @param string $originalSuiteName
182+
* @return void
183+
* @throws TestReferenceException
184+
*/
185+
private function validateTestsReferencedInSuite($suiteName, $testsReferenced, $originalSuiteName)
186+
{
187+
$suiteRef = $originalSuiteName ?? $suiteName;
188+
$possibleTestRef = SuiteObjectHandler::getInstance()->getObject($suiteRef)->getTests();
189+
$invalidTestRef = null;
190+
$errorMsg = "Cannot reference tests not declared as part of {$suiteRef}:\n ";
191+
192+
array_walk($testsReferenced, function ($value) use (&$invalidTestRef, $possibleTestRef, &$errorMsg) {
193+
if (!array_key_exists($value, $possibleTestRef)) {
194+
$invalidTestRef.= "\t{$value}\n";
195+
}
196+
});
197+
198+
if ($invalidTestRef != null) {
199+
throw new TestReferenceException($errorMsg . $invalidTestRef);
200+
}
201+
}
202+
173203
/**
174204
* Function for generating split groups of tests (following a parallel execution). Takes a paralle suite config
175205
* and generates applicable suites.

src/Magento/FunctionalTestingFramework/Util/Manifest/DefaultTestManifest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public function __construct($suiteConfiguration, $testPath)
4545
$this->manifestPath = dirname($testPath) . DIRECTORY_SEPARATOR . 'testManifest.txt';
4646
$this->cleanManifest($this->manifestPath);
4747
parent::__construct($testPath, self::DEFAULT_CONFIG, $suiteConfiguration);
48-
// $fileResource = fopen($this->manifestPath, 'a');
49-
// fclose($fileResource);
5048
}
5149

5250
/**

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,17 @@ private function assembleAllTestPhp($testManifest, array $testsToIgnore)
217217
{
218218
/** @var TestObject[] $testObjects */
219219
$testObjects = $this->loadAllTestObjects();
220+
221+
// We need to check the tests passed in to insure that we can generate them in the current context.
222+
$invalidTestObjects = array_intersect_key($testObjects, $testsToIgnore);
223+
if (!empty($invalidTestObjects)) {
224+
$errorMsg = "Cannot reference the following tests for generation without accompanying suite:\n";
225+
array_walk($invalidTestObjects, function ($value, $key) use (&$errorMsg) {
226+
$errorMsg.= "\t{$key}\n";
227+
});
228+
throw new TestReferenceException($errorMsg);
229+
}
230+
220231
$testObjects = array_diff_key($testObjects, $testsToIgnore);
221232
$cestPhpArray = [];
222233

0 commit comments

Comments
 (0)