-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(compatibility-suite): Implement V4 scenarios
- Loading branch information
Showing
22 changed files
with
1,267 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
compatibility-suite/tests/Context/V4/BodyGeneratorsContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
/** | ||
* @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
87
compatibility-suite/tests/Context/V4/Http/ConsumerContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.