2 namespace Robo\Task\Testing;
4 use Robo\Contract\CommandInterface;
5 use Robo\Contract\PrintedInterface;
6 use Robo\Task\BaseTask;
13 * $this->taskPHPUnit()
15 * ->bootstrap('test/bootstrap.php')
21 class PHPUnit extends BaseTask implements CommandInterface, PrintedInterface
23 use \Robo\Common\ExecOneCommand;
31 * Directory of test files or single test file to run. Appended to
32 * the command and arguments.
36 protected $files = '';
38 public function __construct($pathToPhpUnit = null)
40 $this->command = $pathToPhpUnit;
41 if (!$this->command) {
42 $this->command = $this->findExecutablePhar('phpunit');
44 if (!$this->command) {
45 throw new \Robo\Exception\TaskException(__CLASS__, "Neither local phpunit nor global composer installation not found");
50 * @param string $filter
54 public function filter($filter)
56 $this->option('filter', $filter);
61 * @param string $group
65 public function group($group)
67 $this->option("group", $group);
72 * @param string $group
76 public function excludeGroup($group)
78 $this->option("exclude-group", $group);
83 * adds `log-json` option to runner
89 public function json($file = null)
91 $this->option("log-json", $file);
96 * adds `log-junit` option
102 public function xml($file = null)
104 $this->option("log-junit", $file);
109 * @param string $file
113 public function tap($file = "")
115 $this->option("log-tap", $file);
120 * @param string $file
124 public function bootstrap($file)
126 $this->option("bootstrap", $file);
131 * @param string $file
135 public function configFile($file)
137 $this->option('-c', $file);
144 public function debug()
146 $this->option("debug");
151 * Directory of test files or single test file to run.
153 * @param string $files A single test file or a directory containing test files.
157 * @throws \Robo\Exception\TaskException
159 * @deprecated Use file() or dir() method instead
161 public function files($files)
163 if (!empty($this->files) || is_array($files)) {
164 throw new \Robo\Exception\TaskException(__CLASS__, "Only one file or directory may be provided.");
166 $this->files = ' ' . $files;
172 * Test the provided file.
174 * @param string $file path to file to test
178 public function file($file)
180 return $this->files($file);
186 public function getCommand()
188 return $this->command . $this->arguments . $this->files;
194 public function run()
196 $this->printTaskInfo('Running PHPUnit {arguments}', ['arguments' => $this->arguments]);
197 return $this->executeCommand($this->getCommand());