2 namespace Robo\Task\Testing;
4 use Robo\Contract\CommandInterface;
5 use Robo\Contract\PrintedInterface;
6 use Robo\Task\BaseTask;
21 class Behat extends BaseTask implements CommandInterface, PrintedInterface
23 use \Robo\Common\ExecOneCommand;
31 * @var string[] $formaters available formaters for format option
33 protected $formaters = ['progress', 'pretty', 'junit'];
36 * @var string[] $verbose_levels available verbose levels
38 protected $verbose_levels = ['v', 'vv'];
43 * @param null|string $pathToBehat
45 * @throws \Robo\Exception\TaskException
47 public function __construct($pathToBehat = null)
49 $this->command = $pathToBehat;
50 if (!$this->command) {
51 $this->command = $this->findExecutable('behat');
53 if (!$this->command) {
54 throw new \Robo\Exception\TaskException(__CLASS__, "Neither composer nor phar installation of Behat found");
61 public function stopOnFail()
63 $this->option('stop-on-failure');
70 public function noInteraction()
72 $this->option('no-interaction');
81 public function config($config_file)
83 $this->option('config', $config_file);
90 public function colors()
92 $this->option('colors');
99 public function noColors()
101 $this->option('no-colors');
106 * @param string $suite
110 public function suite($suite)
112 $this->option('suite', $suite);
117 * @param string $level
121 public function verbose($level = 'v')
123 if (!in_array($level, $this->verbose_levels)) {
124 throw new \InvalidArgumentException('expected ' . implode(',', $this->verbose_levels));
126 $this->option('-' . $level);
131 * @param string $formater
135 public function format($formater)
137 if (!in_array($formater, $this->formaters)) {
138 throw new \InvalidArgumentException('expected ' . implode(',', $this->formaters));
140 $this->option('format', $formater);
145 * Returns command that can be executed.
146 * This method is used to pass generated command from one task to another.
150 public function getCommand()
152 return $this->command . $this->arguments;
158 public function run()
160 $this->printTaskInfo('Running behat {arguments}', ['arguments' => $this->arguments]);
161 return $this->executeCommand($this->getCommand());