|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PhpPactTest\CompatibilitySuite\Context\V2\Http; |
| 4 | + |
| 5 | +use Behat\Behat\Context\Context; |
| 6 | +use Behat\Gherkin\Node\TableNode; |
| 7 | +use PhpPactTest\CompatibilitySuite\Service\InteractionsStorageInterface; |
| 8 | +use PhpPactTest\CompatibilitySuite\Service\MatchingRulesStorageInterface; |
| 9 | +use PhpPactTest\CompatibilitySuite\Service\RequestBuilderInterface; |
| 10 | +use PhpPactTest\CompatibilitySuite\Service\RequestMatchingRuleBuilderInterface; |
| 11 | +use PhpPactTest\CompatibilitySuite\Service\ServerInterface; |
| 12 | + |
| 13 | +final class ConsumerContext implements Context |
| 14 | +{ |
| 15 | + public function __construct( |
| 16 | + private ServerInterface $server, |
| 17 | + private RequestBuilderInterface $requestBuilder, |
| 18 | + private RequestMatchingRuleBuilderInterface $requestMatchingRuleBuilder, |
| 19 | + private MatchingRulesStorageInterface $matchingRulesStorage, |
| 20 | + private InteractionsStorageInterface $storage, |
| 21 | + ) { |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * @When the mock server is started with interaction :id but with the following changes: |
| 26 | + */ |
| 27 | + public function theMockServerIsStartedWithInteractionButWithTheFollowingChanges(int $id, TableNode $table): void |
| 28 | + { |
| 29 | + $request = $this->storage->get(InteractionsStorageInterface::SERVER_DOMAIN, $id)->getRequest(); |
| 30 | + $this->requestBuilder->build($request, $table->getHash()[0]); |
| 31 | + if ($file = $this->matchingRulesStorage->get(MatchingRulesStorageInterface::REQUEST_DOMAIN, $id)) { |
| 32 | + $this->requestMatchingRuleBuilder->build($request, $file); |
| 33 | + } |
| 34 | + $this->server->register($id); |
| 35 | + } |
| 36 | +} |
0 commit comments