Skip to content

Commit a9d1917

Browse files
committed
MQE-1582: Enable Testers To Run Skipped Tests
- Added new unit test for TestGenerator, also changed visibility of function for testing
1 parent 9dfcefb commit a9d1917

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
1313
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
1414
use Magento\FunctionalTestingFramework\Util\TestGenerator;
15+
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
16+
use Magento\FunctionalTestingFramework\ObjectManager;
17+
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
1518

1619
class TestGeneratorTest extends MagentoTestCase
1720
{
@@ -38,4 +41,51 @@ public function testEntityException()
3841

3942
$testGeneratorObject->createAllTestFiles(null, []);
4043
}
44+
45+
/**
46+
* Tests that skipped tests do not have a fully generated body
47+
*
48+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
49+
*/
50+
public function testSkippedNoGeneration()
51+
{
52+
$actionInput = 'fakeInput';
53+
$actionObject = new ActionObject('fakeAction', 'comment', [
54+
'userInput' => $actionInput
55+
]);
56+
57+
$annotations = ['skip' => ['issue']];
58+
$testObject = new TestObject("sampleTest", ["merge123" => $actionObject], $annotations, [], "filename");
59+
60+
$testGeneratorObject = TestGenerator::getInstance("", ["sampleTest" => $testObject]);
61+
$output = $testGeneratorObject->assembleTestPhp($testObject);
62+
63+
$this->assertContains('This test is skipped', $output);
64+
$this->assertNotContains( $actionInput, $output);
65+
}
66+
67+
/**
68+
* Tests that skipped tests have a fully generated body when --allowSkipped is passed in
69+
*
70+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
71+
*/
72+
public function testAllowSkipped()
73+
{
74+
// Mock allowSkipped for TestGenerator
75+
AspectMock::double(MftfApplicationConfig::class, ['allowSkipped' => true]);
76+
77+
$actionInput = 'fakeInput';
78+
$actionObject = new ActionObject('fakeAction', 'comment', [
79+
'userInput' => $actionInput
80+
]);
81+
82+
$annotations = ['skip' => ['issue']];
83+
$testObject = new TestObject("sampleTest", ["merge123" => $actionObject], $annotations, [], "filename");
84+
85+
$testGeneratorObject = TestGenerator::getInstance("", ["sampleTest" => $testObject]);
86+
$output = $testGeneratorObject->assembleTestPhp($testObject);
87+
88+
$this->assertNotContains('This test is skipped', $output);
89+
$this->assertContains($actionInput, $output);
90+
}
4191
}

src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Symfony\Component\Console\Output\OutputInterface;
1414
use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil;
1515
use Magento\FunctionalTestingFramework\Util\TestGenerator;
16+
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
1617

1718
class BaseGenerateCommand extends Command
1819
{

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,14 @@ public function createAllTestFiles($testManifest = null, $testsToIgnore = null)
228228
* @throws TestReferenceException
229229
* @throws \Exception
230230
*/
231-
private function assembleTestPhp($testObject)
231+
public function assembleTestPhp($testObject)
232232
{
233233
$usePhp = $this->generateUseStatementsPhp();
234234
$classAnnotationsPhp = $this->generateAnnotationsPhp($testObject->getAnnotations());
235235

236236
$className = $testObject->getCodeceptionName();
237237
try {
238-
if (!$testObject->isSkipped()) {
238+
if (!$testObject->isSkipped() && !MftfApplicationConfig::getConfig()->allowSkipped()) {
239239
$hookPhp = $this->generateHooksPhp($testObject->getHooks());
240240
} else {
241241
$hookPhp = null;

0 commit comments

Comments
 (0)