Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RoboFile.php
Go to the documentation of this file.
1 <?php
7 use Symfony\Component\Yaml\Yaml;
8 
14 class RoboFile extends \Robo\Tasks
15 {
16  use Robo\Task\Base\loadShortcuts;
17 
24  function buildProject()
25  {
26  passthru($this->getBaseCmd("build:project"));
27  }
28 
36  function generateTests(array $tests, $opts = [
37  'config' => null,
38  'force' => false,
39  'nodes' => null,
40  'lines' => null,
41  'tests' => null
42  ])
43  {
44  $baseCmd = $this->getBaseCmd("generate:tests");
45 
46  $mftfArgNames = ['config', 'nodes', 'lines', 'tests'];
47  // append arguments to the end of the command
48  foreach ($opts as $argName => $argValue) {
49  if (in_array($argName, $mftfArgNames) && $argValue !== null) {
50  $baseCmd .= " --$argName $argValue";
51  }
52  }
53 
54  // use a separate conditional for the force flag (casting bool to string in php is hard)
55  if ($opts['force']) {
56  $baseCmd .= ' --force';
57  }
58 
59  return $this->taskExec($baseCmd)->args($tests)->run();
60  }
61 
69  function generateSuite(array $args)
70  {
71  if (empty($args)) {
72  throw new Exception("Please provide suite name(s) after generate:suite command");
73  }
74  $baseCmd = $this->getBaseCmd("generate:suite");
75  return $this->taskExec($baseCmd)->args($args)->run();
76  }
77 
84  function group(array $args)
85  {
86  $args = array_merge($args, ['-k']);
87  $baseCmd = $this->getBaseCmd("run:group");
88  return $this->taskExec($baseCmd)->args($args)->run();
89  }
90 
96  function allure1Generate()
97  {
98  return $this->_exec('allure generate tests'. DIRECTORY_SEPARATOR .'_output'. DIRECTORY_SEPARATOR .'allure-results'. DIRECTORY_SEPARATOR .' -o tests'. DIRECTORY_SEPARATOR .'_output'. DIRECTORY_SEPARATOR .'allure-report'. DIRECTORY_SEPARATOR .'');
99  }
100 
106  function allure2Generate()
107  {
108  return $this->_exec('allure generate tests'. DIRECTORY_SEPARATOR .'_output'. DIRECTORY_SEPARATOR .'allure-results'. DIRECTORY_SEPARATOR .' --output tests'. DIRECTORY_SEPARATOR .'_output'. DIRECTORY_SEPARATOR .'allure-report'. DIRECTORY_SEPARATOR .' --clean');
109  }
110 
116  function allure1Open()
117  {
118  return $this->_exec('allure report open --report-dir tests'. DIRECTORY_SEPARATOR .'_output'. DIRECTORY_SEPARATOR .'allure-report'. DIRECTORY_SEPARATOR .'');
119  }
120 
126  function allure2Open()
127  {
128  return $this->_exec('allure open --port 0 tests'. DIRECTORY_SEPARATOR .'_output'. DIRECTORY_SEPARATOR .'allure-report'. DIRECTORY_SEPARATOR .'');
129  }
130 
136  function allure1Report()
137  {
138  $result1 = $this->allure1Generate();
139 
140  if ($result1->wasSuccessful()) {
141  return $this->allure1Open();
142  } else {
143  return $result1;
144  }
145  }
146 
152  function allure2Report()
153  {
154  $result1 = $this->allure2Generate();
155 
156  if ($result1->wasSuccessful()) {
157  return $this->allure2Open();
158  } else {
159  return $result1;
160  }
161  }
162 
169  private function getBaseCmd($command)
170  {
171  $this->writeln("\033[01;31m Use of robo will be deprecated with next major release, please use <root>/vendor/bin/mftf $command \033[0m");
172  chdir(__DIR__);
173  return realpath('../../../vendor/bin/mftf') . " $command";
174  }
175 }
generateSuite(array $args)
Definition: RoboFile.php:69
group(array $args)
Definition: RoboFile.php:84
allure2Generate()
Definition: RoboFile.php:106
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
buildProject()
Definition: RoboFile.php:24
generateTests(array $tests, $opts=[ 'config'=> null, 'force'=> false, 'nodes'=> null, 'lines'=> null, 'tests'=> null])
Definition: RoboFile.php:36
allure2Report()
Definition: RoboFile.php:152
allure1Generate()
Definition: RoboFile.php:96
passthru($command, &$return_var=null)
allure1Report()
Definition: RoboFile.php:136
allure2Open()
Definition: RoboFile.php:126
allure1Open()
Definition: RoboFile.php:116