Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ParallelGroupSorterTest.php
Go to the documentation of this file.
1 <?php
7 
8 use AspectMock\Test as AspectMock;
15 
17 {
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', 'test4', 'test8'],
40  4 => ['test1', 'test9'],
41  5 => ['test3', 'test5', 'test10']
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 
58  public function testSortWithSuites()
59  {
60  // mock tests for test object handler.
61  $numberOfCalls = 0;
62  $mockTest1 = AspectMock::double(
63  TestObject::class,
64  ['getEstimatedDuration' => function () use (&$numberOfCalls) {
65  $actionCount = [300, 275];
66  $result = $actionCount[$numberOfCalls];
67  $numberOfCalls++;
68 
69  return $result;
70  }]
71  )->make();
72 
73  $mockHandler = AspectMock::double(
74  TestObjectHandler::class,
75  ['getObject' => function () use ($mockTest1) {
76  return $mockTest1;
77  }]
78  )->make();
79 
80  AspectMock::double(TestObjectHandler::class, ['getInstance' => $mockHandler])->make();
81 
82  // create test to size array
83  $sampleTestArray = [
84  'test1' => 100,
85  'test2' => 300,
86  'test3' => 500,
87  'test4' => 60,
88  'test5' => 125
89  ];
90 
91  // create mock suite references
92  $sampleSuiteArray = [
93  'mockSuite1' => ['mockTest1', 'mockTest2']
94  ];
95 
96  // perform sort
97  $testSorter = new ParallelGroupSorter();
98  $actualResult = $testSorter->getTestsGroupedBySize($sampleSuiteArray, $sampleTestArray, 500);
99 
100  // verify the resulting groups
101  $this->assertCount(4, $actualResult);
102 
103  $expectedResults = [
104  1 => ['mockSuite1_0'],
105  2 => ['mockSuite1_1'],
106  3 => ['test3'],
107  4 => ['test2','test5', 'test4'],
108  5 => ['test1'],
109  ];
110 
111  foreach ($actualResult as $groupNum => $group) {
112  $this->assertEquals($expectedResults[$groupNum], array_keys($group));
113  }
114  }
115 }
$group
Definition: sections.phtml:16