Skip to content

Commit a2094bc

Browse files
committed
MQE-1800: Allow generate:tests to continue running even if one test fails generation
1 parent ec8abe6 commit a2094bc

File tree

61 files changed

+1313
-111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1313
-111
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
},
6464
"autoload-dev": {
6565
"psr-4": {
66-
"tests\\unit\\": "dev/tests/unit"
66+
"tests\\": "dev/tests"
6767
}
6868
},
6969
"scripts": {

dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,13 @@ public function mockHandlers($testArray, $suiteArray)
188188
$property->setAccessible(true);
189189
$property->setValue($handler, $testArray);
190190

191-
AspectMock::double(SuiteObjectHandler::class, ['initSuiteData' => ''])->make();
191+
AspectMock::double(
192+
SuiteObjectHandler::class,
193+
[
194+
'initSuiteData' => '',
195+
'parseSuccessful' => true,
196+
]
197+
)->make();
192198
$handler = SuiteObjectHandler::getInstance();
193199
$property = new \ReflectionProperty(SuiteObjectHandler::class, 'suiteObjects');
194200
$property->setAccessible(true);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function testGenerateEmptySuite()
138138
$this->setMockTestAndSuiteParserOutput($mockTestData, $mockData);
139139

140140
// set expected error message
141-
$this->expectExceptionMessage("Suites must not be empty. Suite: \"basicTestSuite\"");
141+
$this->expectExceptionMessage("Suite basicTestSuite is not defined in xml or is invalid");
142142

143143
// parse and generate suite object with mocked data
144144
$mockSuiteGenerator = SuiteGenerator::getInstance();
@@ -180,7 +180,7 @@ public function testInvalidSuiteTestPair()
180180
$manifest = TestManifestFactory::makeManifest('default', $suiteConfig);
181181

182182
// Set up Expected Exception
183-
$this->expectException(TestReferenceException::class);
183+
$this->expectException(\Exception::class);
184184
$this->expectExceptionMessageMatches('(Suite: "Suite2" Tests: "Test1")');
185185

186186
// parse and generate suite object with mocked data and manifest
@@ -204,7 +204,7 @@ public function testNonExistentSuiteTestPair()
204204
$manifest = TestManifestFactory::makeManifest('default', $suiteConfig);
205205

206206
// Set up Expected Exception
207-
$this->expectException(TestReferenceException::class);
207+
$this->expectException(\Exception::class);
208208
$this->expectExceptionMessageMatches('#Suite3 is not defined#');
209209

210210
// parse and generate suite object with mocked data and manifest

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use AspectMock\Test as AspectMock;
1010

1111
use Magento\FunctionalTestingFramework\Filter\FilterList;
12+
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
1213
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
1314
use Magento\FunctionalTestingFramework\Test\Objects\TestHookObject;
1415
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
@@ -41,13 +42,13 @@ public function testEntityException()
4142

4243
$testObject = new TestObject("sampleTest", ["merge123" => $actionObject], [], [], "filename");
4344

45+
AspectMock::double(TestObjectHandler::class, ['initTestData' => '']);
46+
4447
$testGeneratorObject = TestGenerator::getInstance("", ["sampleTest" => $testObject]);
4548

4649
AspectMock::double(TestGenerator::class, ['loadAllTestObjects' => ["sampleTest" => $testObject]]);
4750

48-
$this->expectExceptionMessage("Could not resolve entity reference \"{{someEntity.entity}}\" " .
49-
"in Action with stepKey \"fakeAction\".\n" .
50-
"Exception occurred parsing action at StepKey \"fakeAction\" in Test \"sampleTest\"");
51+
$this->expectExceptionMessage("ERROR: 1 Test failed to generate.");
5152

5253
$testGeneratorObject->createAllTestFiles(null, []);
5354
}

dev/tests/unit/Util/TestLoggingUtil.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function validateMockLogStatmentRegex($type, $regex, $context)
9393
$records = $this->testLogHandler->getRecords();
9494
$record = $records[count($records)-1]; // we assume the latest record is what requires validation
9595
$this->assertEquals(strtoupper($type), $record['level_name']);
96-
$this->assertRegExp($regex, $record['message']);
96+
$this->assertMatchesRegularExpression($regex, $record['message']);
9797
$this->assertEquals($context, $record['context']);
9898
}
9999

dev/tests/util/MftfTestCase.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,28 @@ public function validateSchemaErrorWithTest($fileContents, $objectType ,$expecte
8080
}
8181
}
8282

83+
/**
84+
* Asserts that the given callback throws the given exception
85+
*
86+
* @param string $expectClass
87+
* @param array $expectedMessages
88+
* @param callable $callback
89+
*/
90+
protected function assertExceptionRegex(string $expectClass, array $expectedMessages, callable $callback)
91+
{
92+
try {
93+
$callback();
94+
} catch (\Throwable $exception) {
95+
$this->assertInstanceOf($expectClass, $exception, 'An invalid exception was thrown.');
96+
foreach ($expectedMessages as $expectedMessage) {
97+
$this->assertMatchesRegularExpression($expectedMessage, $exception->getMessage());
98+
}
99+
return;
100+
}
101+
102+
$this->fail('No exception was thrown.');
103+
}
104+
83105
/**
84106
* Clears test handler and object manager to force recollection of test data
85107
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="NotGenerateArgActionGroup">
11+
<arguments>
12+
<argument name="someArgument" defaultValue="ReplacementPerson"/>
13+
</arguments>
14+
<see selector="{{SampleSection.threeParamElement(someArgument.firstname, someArgument.lastname, 'test')}}" userInput="{{someArgument.lastname}}" stepKey="seeLastName" />
15+
</actionGroup>
16+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="NotGenerateCreateDataActionGroup">
11+
<createData entity="NotExtendParentData" stepKey="createData"/>
12+
</actionGroup>
13+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="NotGenerateExtendChildActionGroup" extends="NotGenerateExtendParentActionGroup">
11+
<arguments>
12+
<argument name="otherCount" type="string"/>
13+
</arguments>
14+
<grabMultiple selector="notASelector" stepKey="grabProducts"/>
15+
<comment userInput="New Input After" stepKey="afterGrabProducts" after="grabProducts"/>
16+
<comment userInput="New Input Before" stepKey="beforeGrabProducts" before="grabProducts"/>
17+
<assertCount stepKey="assertSecondCount">
18+
<expectedResult type="int">{{otherCount}}</expectedResult>
19+
<actualResult type="variable">grabProducts</actualResult>
20+
</assertCount>
21+
</actionGroup>
22+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="NotGenerateExtendChildBadReferenceActionGroup" extends="extendBasicActionGroup">
11+
<fillField stepKey="fill" selector="$name" userInput="$$N.N$$"/>
12+
</actionGroup>
13+
</actionGroups>

0 commit comments

Comments
 (0)