Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ParallelTestManifest.php
Go to the documentation of this file.
1 <?php
8 
9 use Codeception\Suite;
17 use RecursiveArrayIterator;
18 use RecursiveIteratorIterator;
19 
21 {
22  const PARALLEL_CONFIG = 'parallel';
23 
29  private $testNameToSize = [];
30 
36  private $testGroups;
37 
43  private $parallelGroupSorter;
44 
50  private $dirPath;
51 
58  public function __construct($suiteConfiguration, $testPath)
59  {
60  $this->dirPath = dirname($testPath) . DIRECTORY_SEPARATOR . 'groups';
61  $this->parallelGroupSorter = new ParallelGroupSorter();
62  parent::__construct($testPath, self::PARALLEL_CONFIG, $suiteConfiguration);
63  }
64 
71  public function addTest($testObject)
72  {
73  $this->testNameToSize[$testObject->getCodeceptionName()] = $testObject->getEstimatedDuration();
74  }
75 
83  public function createTestGroups($time)
84  {
85  $this->testGroups = $this->parallelGroupSorter->getTestsGroupedBySize(
86  $this->getSuiteConfig(),
87  $this->testNameToSize,
88  $time
89  );
90 
91  $this->suiteConfiguration = $this->parallelGroupSorter->getResultingSuiteConfig();
92  }
93 
99  public function generate()
100  {
101  DirSetupUtil::createGroupDir($this->dirPath);
102  $suites = $this->getFlattenedSuiteConfiguration($this->suiteConfiguration ?? []);
103 
104  foreach ($this->testGroups as $groupNumber => $groupContents) {
105  $this->generateGroupFile($groupContents, $groupNumber, $suites);
106  }
107  }
108 
114  public function getSorter()
115  {
116  return $this->parallelGroupSorter;
117  }
118 
129  private function generateGroupFile($testGroup, $nodeNumber, $suites)
130  {
131  foreach ($testGroup as $entryName => $testValue) {
132  $fileResource = fopen($this->dirPath . DIRECTORY_SEPARATOR . "group{$nodeNumber}.txt", 'a');
133 
134  $line = null;
135  if (array_key_exists($entryName, $suites)) {
136  $line = "-g {$entryName}";
137  } else {
138  $line = $this->relativeDirPath . DIRECTORY_SEPARATOR . $entryName . '.php';
139  }
140  fwrite($fileResource, $line . PHP_EOL);
141  fclose($fileResource);
142  }
143  }
144 
152  private function getFlattenedSuiteConfiguration($multiDimensionalSuites)
153  {
154  $suites = [];
155  foreach ($multiDimensionalSuites as $suiteName => $suiteContent) {
156  $value = array_values($suiteContent)[0];
157  if (is_array($value)) {
158  $suites = array_merge($suites, $this->getFlattenedSuiteConfiguration($suiteContent));
159  continue;
160  }
161 
162  $suites[$suiteName] = $suiteContent;
163  }
164 
165  return $suites;
166  }
167 }
$value
Definition: gender.phtml:16