Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(compatibility-suite): Implement V2 scenarios #430

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/compatibility-suite.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace PhpPactTest\CompatibilitySuite\ServiceContainer;

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