|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of codeception-phiremock-extension. |
|
4
|
|
|
* |
|
5
|
|
|
* phiremock-codeception-extension is free software: you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
|
7
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
8
|
|
|
* (at your option) any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* phiremock-codeception-extension is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU General Public License |
|
16
|
|
|
* along with phiremock-codeception-extension. If not, see <http://www.gnu.org/licenses/>. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Mcustiel\Phiremock\Codeception\Extension\ReadinessChecker; |
|
20
|
|
|
|
|
21
|
|
|
use Mcustiel\Phiremock\Codeception\Extension\ReadinessCheckerInterface; |
|
22
|
|
|
|
|
23
|
|
|
class CurlChecker implements ReadinessCheckerInterface |
|
24
|
|
|
{ |
|
25
|
|
|
private $url; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct(string $url) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->url = rtrim($url, '/'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function isReady(): bool |
|
33
|
|
|
{ |
|
34
|
|
|
$ch = \curl_init(); |
|
35
|
|
|
|
|
36
|
|
|
\curl_setopt($ch, CURLOPT_URL,$this->url . '/__phiremock/reset'); |
|
37
|
|
|
\curl_setopt($ch, CURLOPT_POST, 1); |
|
38
|
|
|
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
39
|
|
|
|
|
40
|
|
|
$output = \curl_exec($ch); |
|
41
|
|
|
\curl_close($ch); |
|
42
|
|
|
|
|
43
|
|
|
if ($output === false) { |
|
44
|
|
|
return false; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return true; |
|
48
|
|
|
} |
|
49
|
|
|
} |