1 | <?php |
||
19 | class DockerChrome extends Extension |
||
20 | { |
||
21 | /** |
||
22 | * events |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | static public $events = [ |
||
27 | 'module.init' => 'moduleInit', |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * process |
||
32 | * |
||
33 | * @var \Symfony\Component\Process\Process |
||
34 | */ |
||
35 | private $process; |
||
36 | |||
37 | /** |
||
38 | * dockerStarted |
||
39 | * |
||
40 | * @var bool |
||
41 | */ |
||
42 | private $dockerStarted = false; |
||
43 | |||
44 | /** |
||
45 | * dockerComposePath |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | private $dockerComposePath; |
||
50 | |||
51 | /** |
||
52 | * DockerChrome constructor. |
||
53 | * |
||
54 | * @param array $config |
||
55 | * @param array $options |
||
56 | * @param \Symfony\Component\Process\Process|null $process |
||
57 | * @param string $defaultDockerComposePath |
||
58 | */ |
||
59 | 16 | public function __construct( |
|
60 | array $config, |
||
61 | array $options, |
||
62 | Process $process = null, |
||
63 | string $defaultDockerComposePath = '/usr/local/bin/docker-compose' |
||
64 | ) { |
||
65 | |||
66 | // Set default https proxy |
||
67 | 16 | if (!isset($options['silent'])) { |
|
68 | 16 | $options['silent'] = false; |
|
69 | } |
||
70 | |||
71 | 16 | $this->dockerComposePath = $defaultDockerComposePath; |
|
72 | |||
73 | 16 | parent::__construct($config, $options); |
|
74 | |||
75 | 16 | $this->initDefaultConfig(); |
|
76 | 16 | $command = $this->getCommand(); |
|
77 | 16 | $this->process = $process ?: new Process($command, realpath(__DIR__), null, null, 3600); |
|
78 | 16 | } |
|
79 | |||
80 | /** |
||
81 | * initDefaultConfig |
||
82 | * |
||
83 | * @return void |
||
84 | * @throws \Codeception\Exception\ExtensionException |
||
85 | */ |
||
86 | 16 | protected function initDefaultConfig() |
|
87 | { |
||
88 | 16 | $this->config['path'] = $this->config['path'] ?? $this->dockerComposePath; |
|
89 | |||
90 | // Set default WebDriver port |
||
91 | 16 | $this->config['port'] = $this->config['port'] ?? 4444; |
|
92 | |||
93 | // Set default debug mode |
||
94 | 16 | $this->config['debug'] = $this->config['debug'] ?? false; |
|
95 | |||
96 | // Set default extra_hosts mode |
||
97 | 16 | $this->config['extra_hosts'] = $this->config['extra_hosts'] ?? false; |
|
98 | |||
99 | // Set default http proxy |
||
100 | 16 | $this->config['http_proxy'] = $this->config['http_proxy'] ?? ''; |
|
101 | |||
102 | // Set default https proxy |
||
103 | 16 | $this->config['https_proxy'] = $this->config['https_proxy'] ?? ''; |
|
104 | |||
105 | // Set default https proxy |
||
106 | 16 | $this->config['no_proxy'] = $this->config['no_proxy'] ?? ''; |
|
107 | |||
108 | 16 | if (!file_exists($this->config['path'])) { |
|
109 | 2 | throw new ExtensionException($this, "File not found: {$this->config['path']}."); |
|
110 | } |
||
111 | 16 | } |
|
112 | |||
113 | /** |
||
114 | * getCommand |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | 16 | private function getCommand(): string |
|
122 | |||
123 | /** |
||
124 | * getConfig |
||
125 | * |
||
126 | * @return array |
||
127 | */ |
||
128 | 7 | public function getConfig(): array |
|
132 | |||
133 | /** |
||
134 | * |
||
135 | */ |
||
136 | 10 | public function __destruct() |
|
140 | |||
141 | /** |
||
142 | * stopServer |
||
143 | * |
||
144 | * @return void |
||
145 | */ |
||
146 | 10 | private function stopServer() |
|
155 | |||
156 | /** |
||
157 | * moduleInit |
||
158 | * |
||
159 | * @param \Codeception\Event\SuiteEvent $e |
||
160 | * @return void |
||
161 | */ |
||
162 | 6 | public function moduleInit(\Codeception\Event\SuiteEvent $e) |
|
172 | |||
173 | /** |
||
174 | * suiteAllowed |
||
175 | * |
||
176 | * @param \Codeception\Event\SuiteEvent $e |
||
177 | * @return bool |
||
178 | */ |
||
179 | 6 | protected function suiteAllowed(\Codeception\Event\SuiteEvent $e): bool |
|
196 | |||
197 | /** |
||
198 | * overrideWithModuleConfig |
||
199 | * |
||
200 | * @param \Codeception\Event\SuiteEvent $e |
||
201 | * @return void |
||
202 | */ |
||
203 | 5 | protected function overrideWithModuleConfig(\Codeception\Event\SuiteEvent $e) |
|
216 | |||
217 | /** |
||
218 | * generateYaml |
||
219 | * |
||
220 | * @return void |
||
221 | */ |
||
222 | 5 | protected function generateYaml() |
|
259 | |||
260 | /** |
||
261 | * startServer |
||
262 | * |
||
263 | * @return void |
||
264 | * @throws \Codeception\Exception\ExtensionException |
||
265 | */ |
||
266 | 5 | private function startServer() |
|
287 | } |
||
288 |