Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / consolidation / robo / src / Task / Testing / Phpspec.php
1 <?php
2 namespace Robo\Task\Testing;
3
4 use Robo\Contract\PrintedInterface;
5 use Robo\Task\BaseTask;
6 use Robo\Contract\CommandInterface;
7
8 /**
9  * Executes Phpspec tests
10  *
11  * ``` php
12  * <?php
13  * $this->taskPhpspec()
14  *      ->format('pretty')
15  *      ->noInteraction()
16  *      ->run();
17  * ?>
18  * ```
19  *
20  */
21 class Phpspec extends BaseTask implements CommandInterface, PrintedInterface
22 {
23     use \Robo\Common\ExecOneCommand;
24
25     /**
26      * @var string
27      */
28     protected $command;
29
30     /**
31      * @var string[] $formaters available formaters for format option
32      */
33     protected $formaters = ['progress', 'html', 'pretty', 'junit', 'dot', 'tap'];
34
35     /**
36      * @var array $verbose_levels available verbose levels
37      */
38     protected $verbose_levels = ['v', 'vv', 'vvv'];
39
40     public function __construct($pathToPhpspec = null)
41     {
42         $this->command = $pathToPhpspec;
43         if (!$this->command) {
44             $this->command = $this->findExecutable('phpspec');
45         }
46         if (!$this->command) {
47             throw new \Robo\Exception\TaskException(__CLASS__, "Neither composer nor phar installation of Phpspec found");
48         }
49         $this->arg('run');
50     }
51
52     public function stopOnFail()
53     {
54         $this->option('stop-on-failure');
55         return $this;
56     }
57
58     public function noCodeGeneration()
59     {
60         $this->option('no-code-generation');
61         return $this;
62     }
63
64     public function quiet()
65     {
66         $this->option('quiet');
67         return $this;
68     }
69
70     public function verbose($level = 'v')
71     {
72         if (!in_array($level, $this->verbose_levels)) {
73             throw new \InvalidArgumentException('expected ' . implode(',', $this->verbose_levels));
74         }
75         $this->option('-' . $level);
76         return $this;
77     }
78
79     public function noAnsi()
80     {
81         $this->option('no-ansi');
82         return $this;
83     }
84
85     public function noInteraction()
86     {
87         $this->option('no-interaction');
88         return $this;
89     }
90
91     public function config($config_file)
92     {
93         $this->option('config', $config_file);
94         return $this;
95     }
96
97     public function format($formater)
98     {
99         if (!in_array($formater, $this->formaters)) {
100             throw new \InvalidArgumentException('expected ' . implode(',', $this->formaters));
101         }
102         $this->option('format', $formater);
103         return $this;
104     }
105
106     public function getCommand()
107     {
108         return $this->command . $this->arguments;
109     }
110
111     public function run()
112     {
113         $this->printTaskInfo('Running phpspec {arguments}', ['arguments' => $this->arguments]);
114         return $this->executeCommand($this->getCommand());
115     }
116 }