Skip to content

Commit 065b813

Browse files
authored
Merge pull request #2 from magento-commerce/imported-magento-magento2-functional-testing-framework-797
[Imported] MQE-1800: Allow generate:tests to continue running even if one test f…
2 parents 7b6ec51 + 8b56bfe commit 065b813

File tree

89 files changed

+2603
-267
lines changed

Some content is hidden

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

89 files changed

+2603
-267
lines changed

bin/functional

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ echo "==============================="
77
echo " EXECUTE Functional Tests "
88
echo "==============================="
99
bin/mftf build:project
10+
bin/mftf run:test DeprecatedDevDocsTest -f
1011
bin/mftf run:test DevDocsTest -f
1112
bin/mftf run:test FormatCurrencyTest -f

composer.json

+1-1
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": {

composer.lock

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+36-13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
1717
use Magento\FunctionalTestingFramework\Test\Util\TestObjectExtractor;
1818
use Magento\FunctionalTestingFramework\Test\Parsers\TestDataParser;
19+
use Magento\FunctionalTestingFramework\Util\GenerationErrorHandler;
1920
use Magento\FunctionalTestingFramework\Util\Manifest\DefaultTestManifest;
2021
use tests\unit\Util\MagentoTestCase;
2122
use Magento\FunctionalTestingFramework\Util\Manifest\TestManifestFactory;
@@ -50,7 +51,6 @@ public function setUp(): void
5051

5152
/**
5253
* Tests generating a single suite given a set of parsed test data
53-
* @throws \Exception
5454
*/
5555
public function testGenerateSuite()
5656
{
@@ -86,7 +86,6 @@ public function testGenerateSuite()
8686

8787
/**
8888
* Tests generating all suites given a set of parsed test data
89-
* @throws \Exception
9089
*/
9190
public function testGenerateAllSuites()
9291
{
@@ -123,28 +122,36 @@ public function testGenerateAllSuites()
123122

124123
/**
125124
* Tests attempting to generate a suite with no included/excluded tests and no hooks
126-
* @throws \Exception
127125
*/
128126
public function testGenerateEmptySuite()
129127
{
128+
$testDataArrayBuilder = new TestDataArrayBuilder();
129+
$mockTestData = $testDataArrayBuilder
130+
->withName('test')
131+
->withAnnotations()
132+
->withTestActions()
133+
->build();
134+
130135
$suiteDataArrayBuilder = new SuiteDataArrayBuilder();
131136
$mockData = $suiteDataArrayBuilder
132137
->withName('basicTestSuite')
133138
->build();
134139
unset($mockData['suites']['basicTestSuite'][TestObjectExtractor::TEST_BEFORE_HOOK]);
135140
unset($mockData['suites']['basicTestSuite'][TestObjectExtractor::TEST_AFTER_HOOK]);
136141

137-
$mockTestData = null;
138142
$this->setMockTestAndSuiteParserOutput($mockTestData, $mockData);
139143

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

143147
// parse and generate suite object with mocked data
144148
$mockSuiteGenerator = SuiteGenerator::getInstance();
145149
$mockSuiteGenerator->generateSuite("basicTestSuite");
146150
}
147151

152+
/**
153+
* Tests generating all suites with a suite containing invalid test reference
154+
*/
148155
public function testInvalidSuiteTestPair()
149156
{
150157
// Mock Suite1 => Test1 and Suite2 => Test2
@@ -179,15 +186,20 @@ public function testInvalidSuiteTestPair()
179186
$suiteConfig = ['Suite2' => ['Test1']];
180187
$manifest = TestManifestFactory::makeManifest('default', $suiteConfig);
181188

182-
// Set up Expected Exception
183-
$this->expectException(TestReferenceException::class);
184-
$this->expectExceptionMessageMatches('(Suite: "Suite2" Tests: "Test1")');
185-
186189
// parse and generate suite object with mocked data and manifest
187190
$mockSuiteGenerator = SuiteGenerator::getInstance();
188191
$mockSuiteGenerator->generateAllSuites($manifest);
192+
193+
// assert that no exception for generateAllSuites and suite generation error is stored in GenerationErrorHandler
194+
$errMessage = 'Cannot reference tests which are not declared as part of suite (Suite: "Suite2" Tests: "Test1")';
195+
TestLoggingUtil::getInstance()->validateMockLogStatement('error', $errMessage, []);
196+
$suiteErrors = GenerationErrorHandler::getInstance()->getErrorsByType('suite');
197+
$this->assertArrayHasKey('Suite2', $suiteErrors);
189198
}
190199

200+
/**
201+
* Tests generating all suites with a non-existing suite
202+
*/
191203
public function testNonExistentSuiteTestPair()
192204
{
193205
$testDataArrayBuilder = new TestDataArrayBuilder();
@@ -203,19 +215,22 @@ public function testNonExistentSuiteTestPair()
203215
$suiteConfig = ['Suite3' => ['Test1']];
204216
$manifest = TestManifestFactory::makeManifest('default', $suiteConfig);
205217

206-
// Set up Expected Exception
207-
$this->expectException(TestReferenceException::class);
208-
$this->expectExceptionMessageMatches('#Suite3 is not defined#');
209-
210218
// parse and generate suite object with mocked data and manifest
211219
$mockSuiteGenerator = SuiteGenerator::getInstance();
212220
$mockSuiteGenerator->generateAllSuites($manifest);
221+
222+
// assert that no exception for generateAllSuites and suite generation error is stored in GenerationErrorHandler
223+
$errMessage = 'Suite Suite3 is not defined in xml or is invalid.';
224+
TestLoggingUtil::getInstance()->validateMockLogStatement('error', $errMessage, []);
225+
$suiteErrors = GenerationErrorHandler::getInstance()->getErrorsByType('suite');
226+
$this->assertArrayHasKey('Suite3', $suiteErrors);
213227
}
214228

215229
/**
216230
* Function used to set mock for parser return and force init method to run between tests.
217231
*
218232
* @param array $testData
233+
* @param array $suiteData
219234
* @throws \Exception
220235
*/
221236
private function setMockTestAndSuiteParserOutput($testData, $suiteData)
@@ -271,6 +286,14 @@ private function setMockTestAndSuiteParserOutput($testData, $suiteData)
271286
$property->setValue($instance, $instance);
272287
}
273288

289+
/**
290+
* clean up function runs after each test
291+
*/
292+
public function tearDown(): void
293+
{
294+
GenerationErrorHandler::getInstance()->reset();
295+
}
296+
274297
/**
275298
* clean up function runs after all tests
276299
*/

dev/tests/unit/Magento/FunctionalTestFramework/Test/Handlers/TestObjectHandlerTest.php

+16-5
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@
2020
use tests\unit\Util\ObjectHandlerUtil;
2121
use tests\unit\Util\TestDataArrayBuilder;
2222
use tests\unit\Util\MockModuleResolverBuilder;
23+
use tests\unit\Util\TestLoggingUtil;
24+
use Magento\FunctionalTestingFramework\Util\GenerationErrorHandler;
2325

2426
class TestObjectHandlerTest extends MagentoTestCase
2527
{
28+
public function setUp(): void
29+
{
30+
TestLoggingUtil::getInstance()->setMockLoggingUtil();
31+
}
32+
2633
/**
2734
* Basic test to validate array => test object conversion.
2835
*
@@ -111,8 +118,7 @@ public function testGetTestObject()
111118
*/
112119
public function testGetTestWithFileName()
113120
{
114-
$this->markTestIncomplete();
115-
//TODO
121+
$this->markTestIncomplete('TODO');
116122
}
117123

118124
/**
@@ -254,10 +260,13 @@ public function testGetAllTestObjectsWithInvalidExtends()
254260
ObjectHandlerUtil::mockTestObjectHandlerWitData(array_merge($testOne, $testTwo));
255261

256262
$toh = TestObjectHandler::getInstance();
257-
258-
$this->expectException(\Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException::class);
259-
$this->expectExceptionMessage("Mftf Test can not extend from itself: " . "testOne");
260263
$toh->getAllObjects();
264+
265+
// assert that no exception for getAllObjects and test generation error is stored in GenerationErrorHandler
266+
$errorMessage = '/' . preg_quote("Mftf Test can not extend from itself: " . "testOne") . '/';
267+
TestLoggingUtil::getInstance()->validateMockLogStatmentRegex('error', $errorMessage, []);
268+
$testErrors = GenerationErrorHandler::getInstance()->getErrorsByType('test');
269+
$this->assertArrayHasKey('testOne', $testErrors);
261270
}
262271

263272
/**
@@ -360,6 +369,8 @@ public function testGetTestObjectWhenEnablePause()
360369
*/
361370
public function tearDown(): void
362371
{
372+
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
363373
AspectMock::clean();
374+
parent::tearDownAfterClass();
364375
}
365376
}

dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/AnnotationExtractorTest.php

+15-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Monolog\Logger;
1313
use PHPUnit\Framework\TestCase;
1414
use tests\unit\Util\TestLoggingUtil;
15+
use Magento\FunctionalTestingFramework\Util\GenerationErrorHandler;
1516

1617
class AnnotationExtractorTest extends TestCase
1718
{
@@ -195,14 +196,22 @@ public function testTestCaseIdUniqueness()
195196
$extractor = new AnnotationExtractor();
196197
$extractor->extractAnnotations($firstTestAnnotation, "firstTest");
197198
$extractor->extractAnnotations($secondTestannotation, "secondTest");
199+
$extractor->validateTestCaseIdTitleUniqueness();
198200

199-
//Expect Exception
200-
$this->expectException(\Magento\FunctionalTestingFramework\Exceptions\XmlException::class);
201-
$this->expectExceptionMessage("TestCaseId and Title pairs must be unique:\n\n" .
202-
"TestCaseId: 'MQE-0001' Title: 'TEST TITLE' in Tests 'firstTest', 'secondTest'");
201+
// assert that no exception for validateTestCaseIdTitleUniqueness
202+
// and validation error is stored in GenerationErrorHandler
203+
$errorMessage = '/'
204+
. preg_quote("TestCaseId and Title pairs is not unique in Tests 'firstTest', 'secondTest'")
205+
. '/';
206+
TestLoggingUtil::getInstance()->validateMockLogStatmentRegex('error', $errorMessage, []);
207+
$testErrors = GenerationErrorHandler::getInstance()->getErrorsByType('test');
208+
$this->assertArrayHasKey('firstTest', $testErrors);
209+
$this->assertArrayHasKey('secondTest', $testErrors);
210+
}
203211

204-
//Trigger Exception
205-
$extractor->validateTestCaseIdTitleUniqueness();
212+
public function tearDown(): void
213+
{
214+
GenerationErrorHandler::getInstance()->reset();
206215
}
207216

208217
/**

0 commit comments

Comments
 (0)