Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DefaultTestManifest.php
Go to the documentation of this file.
1 <?php
8 
11 
13 {
14  const DEFAULT_CONFIG = 'default';
15 
21  protected $manifestPath;
22 
28  private static $CLEARED_MANIFESTS = [];
29 
35  protected $testNames = [];
36 
43  public function __construct($suiteConfiguration, $testPath)
44  {
45  $this->manifestPath = dirname($testPath) . DIRECTORY_SEPARATOR . 'testManifest.txt';
46  $this->cleanManifest($this->manifestPath);
47  parent::__construct($testPath, self::DEFAULT_CONFIG, $suiteConfiguration);
48  }
49 
56  public function addTest($testObject)
57  {
58  $this->testNames[] = $testObject->getCodeceptionName();
59  }
60 
66  public function generate()
67  {
68  $fileResource = fopen($this->manifestPath, 'a');
69 
70  foreach ($this->testNames as $testName) {
71  $line = $this->relativeDirPath . DIRECTORY_SEPARATOR . $testName . '.php';
72  fwrite($fileResource, $line . PHP_EOL);
73  }
74 
75  $this->generateSuiteEntries($fileResource);
76 
77  fclose($fileResource);
78  }
79 
86  protected function generateSuiteEntries($fileResource)
87  {
88  foreach ($this->getSuiteConfig() as $suiteName => $tests) {
89  $line = "-g {$suiteName}";
90  fwrite($fileResource, $line . PHP_EOL);
91  }
92  }
93 
101  private function cleanManifest($path)
102  {
103  // if we have already cleared the file then simply return
104  if (in_array($path, self::$CLEARED_MANIFESTS)) {
105  return;
106  }
107 
108  // if the file exists remove
109  if (file_exists($path)) {
110  unlink($path);
111  }
112 
113  self::$CLEARED_MANIFESTS[] = $path;
114  }
115 }