Skip to content

Commit

Permalink
feat: Get mock server's mismatches
Browse files Browse the repository at this point in the history
  • Loading branch information
tienvx committed Oct 16, 2023
1 parent a6f616c commit 2bd81ef
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/PhpPact/Consumer/Driver/Interaction/InteractionDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ public function registerInteraction(Interaction $interaction): bool

return true;
}

public function getMismatches(): array

Check failure on line 33 in src/PhpPact/Consumer/Driver/Interaction/InteractionDriver.php

View workflow job for this annotation

GitHub Actions / php-cs (8.2)

Method PhpPact\Consumer\Driver\Interaction\InteractionDriver::getMismatches() return type has no value type specified in iterable type array.
{
return $this->mockServer->getMismatches();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ interface InteractionDriverInterface
public function registerInteraction(Interaction $interaction): bool;

public function verifyInteractions(): bool;

public function getMismatches(): array;

Check failure on line 13 in src/PhpPact/Consumer/Driver/Interaction/InteractionDriverInterface.php

View workflow job for this annotation

GitHub Actions / php-cs (8.2)

Method PhpPact\Consumer\Driver\Interaction\InteractionDriverInterface::getMismatches() return type has no value type specified in iterable type array.
}
28 changes: 25 additions & 3 deletions src/PhpPact/Consumer/Service/MockServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PhpPact\Consumer\Service;

use FFI;
use PhpPact\Config\PactConfigInterface;
use PhpPact\Consumer\Exception\MockServerNotStartedException;
use PhpPact\Consumer\Exception\MockServerNotWrotePactFileException;
Expand All @@ -11,6 +12,8 @@

class MockServer implements MockServerInterface
{
private array $mismatches = [];

Check failure on line 15 in src/PhpPact/Consumer/Service/MockServer.php

View workflow job for this annotation

GitHub Actions / php-cs (8.2)

Property PhpPact\Consumer\Service\MockServer::$mismatches type has no value type specified in iterable type array.

public function __construct(
private ClientInterface $client,
private PactRegistryInterface $pactRegistry,
Expand All @@ -37,17 +40,25 @@ public function start(): void

public function verify(): bool
{
$matched = $this->client->call('pactffi_mock_server_matched', $this->config->getPort());

try {
$matched = $this->isMatched();

if ($matched) {
$this->writePact();
$this->mismatches = [];
} else {
$this->storeMismatches();
}
} finally {
$this->cleanUp();
}

return $matched;
return $matched ?? false;

Check failure on line 56 in src/PhpPact/Consumer/Service/MockServer.php

View workflow job for this annotation

GitHub Actions / php-cs (8.2)

Variable $matched on left side of ?? always exists and is not nullable.
}

public function getMismatches(): array

Check failure on line 59 in src/PhpPact/Consumer/Service/MockServer.php

View workflow job for this annotation

GitHub Actions / php-cs (8.2)

Method PhpPact\Consumer\Service\MockServer::getMismatches() return type has no value type specified in iterable type array.
{
return $this->mismatches;
}

protected function getTransport(): string
Expand Down Expand Up @@ -78,4 +89,15 @@ private function cleanUp(): void
$this->client->call('pactffi_cleanup_mock_server', $this->config->getPort());
$this->pactRegistry->deletePact();
}

private function isMatched(): bool
{
return $this->client->call('pactffi_mock_server_matched', $this->config->getPort());
}

private function storeMismatches(): void
{
$cData = $this->client->call('pactffi_mock_server_mismatches', $this->config->getPort());
$this->mismatches = json_decode(FFI::string($cData), true);
}
}
2 changes: 2 additions & 0 deletions src/PhpPact/Consumer/Service/MockServerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ interface MockServerInterface
public function start(): void;

public function verify(): bool;

public function getMismatches(): array;

Check failure on line 11 in src/PhpPact/Consumer/Service/MockServerInterface.php

View workflow job for this annotation

GitHub Actions / php-cs (8.2)

Method PhpPact\Consumer\Service\MockServerInterface::getMismatches() return type has no value type specified in iterable type array.
}

0 comments on commit 2bd81ef

Please sign in to comment.