1 | <?php |
||
18 | class TestRunner |
||
19 | { |
||
20 | /** |
||
21 | * @var Application |
||
22 | */ |
||
23 | private $app; |
||
24 | |||
25 | /** |
||
26 | * @var InputInterface |
||
27 | */ |
||
28 | private $input; |
||
29 | |||
30 | /** |
||
31 | * @var OutputInterface |
||
32 | */ |
||
33 | private $output; |
||
34 | |||
35 | /** |
||
36 | * @var Configuration |
||
37 | */ |
||
38 | private $configuration; |
||
39 | |||
40 | 6 | public function __construct( |
|
51 | |||
52 | 1 | public function getRootDir() : string |
|
56 | |||
57 | 1 | public function generatePhpunitXml(array &$files) : string |
|
58 | { |
||
59 | // load the config into memory |
||
60 | 1 | $phpunitXmlDistPath = is_file($file = $this->getRootDir().'/phpunit.xml') |
|
61 | ? $file |
||
62 | 1 | : $this->getRootDir().'/phpunit.xml.dist' |
|
63 | ; |
||
64 | |||
65 | 1 | $src = file_get_contents($phpunitXmlDistPath); |
|
66 | 1 | $xml = simplexml_load_string(str_replace('./', $this->getRootDir().'/', $src)); |
|
67 | |||
68 | // temp config file |
||
69 | 1 | $config = tempnam($this->getRootDir(), 'phpunitxml'); |
|
70 | |||
71 | register_shutdown_function(function() use ($config) { |
||
72 | unlink($config); |
||
73 | 1 | }); |
|
74 | |||
75 | 1 | unset($xml->testsuites[0]->testsuite); |
|
76 | 1 | $suite = $xml->testsuites[0]->addChild('testsuite'); |
|
77 | |||
78 | 1 | if (!empty($files)) { |
|
79 | 1 | $files = array_unique($files); |
|
80 | |||
81 | 1 | foreach ($files as $file) { |
|
82 | 1 | $path = strpos($file, '/') === 0 |
|
83 | ? $file |
||
84 | 1 | : $this->getRootDir().'/'.$file; |
|
85 | |||
86 | 1 | $suite->addChild('file', $path); |
|
87 | } |
||
88 | |||
89 | 1 | file_put_contents($config, $xml->asXml()); |
|
90 | |||
91 | 1 | return $config; |
|
92 | } |
||
93 | |||
94 | return ''; |
||
95 | } |
||
96 | |||
97 | 1 | public function runTestFiles(array $files, array $env = []) : int |
|
117 | |||
118 | 1 | public function runPhpunit(string $command, array $env = [], \Closure $callback = null) : int |
|
128 | |||
129 | public function getPhpunitProcess(string $command, array $env = []) : Process |
||
139 | |||
140 | /** |
||
141 | * @throws RuntimeException |
||
142 | */ |
||
143 | 2 | public function run(string $command, bool $throw = true, array $env = [], \Closure $callback = null) : int |
|
144 | { |
||
145 | 2 | $process = $this->getProcess($command, $env); |
|
146 | |||
147 | 2 | if ($callback === null) { |
|
148 | $callback = function($output) { |
||
149 | echo $output; |
||
150 | 2 | }; |
|
151 | } |
||
152 | |||
153 | 2 | $process->run(function($type, $output) use ($callback) { |
|
154 | $callback($output); |
||
155 | 2 | }); |
|
156 | |||
157 | 2 | if ($process->getExitCode() > 0 && $throw) { |
|
158 | 1 | throw new RuntimeException('The command did not exit successfully.'); |
|
159 | } |
||
160 | |||
161 | 1 | return $process->getExitCode(); |
|
162 | } |
||
163 | |||
164 | 2 | public function getProcess(string $command, array $env = []) : Process |
|
176 | |||
177 | 1 | public function runTestCommand(string $command, array $input = []) : int |
|
184 | |||
185 | 1 | private function flags() : string |
|
215 | |||
216 | protected function createProcess(string $command) : Process |
||
220 | } |
||
221 |