Skip to content

Commit 556ec04

Browse files
authored
Merge pull request #430 from tienvx/v2-http-consumer-provider
test(compatibility-suite): Implement V2 scenarios
2 parents c07b72a + 6b21ab1 commit 556ec04

File tree

6 files changed

+124
-0
lines changed

6 files changed

+124
-0
lines changed

.github/workflows/compatibility-suite.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,19 @@ jobs:
2222

2323
- name: Run Behat
2424
run: vendor/bin/behat compatibility-suite/pact-compatibility-suite/features/V1
25+
v2:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v3
29+
with:
30+
submodules: recursive
31+
32+
- uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: 8.2
35+
coverage: none
36+
37+
- uses: ramsey/composer-install@v2
38+
39+
- name: Run Behat
40+
run: vendor/bin/behat compatibility-suite/pact-compatibility-suite/features/V2

behat.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
imports:
22
- 'compatibility-suite/suites/v1/http/consumer.yml'
33
- 'compatibility-suite/suites/v1/http/provider.yml'
4+
- 'compatibility-suite/suites/v2/http/consumer.yml'
5+
- 'compatibility-suite/suites/v2/http/provider.yml'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
default:
2+
suites:
3+
v2_http_consumer:
4+
paths: [ '%paths.base%/compatibility-suite/pact-compatibility-suite/features/V2/http_consumer.feature' ]
5+
6+
contexts:
7+
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Hook\SetUpContext'
8+
- 'PhpPactTest\CompatibilitySuite\Context\Shared\InteractionsContext':
9+
- '@interactions_storage'
10+
- '@request_matching_rule_builder'
11+
- '@response_matching_rule_builder'
12+
- '@matching_rules_storage'
13+
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Transform\InteractionsContext':
14+
- '@interaction_builder'
15+
- '@matching_rules_storage'
16+
- 'PhpPactTest\CompatibilitySuite\Context\V1\Http\ConsumerContext':
17+
- '@server'
18+
- '@request_builder'
19+
- '@client'
20+
- '@interactions_storage'
21+
- '@fixture_loader'
22+
- 'PhpPactTest\CompatibilitySuite\Context\V2\Http\ConsumerContext':
23+
- '@server'
24+
- '@request_builder'
25+
- '@request_matching_rule_builder'
26+
- '@matching_rules_storage'
27+
- '@interactions_storage'
28+
29+
services: PhpPactTest\CompatibilitySuite\ServiceContainer\V2
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
default:
2+
suites:
3+
v2_http_provider:
4+
paths: [ '%paths.base%/compatibility-suite/pact-compatibility-suite/features/V2/http_provider.feature' ]
5+
6+
contexts:
7+
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Hook\SetUpContext'
8+
- 'PhpPactTest\CompatibilitySuite\Context\Shared\InteractionsContext':
9+
- '@interactions_storage'
10+
- '@request_matching_rule_builder'
11+
- '@response_matching_rule_builder'
12+
- '@matching_rules_storage'
13+
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Transform\InteractionsContext':
14+
- '@interaction_builder'
15+
- '@matching_rules_storage'
16+
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Hook\ProviderStateContext':
17+
- '@provider_state_server'
18+
- 'PhpPactTest\CompatibilitySuite\Context\Shared\ProviderContext':
19+
- '@server'
20+
- '@provider_verifier'
21+
- '@provider_state_server'
22+
- 'PhpPactTest\CompatibilitySuite\Context\V1\Http\ProviderContext':
23+
- '@server'
24+
- '@pact_writer'
25+
- '@pact_broker'
26+
- '@response_builder'
27+
- '@interactions_storage'
28+
- '@provider_verifier'
29+
30+
services: PhpPactTest\CompatibilitySuite\ServiceContainer\V2
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace PhpPactTest\CompatibilitySuite\ServiceContainer;
4+
5+
class V2 extends V1
6+
{
7+
protected function getSpecification(): string
8+
{
9+
return '2.0.0';
10+
}
11+
}

0 commit comments

Comments
 (0)