Skip to content

Commit f3d4df1

Browse files
committed
Merge branch 'develop' of github.com:magento/magento2-functional-testing-framework
2 parents f627085 + 1416cfb commit f3d4df1

File tree

14 files changed

+815
-151
lines changed

14 files changed

+815
-151
lines changed
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Tests\unit\Magento\FunctionalTestingFramework\Console;
7+
8+
use AspectMock\Test as AspectMock;
9+
use PHPUnit\Framework\TestCase;
10+
use Magento\FunctionalTestingFramework\Console\BaseGenerateCommand;
11+
use Magento\FunctionalTestingFramework\Suite\Objects\SuiteObject;
12+
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
13+
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
14+
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
15+
16+
class BaseGenerateCommandTest extends TestCase
17+
{
18+
public function tearDown()
19+
{
20+
AspectMock::clean();
21+
}
22+
23+
public function testOneTestOneSuiteConfig()
24+
{
25+
$testOne = new TestObject('Test1', [], [], []);
26+
$suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne], [], []);
27+
28+
$testArray = ['Test1' => $testOne];
29+
$suiteArray = ['Suite1' => $suiteOne];
30+
31+
$this->mockHandlers($testArray, $suiteArray);
32+
33+
$actual = json_decode($this->callTestConfig(['Test1']), true);
34+
$expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1']]];
35+
$this->assertEquals($expected, $actual);
36+
}
37+
38+
public function testOneTestTwoSuitesConfig()
39+
{
40+
$testOne = new TestObject('Test1', [], [], []);
41+
$suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne], [], []);
42+
$suiteTwo = new SuiteObject('Suite2', ['Test1' => $testOne], [], []);
43+
44+
$testArray = ['Test1' => $testOne];
45+
$suiteArray = ['Suite1' => $suiteOne, 'Suite2' => $suiteTwo];
46+
47+
$this->mockHandlers($testArray, $suiteArray);
48+
49+
$actual = json_decode($this->callTestConfig(['Test1']), true);
50+
$expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1'], 'Suite2' => ['Test1']]];
51+
$this->assertEquals($expected, $actual);
52+
}
53+
54+
public function testOneTestOneGroup()
55+
{
56+
$testOne = new TestObject('Test1', [], ['group' => ['Group1']], []);
57+
58+
$testArray = ['Test1' => $testOne];
59+
$suiteArray = [];
60+
61+
$this->mockHandlers($testArray, $suiteArray);
62+
63+
$actual = json_decode($this->callGroupConfig(['Group1']), true);
64+
$expected = ['tests' => ['Test1'], 'suites' => null];
65+
$this->assertEquals($expected, $actual);
66+
}
67+
68+
public function testThreeTestsTwoGroup()
69+
{
70+
$testOne = new TestObject('Test1', [], ['group' => ['Group1']], []);
71+
$testTwo = new TestObject('Test2', [], ['group' => ['Group1']], []);
72+
$testThree = new TestObject('Test3', [], ['group' => ['Group2']], []);
73+
74+
$testArray = ['Test1' => $testOne, 'Test2' => $testTwo, 'Test3' => $testThree];
75+
$suiteArray = [];
76+
77+
$this->mockHandlers($testArray, $suiteArray);
78+
79+
$actual = json_decode($this->callGroupConfig(['Group1', 'Group2']), true);
80+
$expected = ['tests' => ['Test1', 'Test2', 'Test3'], 'suites' => null];
81+
$this->assertEquals($expected, $actual);
82+
}
83+
84+
public function testOneTestOneSuiteOneGroupConfig()
85+
{
86+
$testOne = new TestObject('Test1', [], ['group' => ['Group1']], []);
87+
$suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne], [], []);
88+
89+
$testArray = ['Test1' => $testOne];
90+
$suiteArray = ['Suite1' => $suiteOne];
91+
92+
$this->mockHandlers($testArray, $suiteArray);
93+
94+
$actual = json_decode($this->callGroupConfig(['Group1']), true);
95+
$expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1']]];
96+
$this->assertEquals($expected, $actual);
97+
}
98+
99+
public function testTwoTestOneSuiteTwoGroupConfig()
100+
{
101+
$testOne = new TestObject('Test1', [], ['group' => ['Group1']], []);
102+
$testTwo = new TestObject('Test2', [], ['group' => ['Group2']], []);
103+
$suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne, 'Test2' => $testTwo], [], []);
104+
105+
$testArray = ['Test1' => $testOne, 'Test2' => $testTwo];
106+
$suiteArray = ['Suite1' => $suiteOne];
107+
108+
$this->mockHandlers($testArray, $suiteArray);
109+
110+
$actual = json_decode($this->callGroupConfig(['Group1', 'Group2']), true);
111+
$expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1', 'Test2']]];
112+
$this->assertEquals($expected, $actual);
113+
}
114+
115+
public function testTwoTestTwoSuiteOneGroupConfig()
116+
{
117+
$testOne = new TestObject('Test1', [], ['group' => ['Group1']], []);
118+
$testTwo = new TestObject('Test2', [], ['group' => ['Group1']], []);
119+
$suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne], [], []);
120+
$suiteTwo = new SuiteObject('Suite2', ['Test2' => $testTwo], [], []);
121+
122+
$testArray = ['Test1' => $testOne, 'Test2' => $testTwo];
123+
$suiteArray = ['Suite1' => $suiteOne, 'Suite2' => $suiteTwo];
124+
125+
$this->mockHandlers($testArray, $suiteArray);
126+
127+
$actual = json_decode($this->callGroupConfig(['Group1']), true);
128+
$expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1'], 'Suite2' => ['Test2']]];
129+
$this->assertEquals($expected, $actual);
130+
}
131+
132+
/**
133+
* Test specific usecase of a test that is in a group with the group being called along with the suite
134+
* i.e. run:group Group1 Suite1
135+
* @throws \Exception
136+
*/
137+
public function testThreeTestOneSuiteOneGroupMix()
138+
{
139+
$testOne = new TestObject('Test1', [], [], []);
140+
$testTwo = new TestObject('Test2', [], [], []);
141+
$testThree = new TestObject('Test3', [], ['group' => ['Group1']], []);
142+
$suiteOne = new SuiteObject(
143+
'Suite1',
144+
['Test1' => $testOne, 'Test2' => $testTwo, 'Test3' => $testThree],
145+
[],
146+
[]
147+
);
148+
149+
$testArray = ['Test1' => $testOne, 'Test2' => $testTwo, 'Test3' => $testThree];
150+
$suiteArray = ['Suite1' => $suiteOne];
151+
152+
$this->mockHandlers($testArray, $suiteArray);
153+
154+
$actual = json_decode($this->callGroupConfig(['Group1', 'Suite1']), true);
155+
$expected = ['tests' => null, 'suites' => ['Suite1' => []]];
156+
$this->assertEquals($expected, $actual);
157+
}
158+
159+
/**
160+
* Mock handlers to skip parsing
161+
* @param array $testArray
162+
* @param array $suiteArray
163+
* @throws \Exception
164+
*/
165+
public function mockHandlers($testArray, $suiteArray)
166+
{
167+
AspectMock::double(TestObjectHandler::class, ['initTestData' => ''])->make();
168+
$handler = TestObjectHandler::getInstance();
169+
$property = new \ReflectionProperty(TestObjectHandler::class, 'tests');
170+
$property->setAccessible(true);
171+
$property->setValue($handler, $testArray);
172+
173+
AspectMock::double(SuiteObjectHandler::class, ['initSuiteData' => ''])->make();
174+
$handler = SuiteObjectHandler::getInstance();
175+
$property = new \ReflectionProperty(SuiteObjectHandler::class, 'suiteObjects');
176+
$property->setAccessible(true);
177+
$property->setValue($handler, $suiteArray);
178+
}
179+
180+
/**
181+
* Changes visibility and runs getTestAndSuiteConfiguration
182+
* @param array $testArray
183+
* @return string
184+
*/
185+
public function callTestConfig($testArray)
186+
{
187+
$command = new BaseGenerateCommand();
188+
$class = new \ReflectionClass($command);
189+
$method = $class->getMethod('getTestAndSuiteConfiguration');
190+
$method->setAccessible(true);
191+
return $method->invokeArgs($command, [$testArray]);
192+
}
193+
194+
/**
195+
* Changes visibility and runs getGroupAndSuiteConfiguration
196+
* @param array $groupArray
197+
* @return string
198+
*/
199+
public function callGroupConfig($groupArray)
200+
{
201+
$command = new BaseGenerateCommand();
202+
$class = new \ReflectionClass($command);
203+
$method = $class->getMethod('getGroupAndSuiteConfiguration');
204+
$method->setAccessible(true);
205+
return $method->invokeArgs($command, [$groupArray]);
206+
}
207+
}

dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Persist/OperationDataArrayResolverTest.php

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
1010
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\OperationDefinitionObjectHandler;
1111
use Magento\FunctionalTestingFramework\DataGenerator\Persist\OperationDataArrayResolver;
12+
use Magento\FunctionalTestingFramework\Util\Iterator\AbstractIterator;
1213
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
1314
use tests\unit\Util\EntityDataObjectBuilder;
1415
use tests\unit\Util\OperationDefinitionBuilder;
@@ -355,6 +356,127 @@ public function testNestedMetadataArrayOfValue()
355356
$this->assertEquals(self::NESTED_METADATA_ARRAY_RESULT, $result);
356357
}
357358

359+
public function testNestedMetadataArrayOfDiverseObjects()
360+
{
361+
362+
$entityDataObjBuilder = new EntityDataObjectBuilder();
363+
$parentDataObject = $entityDataObjBuilder
364+
->withName("parentObject")
365+
->withType("parentType")
366+
->withLinkedEntities(['child1Object' => 'childType1','child2Object' => 'childType2'])
367+
->build();
368+
369+
$child1DataObject = $entityDataObjBuilder
370+
->withName('child1Object')
371+
->withType('childType1')
372+
->withDataFields(['city' => 'Testcity','zip' => 12345])
373+
->build();
374+
375+
$child2DataObject = $entityDataObjBuilder
376+
->withName('child2Object')
377+
->withType('childType2')
378+
->withDataFields(['city' => 'Testcity 2','zip' => 54321,'state' => 'Teststate'])
379+
->build();
380+
381+
$mockDOHInstance = AspectMock::double(
382+
DataObjectHandler::class,
383+
[
384+
'getObject' => function ($name) use ($child1DataObject, $child2DataObject) {
385+
switch ($name) {
386+
case 'child1Object':
387+
return $child1DataObject;
388+
case 'child2Object':
389+
return $child2DataObject;
390+
}
391+
}
392+
]
393+
)->make();
394+
AspectMock::double(DataObjectHandler::class, [
395+
'getInstance' => $mockDOHInstance
396+
]);
397+
398+
$operationDefinitionBuilder = new OperationDefinitionBuilder();
399+
$child1OperationDefinition = $operationDefinitionBuilder
400+
->withName('createchildType1')
401+
->withOperation('create')
402+
->withType('childType1')
403+
->withMetadata([
404+
'city' => 'string',
405+
'zip' => 'integer'
406+
])->build();
407+
408+
$child2OperationDefinition = $operationDefinitionBuilder
409+
->withName('createchildType2')
410+
->withOperation('create')
411+
->withType('childType2')
412+
->withMetadata([
413+
'city' => 'string',
414+
'zip' => 'integer',
415+
'state' => 'string'
416+
])->build();
417+
418+
$mockODOHInstance = AspectMock::double(
419+
OperationDefinitionObjectHandler::class,
420+
[
421+
'getObject' => function ($name) use ($child1OperationDefinition, $child2OperationDefinition) {
422+
switch ($name) {
423+
case 'createchildType1':
424+
return $child1OperationDefinition;
425+
case 'createchildType2':
426+
return $child2OperationDefinition;
427+
}
428+
}
429+
]
430+
)->make();
431+
AspectMock::double(
432+
OperationDefinitionObjectHandler::class,
433+
[
434+
'getInstance' => $mockODOHInstance
435+
]
436+
);
437+
438+
$arrayObElementBuilder = new OperationElementBuilder();
439+
$arrayElement = $arrayObElementBuilder
440+
->withKey('address')
441+
->withType(['childType1','childType2'])
442+
->withFields([])
443+
->withElementType(OperationDefinitionObjectHandler::ENTITY_OPERATION_ARRAY)
444+
//->withNestedElements(['childType1' => $child1Element, 'childType2' => $child2Element])
445+
->build();
446+
447+
$parentOpElementBuilder = new OperationElementBuilder();
448+
$parentElement = $parentOpElementBuilder
449+
->withKey('parentType')
450+
->withType('parentType')
451+
->addElements(['address' => $arrayElement])
452+
->build();
453+
454+
$operationResolver = new OperationDataArrayResolver();
455+
$result = $operationResolver->resolveOperationDataArray($parentDataObject, [$parentElement], 'create', false);
456+
457+
$expectedResult = [
458+
'parentType' => [
459+
'address' => [
460+
[
461+
'city' => 'Testcity',
462+
'zip' => '12345'
463+
],
464+
[
465+
'city' => 'Testcity 2',
466+
'zip' => '54321',
467+
'state' => 'Teststate'
468+
]
469+
],
470+
'name' => 'Hopper',
471+
'gpa' => '3.5678',
472+
'phone' => '5555555',
473+
'isPrimary' => '1'
474+
]
475+
];
476+
477+
$this->assertEquals($expectedResult, $result);
478+
}
479+
358480
/**
359481
* After class functionality
360482
* @return void

0 commit comments

Comments
 (0)