2 namespace Robo\Task\Testing;
4 use Robo\Contract\PrintedInterface;
5 use Robo\Exception\TaskException;
6 use Robo\Task\BaseTask;
7 use Robo\Contract\CommandInterface;
8 use Symfony\Component\Process\Process;
11 * Executes Codeception tests
16 * $this->taskCodecept()
17 * ->suite('acceptance')
28 class Codecept extends BaseTask implements CommandInterface, PrintedInterface
30 use \Robo\Common\ExecOneCommand;
38 * @param string $pathToCodeception
40 * @throws \Robo\Exception\TaskException
42 public function __construct($pathToCodeception = '')
44 $this->command = $pathToCodeception;
45 if (!$this->command) {
46 $this->command = $this->findExecutable('codecept');
48 if (!$this->command) {
49 throw new TaskException(__CLASS__, "Neither composer nor phar installation of Codeception found.");
51 $this->command .= ' run';
55 * @param string $suite
59 public function suite($suite)
61 $this->option(null, $suite);
66 * @param string $testName
70 public function test($testName)
72 $this->option(null, $testName);
77 * set group option. Can be called multiple times
79 * @param string $group
83 public function group($group)
85 $this->option("group", $group);
90 * @param string $group
94 public function excludeGroup($group)
96 $this->option("skip-group", $group);
101 * generate json report
103 * @param string $file
107 public function json($file = null)
109 $this->option("json", $file);
114 * generate xml JUnit report
116 * @param string $file
120 public function xml($file = null)
122 $this->option("xml", $file);
127 * Generate html report
133 public function html($dir = null)
135 $this->option("html", $dir);
140 * generate tap report
142 * @param string $file
146 public function tap($file = null)
148 $this->option("tap", $file);
153 * provides config file other then default `codeception.yml` with `-c` option
155 * @param string $file
159 public function configFile($file)
161 $this->option("-c", $file);
166 * collect codecoverage in raw format. You may pass name of cov file to save results
168 * @param null|string $cov
172 public function coverage($cov = null)
174 $this->option("coverage", $cov);
179 * execute in silent mode
183 public function silent()
185 $this->option("silent");
190 * collect code coverage in xml format. You may pass name of xml file to save results
196 public function coverageXml($xml = null)
198 $this->option("coverage-xml", $xml);
203 * collect code coverage and generate html report. You may pass
205 * @param string $html
209 public function coverageHtml($html = null)
211 $this->option("coverage-html", $html);
220 public function env($env)
222 $this->option("env", $env);
229 public function debug()
231 $this->option("debug");
238 public function noRebuild()
240 $this->option("no-rebuild");
245 * @param string $failGroup
248 public function failGroup($failGroup)
250 $this->option('override', "extensions: config: Codeception\\Extension\\RunFailed: fail-group: {$failGroup}");
257 public function getCommand()
259 return $this->command . $this->arguments;
265 public function run()
267 $command = $this->getCommand();
268 $this->printTaskInfo('Executing {command}', ['command' => $command]);
269 return $this->executeCommand($command);