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 V4 scenarios #432

Merged
merged 1 commit into from
Dec 24, 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 @@ -54,3 +54,19 @@ jobs:

- name: Run Behat
run: vendor/bin/behat compatibility-suite/pact-compatibility-suite/features/V3 --name '/^((?!Kafka|binary body \(negative|Message provider).)*$/'
v4:
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/V4
8 changes: 8 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ imports:
- 'compatibility-suite/suites/v3/message/provider.yml'
- 'compatibility-suite/suites/v3/generators.yml'
- 'compatibility-suite/suites/v3/matching-rules.yml'
- 'compatibility-suite/suites/v4/http/consumer.yml'
- 'compatibility-suite/suites/v4/http/provider.yml'
- 'compatibility-suite/suites/v4/message/consumer.yml'
- 'compatibility-suite/suites/v4/message/provider.yml'
- 'compatibility-suite/suites/v4/combined.yml'
- 'compatibility-suite/suites/v4/sync-message/consumer.yml'
- 'compatibility-suite/suites/v4/matching-rules.yml'
- 'compatibility-suite/suites/v4/generators.yml'
14 changes: 14 additions & 0 deletions compatibility-suite/suites/v4/combined.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
default:
suites:
v4_combined:
paths: [ '%paths.base%/compatibility-suite/pact-compatibility-suite/features/V4/v4.feature' ]

contexts:
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Hook\SetUpContext'
- 'PhpPactTest\CompatibilitySuite\Context\V4\CombinedContext':
- '@interaction_builder'
- '@interactions_storage'
- '@pact_writer'
- '@message_pact_writer'

services: PhpPactTest\CompatibilitySuite\ServiceContainer\V4
28 changes: 28 additions & 0 deletions compatibility-suite/suites/v4/generators.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
default:
suites:
v4_generators:
paths: [ '%paths.base%/compatibility-suite/pact-compatibility-suite/features/V4/generators.feature' ]

contexts:
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Hook\SetUpContext'
- 'PhpPactTest\CompatibilitySuite\Context\V3\BodyGeneratorsContext':
- '@body_validator'
- 'PhpPactTest\CompatibilitySuite\Context\V3\RequestGeneratorsContext':
- '@interaction_builder'
- '@request_generator_builder'
- '@interactions_storage'
- '@pact_writer'
- '@generator_server'
- '@provider_verifier'
- '@body_storage'
- 'PhpPactTest\CompatibilitySuite\Context\V4\BodyGeneratorsContext':
- '@body_validator'
- 'PhpPactTest\CompatibilitySuite\Context\V4\ResponseGeneratorsContext':
- '@interaction_builder'
- '@response_generator_builder'
- '@interactions_storage'
- '@server'
- '@client'
- '@body_storage'

services: PhpPactTest\CompatibilitySuite\ServiceContainer\V4
13 changes: 13 additions & 0 deletions compatibility-suite/suites/v4/http/consumer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
default:
suites:
v4_http_consumer:
paths: [ '%paths.base%/compatibility-suite/pact-compatibility-suite/features/V4/http_consumer.feature' ]

contexts:
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Hook\SetUpContext'
- 'PhpPactTest\CompatibilitySuite\Context\V4\Http\ConsumerContext':
- '@interaction_builder'
- '@pact_writer'
- '@interactions_storage'

services: PhpPactTest\CompatibilitySuite\ServiceContainer\V4
31 changes: 31 additions & 0 deletions compatibility-suite/suites/v4/http/provider.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
default:
suites:
v4_http_provider:
paths: [ '%paths.base%/compatibility-suite/pact-compatibility-suite/features/V4/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\ProviderContext':
- '@server'
- '@provider_verifier'
- '@provider_state_server'
- 'PhpPactTest\CompatibilitySuite\Context\V1\Http\ProviderContext':
- '@server'
- '@pact_writer'
- '@pact_broker'
- '@response_builder'
- '@interactions_storage'
- '@provider_verifier'
- 'PhpPactTest\CompatibilitySuite\Context\V4\Http\ProviderContext':
- '@pact_writer'
- '@provider_verifier'

services: PhpPactTest\CompatibilitySuite\ServiceContainer\V4
23 changes: 23 additions & 0 deletions compatibility-suite/suites/v4/matching-rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
default:
suites:
v4_matching_rules:
paths: [ '%paths.base%/compatibility-suite/pact-compatibility-suite/features/V4/matching_rules.feature' ]

contexts:
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Hook\SetUpContext'
- 'PhpPactTest\CompatibilitySuite\Context\V3\RequestMatchingContext':
- '@interaction_builder'
- '@server'
- '@client'
- '@interactions_storage'
- '@request_builder'
- '@request_matching_rule_builder'
- 'PhpPactTest\CompatibilitySuite\Context\V4\ResponseMatchingContext':
- '@interaction_builder'
- '@interactions_storage'
- '@response_matching_rule_builder'
- '@server'
- '@pact_writer'
- '@provider_verifier'

services: PhpPactTest\CompatibilitySuite\ServiceContainer\V4
14 changes: 14 additions & 0 deletions compatibility-suite/suites/v4/message/consumer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
default:
suites:
v4_message_consumer:
paths: [ '%paths.base%/compatibility-suite/pact-compatibility-suite/features/V4' ]

contexts:
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Hook\SetUpContext'
- 'PhpPactTest\CompatibilitySuite\Context\V4\Message\ConsumerContext':
- '@message_pact_writer'

filters:
tags: "@consumer&&@message"

services: PhpPactTest\CompatibilitySuite\ServiceContainer\V4
18 changes: 18 additions & 0 deletions compatibility-suite/suites/v4/message/provider.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
default:
suites:
v4_message_provider:
paths: [ '%paths.base%/compatibility-suite/pact-compatibility-suite/features/V4' ]

contexts:
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Hook\SetUpContext'
- 'PhpPactTest\CompatibilitySuite\Context\V4\Message\ProviderContext':
- '@server'
- '@interaction_builder'
- '@interactions_storage'
- '@message_pact_writer'
- '@provider_verifier'

filters:
tags: "@provider&&@message"

services: PhpPactTest\CompatibilitySuite\ServiceContainer\V4
14 changes: 14 additions & 0 deletions compatibility-suite/suites/v4/sync-message/consumer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
default:
suites:
v4_sync_message_consumer:
paths: [ '%paths.base%/compatibility-suite/pact-compatibility-suite/features/V4' ]

contexts:
- 'PhpPactTest\CompatibilitySuite\Context\Shared\Hook\SetUpContext'
- 'PhpPactTest\CompatibilitySuite\Context\V4\SyncMessage\ConsumerContext':
- '@sync_message_pact_writer'

filters:
tags: "@SynchronousMessage&&@message"

services: PhpPactTest\CompatibilitySuite\ServiceContainer\V4
22 changes: 22 additions & 0 deletions compatibility-suite/tests/Context/V4/BodyGeneratorsContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace PhpPactTest\CompatibilitySuite\Context\V4;

use Behat\Behat\Context\Context;
use PhpPactTest\CompatibilitySuite\Service\BodyValidatorInterface;

final class BodyGeneratorsContext implements Context
{
public function __construct(
private BodyValidatorInterface $validator,
) {
}

/**
* @Then the body value for :path will have been replaced with :value
*/
public function theBodyValueForWillHaveBeenReplacedWith(string $path, string $value): void
{
$this->validator->validateValue($path, $value);
}
}
64 changes: 64 additions & 0 deletions compatibility-suite/tests/Context/V4/CombinedContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace PhpPactTest\CompatibilitySuite\Context\V4;

use Behat\Behat\Context\Context;
use PhpPact\Config\PactConfigInterface;
use PhpPact\Consumer\Model\Interaction;
use PhpPactTest\CompatibilitySuite\Service\InteractionBuilderInterface;
use PhpPactTest\CompatibilitySuite\Service\InteractionsStorageInterface;
use PhpPactTest\CompatibilitySuite\Service\MessagePactWriterInterface;
use PhpPactTest\CompatibilitySuite\Service\PactWriterInterface;
use PHPUnit\Framework\Assert;

final class CombinedContext implements Context
{
private int $id = 1;

public function __construct(
private InteractionBuilderInterface $builder,
private InteractionsStorageInterface $storage,
private PactWriterInterface $pactWriter,
private MessagePactWriterInterface $messagePactWriter,
) {
}

/**
* @Given an HTTP interaction is being defined for a consumer test
*/
public function anHttpInteractionIsBeingDefinedForAConsumerTest(): void
{
$interaction = $this->builder->build([
'description' => 'http interaction',
'method' => 'GET',
'path' => '/v4-features',
]);
$this->storage->add(InteractionsStorageInterface::PACT_WRITER_DOMAIN, $this->id, $interaction);
}

/**
* @Given a message interaction is being defined for a consumer test
*/
public function aMessageInteractionIsBeingDefinedForAConsumerTest(): void
{
}

/**
* @When the Pact file for the test is generated
*/
public function thePactFileForTheTestIsGenerated(): void
{
$this->pactWriter->write($this->id, 'c', 'p', PactConfigInterface::MODE_MERGE);
$this->messagePactWriter->write('message interaction', '', 'c', 'p', PactConfigInterface::MODE_MERGE);
tienvx marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @Then there will be an interaction in the Pact file with a type of :type
*/
public function thereWillBeAnInteractionInThePactFileWithATypeOf(string $type): void
{
$pact = json_decode(file_get_contents($this->pactWriter->getPactPath()), true);
$types = array_map(fn (array $interaction) => $interaction['type'], $pact['interactions']);
Assert::assertContains($type, $types);
}
}
87 changes: 87 additions & 0 deletions compatibility-suite/tests/Context/V4/Http/ConsumerContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace PhpPactTest\CompatibilitySuite\Context\V4\Http;

use Behat\Behat\Context\Context;
use Behat\Behat\Tester\Exception\PendingException;
use PhpPact\Consumer\Model\Interaction;
use PhpPactTest\CompatibilitySuite\Service\InteractionBuilderInterface;
use PhpPactTest\CompatibilitySuite\Service\InteractionsStorageInterface;
use PhpPactTest\CompatibilitySuite\Service\PactWriterInterface;
use PHPUnit\Framework\Assert;

final class ConsumerContext implements Context
{
private Interaction $interaction;
private int $id = 1;

public function __construct(
private InteractionBuilderInterface $builder,
private PactWriterInterface $pactWriter,
private InteractionsStorageInterface $storage,
) {
}

/**
* @Given an HTTP interaction is being defined for a consumer test
*/
public function anHttpInteractionIsBeingDefinedForAConsumerTest(): void
{
$this->interaction = $this->builder->build([
'description' => 'interaction for a consumer test',
'method' => 'GET',
'path' => '/v4-features',
]);
$this->storage->add(InteractionsStorageInterface::PACT_WRITER_DOMAIN, $this->id, $this->interaction);
}

/**
* @Then the first interaction in the Pact file will have a type of :type
*/
public function theFirstInteractionInThePactFileWillHaveATypeOf(string $type): void
{
$pact = json_decode(file_get_contents($this->pactWriter->getPactPath()), true);
Assert::assertSame($type, $pact['interactions'][0]['type']);
}

/**
* @Given a key of :key is specified for the HTTP interaction
*/
public function aKeyOfIsSpecifiedForTheHttpInteraction(string $key): void
{
throw new PendingException("Can't set interaction's key using FFI call");
}

/**
* @Then the first interaction in the Pact file will have :name = :value
*/
public function theFirstInteractionInThePactFileWillHave(string $name, string $value): void
{
$pact = json_decode(file_get_contents($this->pactWriter->getPactPath()), true);
Assert::assertSame($value, $pact['interactions'][0][$name]);
}

/**
* @Given the HTTP interaction is marked as pending
*/
public function theHttpInteractionIsMarkedAsPending(): void
{
throw new PendingException("Can't set interaction's pending using FFI call");
}

/**
* @Given a comment :value is added to the HTTP interaction
*/
public function aCommentIsAddedToTheHttpInteraction(string $value): void
{
throw new PendingException("Can't set interaction's comment using FFI call");
}

/**
* @When the Pact file for the test is generated
*/
public function thePactFileForTheTestIsGenerated(): void
{
$this->pactWriter->write($this->id);
}
}
Loading