Skip to content

Commit

Permalink
Merge pull request #430 from tienvx/v2-http-consumer-provider
Browse files Browse the repository at this point in the history
test(compatibility-suite): Implement V2 scenarios
  • Loading branch information
tienvx committed Dec 22, 2023
2 parents c07b72a + 6b21ab1 commit 556ec04
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/compatibility-suite.yml
Expand Up @@ -22,3 +22,19 @@ jobs:

- name: Run Behat
run: vendor/bin/behat compatibility-suite/pact-compatibility-suite/features/V1
v2:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- uses: shivammathur/setup-php@v2
with:
php-version: 8.2
coverage: none

- uses: ramsey/composer-install@v2

- name: Run Behat
run: vendor/bin/behat compatibility-suite/pact-compatibility-suite/features/V2
2 changes: 2 additions & 0 deletions behat.yml
@@ -1,3 +1,5 @@
imports:
- 'compatibility-suite/suites/v1/http/consumer.yml'
- 'compatibility-suite/suites/v1/http/provider.yml'
- 'compatibility-suite/suites/v2/http/consumer.yml'
- 'compatibility-suite/suites/v2/http/provider.yml'
29 changes: 29 additions & 0 deletions compatibility-suite/suites/v2/http/consumer.yml
@@ -0,0 +1,29 @@
default:
suites:
v2_http_consumer:
paths: [ '%paths.base%/compatibility-suite/pact-compatibility-suite/features/V2/http_consumer.feature' ]

contexts:
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Hook\SetUpContext'
- 'PhpPactTest\CompatibilitySuite\Context\Shared\InteractionsContext':
- '@interactions_storage'
- '@request_matching_rule_builder'
- '@response_matching_rule_builder'
- '@matching_rules_storage'
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Transform\InteractionsContext':
- '@interaction_builder'
- '@matching_rules_storage'
- 'PhpPactTest\CompatibilitySuite\Context\V1\Http\ConsumerContext':
- '@server'
- '@request_builder'
- '@client'
- '@interactions_storage'
- '@fixture_loader'
- 'PhpPactTest\CompatibilitySuite\Context\V2\Http\ConsumerContext':
- '@server'
- '@request_builder'
- '@request_matching_rule_builder'
- '@matching_rules_storage'
- '@interactions_storage'

services: PhpPactTest\CompatibilitySuite\ServiceContainer\V2
30 changes: 30 additions & 0 deletions compatibility-suite/suites/v2/http/provider.yml
@@ -0,0 +1,30 @@
default:
suites:
v2_http_provider:
paths: [ '%paths.base%/compatibility-suite/pact-compatibility-suite/features/V2/http_provider.feature' ]

contexts:
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Hook\SetUpContext'
- 'PhpPactTest\CompatibilitySuite\Context\Shared\InteractionsContext':
- '@interactions_storage'
- '@request_matching_rule_builder'
- '@response_matching_rule_builder'
- '@matching_rules_storage'
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Transform\InteractionsContext':
- '@interaction_builder'
- '@matching_rules_storage'
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Hook\ProviderStateContext':
- '@provider_state_server'
- 'PhpPactTest\CompatibilitySuite\Context\Shared\ProviderContext':
- '@server'
- '@provider_verifier'
- '@provider_state_server'
- 'PhpPactTest\CompatibilitySuite\Context\V1\Http\ProviderContext':
- '@server'
- '@pact_writer'
- '@pact_broker'
- '@response_builder'
- '@interactions_storage'
- '@provider_verifier'

services: PhpPactTest\CompatibilitySuite\ServiceContainer\V2
36 changes: 36 additions & 0 deletions compatibility-suite/tests/Context/V2/Http/ConsumerContext.php
@@ -0,0 +1,36 @@
<?php

namespace PhpPactTest\CompatibilitySuite\Context\V2\Http;

use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\TableNode;
use PhpPactTest\CompatibilitySuite\Service\InteractionsStorageInterface;
use PhpPactTest\CompatibilitySuite\Service\MatchingRulesStorageInterface;
use PhpPactTest\CompatibilitySuite\Service\RequestBuilderInterface;
use PhpPactTest\CompatibilitySuite\Service\RequestMatchingRuleBuilderInterface;
use PhpPactTest\CompatibilitySuite\Service\ServerInterface;

final class ConsumerContext implements Context
{
public function __construct(
private ServerInterface $server,
private RequestBuilderInterface $requestBuilder,
private RequestMatchingRuleBuilderInterface $requestMatchingRuleBuilder,
private MatchingRulesStorageInterface $matchingRulesStorage,
private InteractionsStorageInterface $storage,
) {
}

/**
* @When the mock server is started with interaction :id but with the following changes:
*/
public function theMockServerIsStartedWithInteractionButWithTheFollowingChanges(int $id, TableNode $table): void
{
$request = $this->storage->get(InteractionsStorageInterface::SERVER_DOMAIN, $id)->getRequest();
$this->requestBuilder->build($request, $table->getHash()[0]);
if ($file = $this->matchingRulesStorage->get(MatchingRulesStorageInterface::REQUEST_DOMAIN, $id)) {
$this->requestMatchingRuleBuilder->build($request, $file);
}
$this->server->register($id);
}
}
11 changes: 11 additions & 0 deletions compatibility-suite/tests/ServiceContainer/V2.php
@@ -0,0 +1,11 @@
<?php

namespace PhpPactTest\CompatibilitySuite\ServiceContainer;

class V2 extends V1
{
protected function getSpecification(): string
{
return '2.0.0';
}
}

0 comments on commit 556ec04

Please sign in to comment.