-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(strategies): added regex matches replacements for proxy response (…
…#15) * feat(strategies): added regex matches replacements for proxy response * docs: added documentation about proxyto generated with data from the request * test: added test for the new feature (proxyto with data from the request) * chore: created phar and added new box config file
- Loading branch information
Showing
13 changed files
with
335 additions
and
119 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ vendor/ | |
.project | ||
.settings | ||
composer.lock | ||
tests/_output | ||
tests/_support/_generated |
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,19 @@ | ||
{ | ||
"directories" : [ "src" ], | ||
"compactors": [ "KevinGH\\Box\\Compactor\\Php" ], | ||
"dump-autoload": false, | ||
"chmod" : "0755", | ||
"main" : "bin/phiremock", | ||
"output" : "phiremock.phar", | ||
"stub" : true, | ||
"files": [ | ||
"LICENSE" | ||
], | ||
"finder": [ | ||
{ | ||
"name": ["*.php"], | ||
"exclude": ["Tests", "tests"], | ||
"in": ["vendor", "."] | ||
} | ||
] | ||
} |
Binary file not shown.
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,72 @@ | ||
<?php | ||
/** | ||
* This file is part of Phiremock. | ||
* | ||
* Phiremock 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 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. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace Mcustiel\Phiremock\Server\Utils\Strategies; | ||
|
||
use Laminas\Diactoros\Uri; | ||
use Mcustiel\Phiremock\Domain\Expectation; | ||
use Mcustiel\Phiremock\Domain\ProxyResponse; | ||
use Mcustiel\Phiremock\Server\Model\ScenarioStorage; | ||
use Mcustiel\Phiremock\Server\Utils\Strategies\Utils\RegexReplacer; | ||
use Psr\Http\Client\ClientInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class RegexProxyResponseStrategy extends AbstractResponse implements ResponseStrategyInterface | ||
{ | ||
/** @var ClientInterface */ | ||
private $httpService; | ||
/** @var RegexReplacer */ | ||
private $regexReplacer; | ||
|
||
public function __construct( | ||
ScenarioStorage $scenarioStorage, | ||
LoggerInterface $logger, | ||
ClientInterface $httpService, | ||
RegexReplacer $regexReplacer | ||
) { | ||
parent::__construct($scenarioStorage, $logger); | ||
$this->httpService = $httpService; | ||
$this->regexReplacer = $regexReplacer; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @see \Mcustiel\Phiremock\Server\Utils\Strategies\ResponseStrategyInterface::createResponse() | ||
*/ | ||
public function createResponse( | ||
Expectation $expectation, | ||
ResponseInterface $transactionData, | ||
ServerRequestInterface $request | ||
): ResponseInterface { | ||
/** @var ProxyResponse $response */ | ||
$response = $expectation->getResponse(); | ||
$url = $response->getUri()->asString(); | ||
$url = $this->regexReplacer->fillWithUrlMatches($expectation, $request, $url); | ||
$url = $this->regexReplacer->fillWithBodyMatches($expectation, $request, $url); | ||
$this->logger->debug('Proxying request to : ' . $url); | ||
$this->processScenario($expectation); | ||
$this->processDelay($response); | ||
|
||
return $this->httpService->sendRequest( | ||
$request->withUri(new Uri($url)) | ||
); | ||
} | ||
} |
Oops, something went wrong.