1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mcustiel\Phiremock\Codeception\Extension; |
4
|
|
|
|
5
|
|
|
class CommandBuilder |
6
|
|
|
{ |
7
|
|
|
/** @var Config */ |
8
|
|
|
private $config; |
9
|
|
|
|
10
|
|
|
public function __construct(Config $config) |
11
|
|
|
{ |
12
|
|
|
$this->config = $config; |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
public function build(): array |
16
|
|
|
{ |
17
|
|
|
$path = $this->config->getPhiremockPath(); |
18
|
|
|
$phiremockPath = is_file($path) ? $path : $path . DIRECTORY_SEPARATOR . 'phiremock'; |
19
|
|
|
|
20
|
|
|
$commandline = [ |
21
|
|
|
$this->getCommandPrefix() . $phiremockPath, |
|
|
|
|
22
|
|
|
'-i', |
23
|
|
|
$this->config->getInterface(), |
24
|
|
|
'-p', |
25
|
|
|
$this->config->getPort(), |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
$this->addDebugMode($commandline); |
29
|
|
|
$this->addExpectationsPath($commandline); |
30
|
|
|
$this->addServerFactory($commandline); |
31
|
|
|
$this->addCertificate($commandline); |
32
|
|
|
|
33
|
|
|
$commandline[] = '>'; |
34
|
|
|
$this->addLogFile($commandline); |
35
|
|
|
$commandline[] = '2>&1'; |
36
|
|
|
|
37
|
|
|
return $commandLine; |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
private function addLogFile(array &$commandline): void |
41
|
|
|
{ |
42
|
|
|
$path = $this->config->getLogsPath(); |
43
|
|
|
$logFile = is_dir($path) ? $path . DIRECTORY_SEPARATOR . self::LOG_FILE_NAME : $path; |
|
|
|
|
44
|
|
|
$commandline[] = $logFile; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
private function addCertificate(array &$commandline): void |
48
|
|
|
{ |
49
|
|
|
if ($this->config->getCertificatePath()) { |
50
|
|
|
$commandline[] = '-t'; |
51
|
|
|
$commandline[] = $this->config->getCertificatePath(); |
52
|
|
|
$commandline[] = '-k'; |
53
|
|
|
$commandline[] = $this->config->getCertificateKeyPath(); |
54
|
|
|
if ($this->config->getCertificatePassphrase()) { |
55
|
|
|
$commandline[] = '-s'; |
56
|
|
|
$commandline[] = $this->config->getCertificatePassphrase(); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function addServerFactory(array &$commandline): void |
62
|
|
|
{ |
63
|
|
|
if ($this->config->getServerFactory()) { |
64
|
|
|
$commandline[] = '-f'; |
65
|
|
|
$commandline[] = escapeshellarg($this->config->getServerFactory()); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
private function addExpectationsPath(array &$commandline): void |
70
|
|
|
{ |
71
|
|
|
$path = $this->config->getExpectationsPath(); |
72
|
|
|
$expectationsPath = is_dir($path) ? $path : ''; |
73
|
|
|
if ($expectationsPath) { |
74
|
|
|
$commandline[] = '-e'; |
75
|
|
|
$commandline[] = $expectationsPath; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
private function addDebugMode(array &$commandline): void |
80
|
|
|
{ |
81
|
|
|
if ($this->config->isDebugMode()) { |
82
|
|
|
$commandline[] = '-d'; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.