1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace RMiller\BehatSpec\Extension\PhpSpecExtension\Process\ExemplifyRunner; |
4
|
|
|
|
5
|
|
|
use RMiller\BehatSpec\Extension\PhpSpecExtension\Process\CachingExecutableFinder; |
6
|
|
|
use RMiller\BehatSpec\Extension\PhpSpecExtension\Process\CommandRunner; |
7
|
|
|
use RMiller\BehatSpec\Extension\PhpSpecExtension\Process\ExemplifyRunner; |
8
|
|
|
|
9
|
|
View Code Duplication |
class PlatformSpecificExemplifyRunner implements ExemplifyRunner |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
const COMMAND_NAME = 'exemplify'; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private $phpspecPath; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $phpspecConfig; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var CommandRunner |
25
|
|
|
*/ |
26
|
|
|
private $commandRunner; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var CachingExecutableFinder |
30
|
|
|
*/ |
31
|
|
|
private $executableFinder; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param CommandRunner $commandRunner |
35
|
|
|
* @param CachingExecutableFinder $executableFinder |
36
|
|
|
* @param string $phpspecPath |
37
|
|
|
*/ |
38
|
|
|
public function __construct( |
39
|
|
|
CommandRunner $commandRunner, |
40
|
|
|
CachingExecutableFinder $executableFinder, |
41
|
|
|
$phpspecPath, |
42
|
|
|
$phpspecConfig |
43
|
|
|
) { |
44
|
|
|
$this->commandRunner = $commandRunner; |
45
|
|
|
$this->executableFinder = $executableFinder; |
46
|
|
|
$this->phpspecPath = $phpspecPath; |
47
|
|
|
$this->phpspecConfig = $phpspecConfig; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return boolean |
52
|
|
|
*/ |
53
|
|
|
public function isSupported() |
54
|
|
|
{ |
55
|
|
|
return $this->commandRunner->isSupported(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function runExemplifyCommand($className, $methodName) |
59
|
|
|
{ |
60
|
|
|
$this->commandRunner->runCommand( |
61
|
|
|
$this->executableFinder->getExecutablePath(), |
62
|
|
|
$this->getCommandArguments($className, $methodName) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param $className |
68
|
|
|
* @param $methodName |
69
|
|
|
* |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
private function getCommandArguments($className, $methodName) |
73
|
|
|
{ |
74
|
|
|
$commandArguments = [$this->phpspecPath, self::COMMAND_NAME]; |
75
|
|
|
$commandArguments = array_merge($commandArguments, $this->composeConfigOption()); |
76
|
|
|
array_push($commandArguments, $className, $methodName); |
77
|
|
|
|
78
|
|
|
return $commandArguments; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
|
|
private function composeConfigOption() |
85
|
|
|
{ |
86
|
|
|
$configOption = []; |
87
|
|
|
if (!is_null($this->phpspecConfig)) { |
88
|
|
|
array_push($configOption, '--config', $this->phpspecConfig); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return $configOption; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.