| @@ 9-92 (lines=84) @@ | ||
| 6 | use RMiller\BehatSpec\Extension\PhpSpecExtension\Process\CommandRunner; | |
| 7 | use RMiller\BehatSpec\Extension\PhpSpecExtension\Process\DescRunner; | |
| 8 | ||
| 9 | class PlatformSpecificDescRunner implements DescRunner | |
| 10 | { | |
| 11 | const COMMAND_NAME = 'desc'; | |
| 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 runDescCommand($className) | |
| 59 |     { | |
| 60 | $this->commandRunner->runCommand( | |
| 61 | $this->executableFinder->getExecutablePath(), | |
| 62 | $this->getCommandArguments($className) | |
| 63 | ); | |
| 64 | } | |
| 65 | ||
| 66 | /** | |
| 67 | * @param $className | |
| 68 | * | |
| 69 | * @return array | |
| 70 | */ | |
| 71 | private function getCommandArguments($className) | |
| 72 |     { | |
| 73 | $commandArguments = [$this->phpspecPath, self::COMMAND_NAME]; | |
| 74 | $commandArguments = array_merge($commandArguments, $this->composeConfigOption()); | |
| 75 | array_push($commandArguments, $className); | |
| 76 | ||
| 77 | return $commandArguments; | |
| 78 | } | |
| 79 | ||
| 80 | /** | |
| 81 | * @return array | |
| 82 | */ | |
| 83 | private function composeConfigOption() | |
| 84 |     { | |
| 85 | $configOption = []; | |
| 86 |         if (!is_null($this->phpspecConfig)) { | |
| 87 | array_push($configOption, '--config', $this->phpspecConfig); | |
| 88 | } | |
| 89 | ||
| 90 | return $configOption; | |
| 91 | } | |
| 92 | } | |
| 93 | ||
| @@ 9-93 (lines=85) @@ | ||
| 6 | use RMiller\BehatSpec\Extension\PhpSpecExtension\Process\CommandRunner; | |
| 7 | use RMiller\BehatSpec\Extension\PhpSpecExtension\Process\ExemplifyRunner; | |
| 8 | ||
| 9 | 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 | ||