1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace GD; |
5
|
|
|
|
6
|
|
|
use Silly\Edition\Pimple\Application; |
7
|
|
|
use Symfony\Component\Process\Process; |
8
|
|
|
|
9
|
|
|
class RunTest extends BaseGherkinToDusk |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $command; |
17
|
|
|
|
18
|
|
|
protected $path_to_command; |
19
|
|
|
|
20
|
3 |
|
public function handleBrowser($path) |
21
|
|
|
{ |
22
|
3 |
|
$this->context = 'browser'; |
23
|
3 |
|
$this->setPathToCommand('php artisan dusk'); |
24
|
3 |
|
$this->runTestFromFile($path); |
25
|
3 |
|
} |
26
|
|
|
|
27
|
3 |
|
public function handleDomain($path) |
28
|
|
|
{ |
29
|
3 |
|
$this->context = 'domain'; |
30
|
3 |
|
$this->setPathToCommand('vendor/bin/phpunit'); |
31
|
3 |
|
$this->runTestFromFile($path); |
32
|
3 |
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
6 |
|
private function runTestFromFile($path) |
36
|
|
|
{ |
37
|
6 |
|
$this->setPathToFeature($path)->buildDuskTestName(); |
38
|
|
|
|
39
|
6 |
|
$path_to_test = $this->fullPathToDestinationFile(); |
40
|
|
|
|
41
|
6 |
|
$path_to_command = $this->getPathToCommand(); |
42
|
|
|
|
43
|
6 |
|
$this->setCommand(sprintf("%s %s", $path_to_command, $path_to_test)); |
44
|
|
|
|
45
|
6 |
|
$this->runCommand(); |
46
|
6 |
|
} |
47
|
|
|
|
48
|
|
|
protected function runCommand() |
49
|
|
|
{ |
50
|
|
|
$process = new \Symfony\Component\Process\Process($this->command); |
51
|
|
|
|
52
|
|
|
$process->setTimeout(600); |
53
|
|
|
|
54
|
|
|
$process->start(); |
55
|
|
|
|
56
|
|
|
$process->wait(function ($type, $buffer) use ($process) { |
57
|
|
|
if (Process::ERR === $type) { |
58
|
|
|
$this->app->getContainer()['output']->write($buffer); |
59
|
|
|
} else { |
60
|
|
|
$this->app->getContainer()['output']->write($buffer); |
61
|
|
|
} |
62
|
|
|
}); |
63
|
|
|
|
64
|
|
|
if (!$process->isSuccessful()) { |
65
|
|
|
//throw new ProcessFailedException($process); |
66
|
|
|
$this->app->getContainer()['output']->writeln("<error>Error with tests....</error>"); |
67
|
|
|
exit(1); |
|
|
|
|
68
|
|
|
} else { |
69
|
|
|
$this->app->getContainer()['output']->writeln("<fg=black;bg=green>All Tests Passed...</>"); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
6 |
|
public function getCommand() |
77
|
|
|
{ |
78
|
6 |
|
return $this->command; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $command |
83
|
|
|
*/ |
84
|
6 |
|
public function setCommand($command) |
85
|
|
|
{ |
86
|
6 |
|
$this->command = $command; |
87
|
6 |
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return mixed |
91
|
|
|
*/ |
92
|
6 |
|
public function getPathToCommand() |
93
|
|
|
{ |
94
|
6 |
|
return $this->path_to_command; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param mixed $path_to_command |
99
|
|
|
*/ |
100
|
6 |
|
public function setPathToCommand($path_to_command) |
101
|
|
|
{ |
102
|
6 |
|
$this->path_to_command = $path_to_command; |
103
|
6 |
|
} |
104
|
|
|
} |
105
|
|
|
|
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.