-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add wait_until_ready config and check if phiremock server is actually…
… running (#48) * Add new config wait_until_ready and actually check if phiremock server is up and running * Mention phiremock client as optional dependency in readme * Refactor code, add readiness checker interface and implementations for Phiremock Client and basic curl * Update README.md
- Loading branch information
Showing
7 changed files
with
259 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* This file is part of codeception-phiremock-extension. | ||
* | ||
* phiremock-codeception-extension is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* phiremock-codeception-extension is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with phiremock-codeception-extension. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace Mcustiel\Phiremock\Codeception\Extension\ReadinessChecker; | ||
|
||
use Mcustiel\Phiremock\Codeception\Extension\ReadinessCheckerInterface; | ||
|
||
class CurlChecker implements ReadinessCheckerInterface | ||
{ | ||
private $url; | ||
|
||
public function __construct(string $url) | ||
{ | ||
$this->url = rtrim($url, '/'); | ||
} | ||
|
||
public function isReady(): bool | ||
{ | ||
$ch = \curl_init(); | ||
|
||
\curl_setopt($ch, CURLOPT_URL,$this->url . '/__phiremock/reset'); | ||
\curl_setopt($ch, CURLOPT_POST, 1); | ||
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
|
||
$output = \curl_exec($ch); | ||
\curl_close($ch); | ||
|
||
if ($output === false) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/PhiremockExtension/ReadinessChecker/PhiremockClientChecker.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* This file is part of codeception-phiremock-extension. | ||
* | ||
* phiremock-codeception-extension is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* phiremock-codeception-extension is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with phiremock-codeception-extension. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace Mcustiel\Phiremock\Codeception\Extension\ReadinessChecker; | ||
|
||
use GuzzleHttp\Exception\ConnectException; | ||
use Mcustiel\Phiremock\Codeception\Extension\ReadinessCheckerInterface; | ||
use Mcustiel\Phiremock\Client\Phiremock; | ||
use Psr\Http\Client\ClientExceptionInterface; | ||
|
||
class PhiremockClientChecker implements ReadinessCheckerInterface | ||
{ | ||
private $client; | ||
|
||
public function __construct(Phiremock $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
public function isReady(): bool | ||
{ | ||
try { | ||
$this->client->reset(); | ||
return true; | ||
} catch (ConnectException $e) {} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* This file is part of codeception-phiremock-extension. | ||
* | ||
* phiremock-codeception-extension is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* phiremock-codeception-extension is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with phiremock-codeception-extension. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace Mcustiel\Phiremock\Codeception\Extension; | ||
|
||
use Mcustiel\Phiremock\Client\Factory; | ||
use Mcustiel\Phiremock\Client\Connection\Host; | ||
use Mcustiel\Phiremock\Client\Connection\Port; | ||
use Mcustiel\Phiremock\Client\Connection\Scheme; | ||
use Mcustiel\Phiremock\Codeception\Extension\ReadinessChecker\CurlChecker; | ||
use Mcustiel\Phiremock\Codeception\Extension\ReadinessChecker\PhiremockClientChecker; | ||
|
||
class ReadinessCheckerFactory | ||
{ | ||
public static function create(string $host, string $port, bool $isSecure): ReadinessCheckerInterface | ||
{ | ||
if (class_exists(Factory::class)) { | ||
$phiremockClient = Factory::createDefault() | ||
->createPhiremockClient( | ||
new Host($host), | ||
new Port($port), | ||
$isSecure ? Scheme::createHttps() : Scheme::createHttp() | ||
); | ||
|
||
return new PhiremockClientChecker( | ||
$phiremockClient | ||
); | ||
} elseif (extension_loaded('curl')) { | ||
$url = 'http' . ($isSecure ? 's' : '') | ||
. '://' . $host | ||
. ($port !== '' ? ':' . $port : ''); | ||
|
||
return new CurlChecker($url); | ||
} | ||
|
||
throw new \RuntimeException( | ||
'Config wait_until_ready is enabled but no readiness checker can be run. Check if you have Phiremock Client installed or curl extension enabled.' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
/** | ||
* This file is part of codeception-phiremock-extension. | ||
* | ||
* phiremock-codeception-extension is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* phiremock-codeception-extension is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with phiremock-codeception-extension. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace Mcustiel\Phiremock\Codeception\Extension; | ||
|
||
interface ReadinessCheckerInterface | ||
{ | ||
public function isReady(): bool; | ||
} |