Skip to content

Commit 1e7c063

Browse files
committed
MQE-806: Missing execution of Merge Test in verification module
- refactor tests to use base class - add merge tests back to test module
1 parent 0da60bd commit 1e7c063

17 files changed

+192
-225
lines changed

dev/tests/_bootstrap.php

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
error_reporting(~E_USER_NOTICE);
88
define('PROJECT_ROOT', dirname(dirname(__DIR__)));
99
require_once PROJECT_ROOT . '/vendor/autoload.php';
10+
require_once 'util/MftfTestCase.php';
1011

1112
// Set up AspectMock
1213
$kernel = \AspectMock\Kernel::getInstance();

dev/tests/util/MftfTestCase.php

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace tests\util;
7+
8+
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
9+
use Magento\FunctionalTestingFramework\Util\TestGenerator;
10+
use PHPUnit\Framework\TestCase;
11+
12+
abstract class MftfTestCase extends TestCase
13+
{
14+
const RESOURCES_PATH = __DIR__ . '/../verification/Resources';
15+
16+
/**
17+
* Private function which takes a test name, generates the test and compares with a correspondingly named txt file
18+
* with expected contents.
19+
*
20+
* @param string $testName
21+
*/
22+
public function generateAndCompareTest($testName)
23+
{
24+
$testObject = TestObjectHandler::getInstance()->getObject($testName);
25+
$test = TestGenerator::getInstance(null, [$testObject]);
26+
$test->createAllTestFiles();
27+
28+
$cestFile = $test->getExportDir() .
29+
DIRECTORY_SEPARATOR .
30+
$testObject->getCodeceptionName() .
31+
".php";
32+
33+
$this->assertTrue(file_exists($cestFile));
34+
35+
$this->assertFileEquals(
36+
self::RESOURCES_PATH . DIRECTORY_SEPARATOR . $testObject->getName() . ".txt",
37+
$cestFile
38+
);
39+
}
40+
}

dev/tests/verification/Resources/MergeFunctionalTest.txt renamed to dev/tests/verification/Resources/BasicMergeTest.txt

+4-16
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ use Yandex\Allure\Adapter\Annotation\TestCaseId;
1717

1818
/**
1919
* @Title("A Functional Cest")
20+
* @group functional
2021
* @group mergeTest
2122
* @Features({"Merge Functional Cest"})
2223
* @Stories({"MQE-433"})
2324
*/
24-
class MergeFunctionalTestCest
25+
class BasicMergeTestCest
2526
{
2627
/**
2728
* @param AcceptanceTester $I
@@ -48,8 +49,8 @@ class MergeFunctionalTestCest
4849
*/
4950
public function _failed(AcceptanceTester $I)
5051
{
51-
$I->saveScreenshot();
52-
$this->_after($I);
52+
$I->saveScreenshot();
53+
$this->_after($I);
5354
}
5455

5556
/**
@@ -75,17 +76,4 @@ class MergeFunctionalTestCest
7576
$I->see("#element .Jane");
7677
$I->click("#step10MergedInResult");
7778
}
78-
79-
/**
80-
* @Parameter(name = "AcceptanceTester", value="$I")
81-
* @param AcceptanceTester $I
82-
* @return void
83-
* @throws \Exception
84-
*/
85-
public function MergedReferencesTest(AcceptanceTester $I)
86-
{
87-
$I->fillField("#merge", "merged");
88-
$I->fillField("#newElement", "newField");
89-
}
90-
9179
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
namespace Magento\AcceptanceTest\_generated\Backend;
3+
4+
use Magento\FunctionalTestingFramework\AcceptanceTester;
5+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
6+
use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHandler;
7+
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
8+
use \Codeception\Util\Locator;
9+
use Yandex\Allure\Adapter\Annotation\Features;
10+
use Yandex\Allure\Adapter\Annotation\Stories;
11+
use Yandex\Allure\Adapter\Annotation\Title;
12+
use Yandex\Allure\Adapter\Annotation\Description;
13+
use Yandex\Allure\Adapter\Annotation\Parameter;
14+
use Yandex\Allure\Adapter\Annotation\Severity;
15+
use Yandex\Allure\Adapter\Model\SeverityLevel;
16+
use Yandex\Allure\Adapter\Annotation\TestCaseId;
17+
18+
/**
19+
* @Title("A Functional Cest")
20+
* @group functional
21+
* @Features({"Merge Functional Cest"})
22+
* @Stories({"MQE-433"})
23+
*/
24+
class MergedReferencesTestCest
25+
{
26+
/**
27+
* @param AcceptanceTester $I
28+
* @throws \Exception
29+
*/
30+
public function _before(AcceptanceTester $I)
31+
{
32+
$I->amOnPage("/beforeUrl");
33+
}
34+
35+
/**
36+
* @param AcceptanceTester $I
37+
* @throws \Exception
38+
*/
39+
public function _after(AcceptanceTester $I)
40+
{
41+
$I->amOnPage("/afterUrl");
42+
}
43+
44+
/**
45+
* @param AcceptanceTester $I
46+
* @throws \Exception
47+
*/
48+
public function _failed(AcceptanceTester $I)
49+
{
50+
$I->saveScreenshot();
51+
$this->_after($I);
52+
}
53+
54+
/**
55+
* @Severity(level = SeverityLevel::CRITICAL)
56+
* @Parameter(name = "AcceptanceTester", value="$I")
57+
* @param AcceptanceTester $I
58+
* @return void
59+
* @throws \Exception
60+
*/
61+
public function MergedReferencesTest(AcceptanceTester $I)
62+
{
63+
$I->fillField("#merge", "merged");
64+
$I->fillField("#newElement", "newField");
65+
}
66+
}

dev/tests/verification/Tests/ActionGroupGenerationTest.php

+8-30
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,10 @@
55
*/
66
namespace tests\verification\Tests;
77

8-
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
9-
use Magento\FunctionalTestingFramework\Util\TestGenerator;
10-
use PHPUnit\Framework\TestCase;
8+
use tests\util\MftfTestCase;
119

12-
class ActionGroupGenerationTest extends TestCase
10+
class ActionGroupGenerationTest extends MftfTestCase
1311
{
14-
const RESOURCES_PATH = __DIR__ . '/../Resources';
15-
16-
/**
17-
* Tests flat generation of a hardcoded test file with no external references.
18-
*
19-
* @throws \Exception
20-
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
21-
*/
22-
private function validateGenerateAndContents($testName)
23-
{
24-
$test = TestObjectHandler::getInstance()->getObject($testName);
25-
$testHandler = TestGenerator::getInstance(null, [$test]);
26-
$testHandler->createAllTestFiles();
27-
28-
$this->assertFileEquals(
29-
self::RESOURCES_PATH . DIRECTORY_SEPARATOR . $testName . ".txt",
30-
$testHandler->getExportDir() . DIRECTORY_SEPARATOR . $test->getCodeceptionName() . ".php"
31-
);
32-
}
33-
3412
/**
3513
* Test generation of a test referencing an action group with no arguments
3614
*
@@ -39,7 +17,7 @@ private function validateGenerateAndContents($testName)
3917
*/
4018
public function testActionGroupWithNoArguments()
4119
{
42-
$this->validateGenerateAndContents('ActionGroupWithNoArguments');
20+
$this->generateAndCompareTest('ActionGroupWithNoArguments');
4321
}
4422

4523
/**
@@ -50,7 +28,7 @@ public function testActionGroupWithNoArguments()
5028
*/
5129
public function testActionGroupWithDefaultArgumentAndStringSelectorParam()
5230
{
53-
$this->validateGenerateAndContents('ActionGroupWithDefaultArgumentAndStringSelectorParam');
31+
$this->generateAndCompareTest('ActionGroupWithDefaultArgumentAndStringSelectorParam');
5432
}
5533

5634
/**
@@ -61,7 +39,7 @@ public function testActionGroupWithDefaultArgumentAndStringSelectorParam()
6139
*/
6240
public function testActionGroupWithPassedArgumentAndStringSelectorParam()
6341
{
64-
$this->validateGenerateAndContents('ActionGroupWithPassedArgumentAndStringSelectorParam');
42+
$this->generateAndCompareTest('ActionGroupWithPassedArgumentAndStringSelectorParam');
6543
}
6644

6745
/**
@@ -72,7 +50,7 @@ public function testActionGroupWithPassedArgumentAndStringSelectorParam()
7250
*/
7351
public function testActionGroupWithSingleParameterSelectorFromDefaultArgument()
7452
{
75-
$this->validateGenerateAndContents('ActionGroupWithSingleParameterSelectorFromDefaultArgument');
53+
$this->generateAndCompareTest('ActionGroupWithSingleParameterSelectorFromDefaultArgument');
7654
}
7755

7856
/**
@@ -83,7 +61,7 @@ public function testActionGroupWithSingleParameterSelectorFromDefaultArgument()
8361
*/
8462
public function testActionGroupWithSingleParameterSelectorFromPassedArgument()
8563
{
86-
$this->validateGenerateAndContents('ActionGroupWithSingleParameterSelectorFromPassedArgument');
64+
$this->generateAndCompareTest('ActionGroupWithSingleParameterSelectorFromPassedArgument');
8765
}
8866

8967
/**
@@ -94,6 +72,6 @@ public function testActionGroupWithSingleParameterSelectorFromPassedArgument()
9472
*/
9573
public function testActionGroupWithMultipleParameterSelectorsFromDefaultArgument()
9674
{
97-
$this->validateGenerateAndContents('ActionGroupWithMultipleParameterSelectorsFromDefaultArgument');
75+
$this->generateAndCompareTest('ActionGroupWithMultipleParameterSelectorsFromDefaultArgument');
9876
}
9977
}

dev/tests/verification/Tests/ActionGroupMergeGenerationTest.php

+11-34
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@
66

77
namespace tests\verification\Tests;
88

9-
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
10-
use Magento\FunctionalTestingFramework\Util\TestGenerator;
11-
use PHPUnit\Framework\TestCase;
9+
use tests\util\MftfTestCase;
1210

13-
class ActionGroupMergeGenerationTest extends TestCase
11+
class ActionGroupMergeGenerationTest extends MftfTestCase
1412
{
15-
const RESOURCES_PATH = __DIR__ . '/../Resources';
16-
1713
/**
1814
* Tests flat generation of a hardcoded test file with no external references.
1915
*
@@ -22,7 +18,7 @@ class ActionGroupMergeGenerationTest extends TestCase
2218
*/
2319
public function testBasicActionGroup()
2420
{
25-
$this->runComparisonTest('BasicActionGroupTest');
21+
$this->generateAndCompareTest('BasicActionGroupTest');
2622
}
2723

2824
/**
@@ -33,7 +29,7 @@ public function testBasicActionGroup()
3329
*/
3430
public function testActionGroupWithData()
3531
{
36-
$this->runComparisonTest('ActionGroupWithDataTest');
32+
$this->generateAndCompareTest('ActionGroupWithDataTest');
3733
}
3834

3935
/**
@@ -44,7 +40,7 @@ public function testActionGroupWithData()
4440
*/
4541
public function testActionGroupWithDataOverride()
4642
{
47-
$this->runComparisonTest('ActionGroupWithDataOverrideTest');
43+
$this->generateAndCompareTest('ActionGroupWithDataOverrideTest');
4844
}
4945

5046
/**
@@ -55,7 +51,7 @@ public function testActionGroupWithDataOverride()
5551
*/
5652
public function testActionGroupWithNoDefault()
5753
{
58-
$this->runComparisonTest('ActionGroupWithNoDefaultTest');
54+
$this->generateAndCompareTest('ActionGroupWithNoDefaultTest');
5955
}
6056

6157
/**
@@ -66,7 +62,7 @@ public function testActionGroupWithNoDefault()
6662
*/
6763
public function testActionGroupWithPersistedData()
6864
{
69-
$this->runComparisonTest('ActionGroupWithPersistedData');
65+
$this->generateAndCompareTest('ActionGroupWithPersistedData');
7066
}
7167

7268
/**
@@ -77,7 +73,7 @@ public function testActionGroupWithPersistedData()
7773
*/
7874
public function testActionGroupWithTopLevelPersistedData()
7975
{
80-
$this->runComparisonTest('ActionGroupWithTopLevelPersistedData');
76+
$this->generateAndCompareTest('ActionGroupWithTopLevelPersistedData');
8177
}
8278

8379
/**
@@ -88,7 +84,7 @@ public function testActionGroupWithTopLevelPersistedData()
8884
*/
8985
public function testMultipleActionGroups()
9086
{
91-
$this->runComparisonTest('MultipleActionGroupsTest');
87+
$this->generateAndCompareTest('MultipleActionGroupsTest');
9288
}
9389

9490
/**
@@ -99,7 +95,7 @@ public function testMultipleActionGroups()
9995
*/
10096
public function testMergedActionGroup()
10197
{
102-
$this->runComparisonTest('MergedActionGroupTest');
98+
$this->generateAndCompareTest('MergedActionGroupTest');
10399
}
104100

105101
/**
@@ -110,25 +106,6 @@ public function testMergedActionGroup()
110106
*/
111107
public function testArgumentWithSameNameAsElement()
112108
{
113-
$this->runComparisonTest('ArgumentWithSameNameAsElement');
114-
}
115-
116-
/**
117-
* Generate a Test by name and assert that it equals the corresponding .txt source of truth
118-
*
119-
* @param string $testName
120-
* @throws \Exception
121-
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
122-
*/
123-
private function runComparisonTest($testName)
124-
{
125-
$test = TestObjectHandler::getInstance()->getObject($testName);
126-
$testHandler = TestGenerator::getInstance(null, [$test]);
127-
$testHandler->createAllTestFiles();
128-
129-
$this->assertFileEquals(
130-
self::RESOURCES_PATH . DIRECTORY_SEPARATOR . $test->getName() . ".txt",
131-
$testHandler->getExportDir() . DIRECTORY_SEPARATOR . $test->getCodeceptionName() . ".php"
132-
);
109+
$this->generateAndCompareTest('ArgumentWithSameNameAsElement');
133110
}
134111
}

0 commit comments

Comments
 (0)