Skip to content

Commit c2f07e5

Browse files
authored
Merge branch 'develop' into MQE-876
2 parents 6801317 + fc58bae commit c2f07e5

23 files changed

+1023
-157
lines changed

dev/tests/_bootstrap.php

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
defined('TESTS_BP') || define('TESTS_BP', __DIR__);
4444
defined('TESTS_MODULE_PATH') || define('TESTS_MODULE_PATH', TESTS_BP . $RELATIVE_TESTS_MODULE_PATH);
45+
defined('MAGENTO_BP') || define('MAGENTO_BP', __DIR__);
4546

4647
$utilDir = DIRECTORY_SEPARATOR . 'Util'. DIRECTORY_SEPARATOR . '*.php';
4748

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Tests\unit\Magento\FunctionalTestFramework\Suite\Handlers;
7+
8+
use AspectMock\Test as AspectMock;
9+
use Magento\FunctionalTestingFramework\ObjectManager\ObjectManager;
10+
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
11+
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
12+
use Magento\FunctionalTestingFramework\Suite\Parsers\SuiteDataParser;
13+
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
14+
use Magento\FunctionalTestingFramework\Test\Parsers\TestDataParser;
15+
use PHPUnit\Framework\TestCase;
16+
use tests\unit\Util\SuiteDataArrayBuilder;
17+
use tests\unit\Util\TestDataArrayBuilder;
18+
19+
class SuiteObjectHandlerTest extends TestCase
20+
{
21+
/**
22+
* Tests basic parsing and accesors of suite object and suite object supporting classes
23+
*/
24+
public function testGetSuiteObject()
25+
{
26+
$suiteDataArrayBuilder = new SuiteDataArrayBuilder();
27+
$mockData = $suiteDataArrayBuilder
28+
->withName('basicTestSuite')
29+
->withAfterHook()
30+
->withBeforeHook()
31+
->includeTests(['simpleTest'])
32+
->includeGroups(['group1'])
33+
->excludeTests(['group1Test2'])
34+
->excludeGroups(['group2'])
35+
->build();
36+
37+
$testDataArrayBuilder = new TestDataArrayBuilder();
38+
$mockSimpleTest = $testDataArrayBuilder
39+
->withName('simpleTest')
40+
->withTestActions()
41+
->build();
42+
43+
$mockGroup1Test1 = $testDataArrayBuilder
44+
->withName('group1Test1')
45+
->withAnnotations(['group' => [['value' => 'group1']]])
46+
->withTestActions()
47+
->build();
48+
49+
$mockGroup1Test2 = $testDataArrayBuilder
50+
->withName('group1Test2')
51+
->withAnnotations(['group' => [['value' => 'group1']]])
52+
->withTestActions()
53+
->build();
54+
55+
$mockGroup2Test1 = $testDataArrayBuilder
56+
->withName('group2Test1')
57+
->withAnnotations(['group' => [['value' => 'group2']]])
58+
->withTestActions()
59+
->build();
60+
61+
$mockTestData = ['tests' => array_merge($mockSimpleTest, $mockGroup1Test1, $mockGroup1Test2, $mockGroup2Test1)];
62+
$this->setMockTestAndSuiteParserOutput($mockTestData, $mockData);
63+
64+
// parse and retrieve suite object with mocked data
65+
$basicTestSuiteObj = SuiteObjectHandler::getInstance()->getObject('basicTestSuite');
66+
67+
// assert on created suite object
68+
$this->assertEquals($basicTestSuiteObj->getName(), 'basicTestSuite');
69+
$this->assertCount(2, $basicTestSuiteObj->getTests());
70+
$this->assertNotEmpty($basicTestSuiteObj->getBeforeHook());
71+
$this->assertNotEmpty($basicTestSuiteObj->getAfterHook());
72+
}
73+
74+
/**
75+
* Function used to set mock for parser return and force init method to run between tests.
76+
*
77+
* @param array $testData
78+
* @throws \Exception
79+
*/
80+
private function setMockTestAndSuiteParserOutput($testData, $suiteData)
81+
{
82+
// clear test object handler value to inject parsed content
83+
$property = new \ReflectionProperty(TestObjectHandler::class, 'testObjectHandler');
84+
$property->setAccessible(true);
85+
$property->setValue(null);
86+
87+
// clear suite object handler value to inject parsed content
88+
$property = new \ReflectionProperty(SuiteObjectHandler::class, 'SUITE_OBJECT_HANLDER_INSTANCE');
89+
$property->setAccessible(true);
90+
$property->setValue(null);
91+
92+
$mockDataParser = AspectMock::double(TestDataParser::class, ['readTestData' => $testData])->make();
93+
$mockSuiteDataParser = AspectMock::double(SuiteDataParser::class, ['readSuiteData' => $suiteData])->make();
94+
$instance = AspectMock::double(
95+
ObjectManager::class,
96+
['create' => function ($clazz) use ($mockDataParser, $mockSuiteDataParser) {
97+
if ($clazz == TestDataParser::class) {
98+
return $mockDataParser;
99+
}
100+
101+
if ($clazz == SuiteDataParser::class) {
102+
return $mockSuiteDataParser;
103+
}
104+
}]
105+
)->make();
106+
// bypass the private constructor
107+
AspectMock::double(ObjectManagerFactory::class, ['getObjectManager' => $instance]);
108+
}
109+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Tests\unit\Magento\FunctionalTestFramework\Util\Sorter;
7+
8+
use AspectMock\Test as AspectMock;
9+
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
10+
use Magento\FunctionalTestingFramework\Suite\Objects\SuiteObject;
11+
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
12+
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
13+
use Magento\FunctionalTestingFramework\Util\Sorter\ParallelGroupSorter;
14+
use PHPUnit\Framework\TestCase;
15+
16+
class ParallelGroupSorterTest extends TestCase
17+
{
18+
/**
19+
* Test a basic sort of available tests based on size
20+
*/
21+
public function testBasicTestGroupSort()
22+
{
23+
$sampleTestArray = [
24+
'test1' => 100,
25+
'test2' => 300,
26+
'test3' => 50,
27+
'test4' => 60,
28+
'test5' => 25,
29+
'test6' => 125,
30+
'test7' => 250,
31+
'test8' => 1,
32+
'test9' => 80,
33+
'test10' => 25
34+
];
35+
36+
$expectedResult = [
37+
1 => ['test2'],
38+
2 => ['test7'],
39+
3 => ['test6', 'test9'],
40+
4 => ['test1', 'test4', 'test3'],
41+
5 => ['test5', 'test10', 'test8']
42+
];
43+
44+
$testSorter = new ParallelGroupSorter();
45+
$actualResult = $testSorter->getTestsGroupedBySize([], $sampleTestArray, 200);
46+
47+
$this->assertCount(5, $actualResult);
48+
49+
foreach ($actualResult as $gropuNumber => $actualTests) {
50+
$expectedTests = $expectedResult[$gropuNumber];
51+
$this->assertEquals($expectedTests, array_keys($actualTests));
52+
}
53+
}
54+
55+
/**
56+
* Test a sort of both tests and a suite which is larger than the given line limitation
57+
*/
58+
public function testSortWithSuites()
59+
{
60+
// mock tests for test object handler.
61+
$numberOfCalls = 0;
62+
$mockTest1 = AspectMock::double(TestObject::class, ['getTestActionCount' => function () use (&$numberOfCalls) {
63+
$actionCount = [200, 275];
64+
$result = $actionCount[$numberOfCalls];
65+
$numberOfCalls++;
66+
67+
return $result;
68+
}])->make();
69+
70+
$mockHandler = AspectMock::double(
71+
TestObjectHandler::class,
72+
['getObject' => function () use ($mockTest1) {
73+
return $mockTest1;
74+
}]
75+
)->make();
76+
77+
AspectMock::double(TestObjectHandler::class, ['getInstance' => $mockHandler])->make();
78+
79+
// mock a suite object
80+
$mockSuite = AspectMock::double(SuiteObject::class, [
81+
'getBeforeHook' => null,
82+
'getAfterHook' => null,
83+
'getName' => 'mockSuite1'
84+
])->make();
85+
$mockSuiteHandler = AspectMock::double(SuiteObjectHandler::class, ['getObject' => $mockSuite])->make();
86+
AspectMock::double(SuiteObjectHandler::class, ['getInstance' => $mockSuiteHandler]);
87+
88+
// create test to size array
89+
$sampleTestArray = [
90+
'test1' => 100,
91+
'test2' => 300,
92+
'test3' => 500,
93+
'test4' => 60,
94+
'test5' => 125
95+
];
96+
97+
// create mock suite references
98+
$sampleSuiteArray = [
99+
'mockTest1' => ['mockSuite1'],
100+
'mockTest2' => ['mockSuite1']
101+
];
102+
103+
// perform sort
104+
$testSorter = new ParallelGroupSorter();
105+
$actualResult = $testSorter->getTestsGroupedBySize($sampleSuiteArray, $sampleTestArray, 200);
106+
107+
// verify the resulting groups
108+
$this->assertCount(5, $actualResult);
109+
110+
$expectedResults = [
111+
1 => ['test3'],
112+
2 => ['test2'],
113+
3 => ['mockSuite1_0'],
114+
4 => ['mockSuite1_1'],
115+
5 => ['test5', 'test4', 'test1']
116+
];
117+
118+
foreach ($actualResult as $groupNum => $group) {
119+
$this->assertEquals($expectedResults[$groupNum], array_keys($group));
120+
}
121+
}
122+
}

dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/TestNameValidationUtilTest.php renamed to dev/tests/unit/Magento/FunctionalTestFramework/Util/Validation/NameValidationUtilTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
namespace tests\unit\Magento\FunctionalTestFramework\Test\Util;
88

99
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
10-
use Magento\FunctionalTestingFramework\Test\Util\TestNameValidationUtil;
10+
use Magento\FunctionalTestingFramework\Util\Validation\NameValidationUtil;
1111
use PHPUnit\Framework\TestCase;
1212

13-
class TestNameValidationUtilTest extends TestCase
13+
class NameValidationUtilTest extends TestCase
1414
{
1515
/**
1616
* Validate name with curly braces throws exception
@@ -69,6 +69,6 @@ public function testSpacesInTestName()
6969
private function validateBlacklistedTestName($testName)
7070
{
7171
$this->expectException(XmlException::class);
72-
TestNameValidationUtil::validateName($testName);
72+
NameValidationUtil::validateName($testName, "Test");
7373
}
7474
}

0 commit comments

Comments
 (0)