2 namespace Robo\Task\Testing;
4 use Robo\Contract\PrintedInterface;
5 use Robo\Task\BaseTask;
6 use Robo\Contract\CommandInterface;
9 * Executes Phpspec tests
13 * $this->taskPhpspec()
21 class Phpspec extends BaseTask implements CommandInterface, PrintedInterface
23 use \Robo\Common\ExecOneCommand;
31 * @var string[] $formaters available formaters for format option
33 protected $formaters = ['progress', 'html', 'pretty', 'junit', 'dot', 'tap'];
36 * @var array $verbose_levels available verbose levels
38 protected $verbose_levels = ['v', 'vv', 'vvv'];
40 public function __construct($pathToPhpspec = null)
42 $this->command = $pathToPhpspec;
43 if (!$this->command) {
44 $this->command = $this->findExecutable('phpspec');
46 if (!$this->command) {
47 throw new \Robo\Exception\TaskException(__CLASS__, "Neither composer nor phar installation of Phpspec found");
52 public function stopOnFail()
54 $this->option('stop-on-failure');
58 public function noCodeGeneration()
60 $this->option('no-code-generation');
64 public function quiet()
66 $this->option('quiet');
70 public function verbose($level = 'v')
72 if (!in_array($level, $this->verbose_levels)) {
73 throw new \InvalidArgumentException('expected ' . implode(',', $this->verbose_levels));
75 $this->option('-' . $level);
79 public function noAnsi()
81 $this->option('no-ansi');
85 public function noInteraction()
87 $this->option('no-interaction');
91 public function config($config_file)
93 $this->option('config', $config_file);
97 public function format($formater)
99 if (!in_array($formater, $this->formaters)) {
100 throw new \InvalidArgumentException('expected ' . implode(',', $this->formaters));
102 $this->option('format', $formater);
106 public function getCommand()
108 return $this->command . $this->arguments;
111 public function run()
113 $this->printTaskInfo('Running phpspec {arguments}', ['arguments' => $this->arguments]);
114 return $this->executeCommand($this->getCommand());