Skip to content

Commit

Permalink
fix(compatibility-suite): Fix conflict pact file name cause 500 error
Browse files Browse the repository at this point in the history
  • Loading branch information
tienvx committed Oct 20, 2024
1 parent 261a10e commit feb14cd
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 36 deletions.
4 changes: 2 additions & 2 deletions compatibility-suite/tests/Context/V3/Http/ConsumerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
final class ConsumerContext implements Context
{
private Interaction $interaction;
private int $id = 1;
private int $id = rand();
private PactPath $pactPath;

public function __construct(
private InteractionBuilderInterface $builder,
private PactWriterInterface $pactWriter,
private InteractionsStorageInterface $storage,
) {
$this->pactPath = new PactPath();
$this->pactPath = new PactPath("c-{$this->id}");
}

/**
Expand Down
12 changes: 5 additions & 7 deletions compatibility-suite/tests/Context/V3/Http/ProviderContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,25 @@

final class ProviderContext implements Context
{
private PactPath $pactPath;

public function __construct(
private PactWriterInterface $pactWriter,
private ProviderStateServerInterface $providerStateServer,
private ProviderVerifierInterface $providerVerifier,
) {
$this->pactPath = new PactPath();
}

/**
* @Given a Pact file for interaction :id is to be verified with the following provider states defined:
*/
public function aPactFileForInteractionIsToBeVerifiedWithTheFollowingProviderStatesDefined(int $id, TableNode $table): void
{
$this->pactWriter->write($id, $this->pactPath);
$pact = json_decode(file_get_contents($this->pactPath));
$pactPath = new PactPath("c-{$id}");
$this->pactWriter->write($id, $pactPath);
$pact = json_decode(file_get_contents($pactPath));
$rows = $table->getHash();
$pact->interactions[0]->providerStates = array_map(fn (array $row): array => ['name' => $row['State Name'], 'params' => json_decode($row['Parameters'] ?? '{}', true)], $rows);
file_put_contents($this->pactPath, json_encode($pact));
$this->providerVerifier->addSource($this->pactPath);
file_put_contents($pactPath, json_encode($pact));
$this->providerVerifier->addSource($pactPath);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

final class ProviderContext implements Context
{
private int $id = 1;
private int $id = rand();
private array $ids = [];
private PactPath $pactPath;

Expand All @@ -31,7 +31,7 @@ public function __construct(
private ParserInterface $parser,
private FixtureLoaderInterface $fixtureLoader
) {
$this->pactPath = new PactPath();
$this->pactPath = new PactPath("c-{$this->id}");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

final class RequestGeneratorsContext implements Context
{
private int $id = 1;
private int $id = rand();
private PactPath $pactPath;

public function __construct(
Expand All @@ -29,7 +29,7 @@ public function __construct(
private ProviderVerifierInterface $providerVerifier,
private BodyStorageInterface $bodyStorage,
) {
$this->pactPath = new PactPath();
$this->pactPath = new PactPath("c-{$this->id}");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class RequestMatchingContext implements Context
public const HEADER_TYPE = 'header';
public const BODY_TYPE = 'body';

private int $id = 1;
private int $id = rand();
private string $type;

public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

final class ResponseGeneratorsContext implements Context
{
private int $id = 1;
private int $id = rand();

public function __construct(
private InteractionBuilderInterface $builder,
Expand Down
4 changes: 2 additions & 2 deletions compatibility-suite/tests/Context/V4/CombinedContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

final class CombinedContext implements Context
{
private int $id = 1;
private int $id = rand();
private PactPath $pactPath;

public function __construct(
Expand All @@ -23,7 +23,7 @@ public function __construct(
private PactWriterInterface $pactWriter,
private MessagePactWriterInterface $messagePactWriter,
) {
$this->pactPath = new PactPath();
$this->pactPath = new PactPath("c-{$this->id}");
}

/**
Expand Down
4 changes: 2 additions & 2 deletions compatibility-suite/tests/Context/V4/Http/ConsumerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
final class ConsumerContext implements Context
{
private Interaction $interaction;
private int $id = 1;
private int $id = rand();
private PactPath $pactPath;

public function __construct(
private InteractionBuilderInterface $builder,
private PactWriterInterface $pactWriter,
private InteractionsStorageInterface $storage,
) {
$this->pactPath = new PactPath();
$this->pactPath = new PactPath("c-{$this->id}");
}

/**
Expand Down
21 changes: 10 additions & 11 deletions compatibility-suite/tests/Context/V4/Http/ProviderContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,23 @@

final class ProviderContext implements Context
{
private PactPath $pactPath;

public function __construct(
private PactWriterInterface $pactWriter,
private ProviderVerifierInterface $providerVerifier,
) {
$this->pactPath = new PactPath();
}

/**
* @Given a Pact file for interaction :id is to be verified, but is marked pending
*/
public function aPactFileForInteractionIsToBeVerifiedButIsMarkedPending(int $id): void
{
$this->pactWriter->write($id, $this->pactPath);
$pact = json_decode(file_get_contents($this->pactPath), true);
$pactPath = new PactPath("c-{$id}");
$this->pactWriter->write($id, $pactPath);
$pact = json_decode(file_get_contents($pactPath), true);
$pact['interactions'][0]['pending'] = true;
file_put_contents($this->pactPath, json_encode($pact));
$this->providerVerifier->addSource($this->pactPath);
file_put_contents($pactPath, json_encode($pact));
$this->providerVerifier->addSource($pactPath);
}

/**
Expand Down Expand Up @@ -85,11 +83,12 @@ public function aPactFileForInteractionIsToBeVerifiedWithTheFollowingComments(in
break;
}
}
$this->pactWriter->write($id, $this->pactPath);
$pact = json_decode(file_get_contents($this->pactPath), true);
$pactPath = new PactPath("c-{$id}");
$this->pactWriter->write($id, $pactPath);
$pact = json_decode(file_get_contents($pactPath), true);
$pact['interactions'][0]['comments'] = $comments;
file_put_contents($this->pactPath, json_encode($pact));
$this->providerVerifier->addSource($this->pactPath);
file_put_contents($pactPath, json_encode($pact));
$this->providerVerifier->addSource($pactPath);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace PhpPactTest\CompatibilitySuite\Context\V4\Message;

use Behat\Behat\Context\Context;
use Behat\Behat\Tester\Exception\PendingException;
use PhpPact\Consumer\Model\Message;
use PhpPactTest\CompatibilitySuite\Model\PactPath;
use PhpPactTest\CompatibilitySuite\Service\MessagePactWriterInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

final class ProviderContext implements Context
{
private int $id = 1;
private int $id = rand();
private PactPath $pactPath;

public function __construct(
Expand All @@ -29,7 +29,7 @@ public function __construct(
private ProviderVerifierInterface $providerVerifier,
private ParserInterface $parser,
) {
$this->pactPath = new PactPath();
$this->pactPath = new PactPath("c-{$this->id}");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

final class ResponseGeneratorsContext implements Context
{
private int $id = 1;
private int $id = rand();

public function __construct(
private InteractionBuilderInterface $builder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

final class ResponseMatchingContext implements Context
{
private int $id = 1;
private int $id = rand();

public function __construct(
private InteractionBuilderInterface $builder,
Expand All @@ -43,7 +43,7 @@ public function anExpectedResponseConfiguredWithTheFollowing(TableNode $table):
$this->storage->add(InteractionsStorageInterface::SERVER_DOMAIN, $this->id, $interaction);
$this->storage->add(InteractionsStorageInterface::PACT_WRITER_DOMAIN, $this->id, $interaction);
$this->responseMatchingRuleBuilder->build($interaction->getResponse(), $row['matching rules']);
$pactPath = new PactPath();
$pactPath = new PactPath("c-{$this->id}");
$this->pactWriter->write($this->id, $pactPath);
$this->providerVerifier->addSource($pactPath);
}
Expand Down

0 comments on commit feb14cd

Please sign in to comment.