Skip to content

Commit

Permalink
Rename FFI Proxy to Client
Browse files Browse the repository at this point in the history
  • Loading branch information
tienvx committed May 8, 2023
1 parent dfaa021 commit 693daad
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/PhpPact/Consumer/Driver/Interaction/AbstractDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace PhpPact\Consumer\Driver\Interaction;

use PhpPact\Consumer\Driver\Pact\PactDriverInterface;
use PhpPact\FFI\ProxyInterface;
use PhpPact\FFI\ClientInterface;

abstract class AbstractDriver implements DriverInterface
{
protected int $id;

public function __construct(
protected ProxyInterface $proxy,
protected ClientInterface $client,
protected PactDriverInterface $pactDriver
) {
}
Expand Down
20 changes: 10 additions & 10 deletions src/PhpPact/Consumer/Driver/Interaction/InteractionDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ class InteractionDriver extends AbstractDriver implements InteractionDriverInter

public function newInteraction(string $description): void
{
$this->id = $this->proxy->call('pactffi_new_interaction', $this->pactDriver->getId(), $description);
$this->id = $this->client->call('pactffi_new_interaction', $this->pactDriver->getId(), $description);
}

public function uponReceiving(string $description): void
{
$this->proxy->call('pactffi_upon_receiving', $this->id, $description);
$this->client->call('pactffi_upon_receiving', $this->id, $description);
}

public function withBody(bool $isRequest, ?string $contentType = null, ?string $body = null): void
{
if (is_null($body)) {
return;
}
$success = $this->proxy->call('pactffi_with_body', $this->id, $this->getPart($isRequest), $contentType, $body);
$success = $this->client->call('pactffi_with_body', $this->id, $this->getPart($isRequest), $contentType, $body);
if (!$success) {
throw new InteractionBodyNotAddedException();
}
Expand All @@ -33,9 +33,9 @@ public function withBody(bool $isRequest, ?string $contentType = null, ?string $
public function given(array $providerStates): void
{
foreach ($providerStates as $providerState) {
$this->proxy->call('pactffi_given', $this->id, $providerState->getName());
$this->client->call('pactffi_given', $this->id, $providerState->getName());
foreach ($providerState->getParams() as $key => $value) {
$this->proxy->call('pactffi_given_with_param', $this->id, $providerState->getName(), (string) $key, (string) $value);
$this->client->call('pactffi_given_with_param', $this->id, $providerState->getName(), (string) $key, (string) $value);
}
}
}
Expand All @@ -44,7 +44,7 @@ public function withHeaders(bool $isRequest, array $headers): void
{
foreach ($headers as $header => $values) {
foreach (array_values($values) as $index => $value) {
$this->proxy->call('pactffi_with_header_v2', $this->id, $this->getPart($isRequest), (string) $header, (int) $index, (string) $value);
$this->client->call('pactffi_with_header_v2', $this->id, $this->getPart($isRequest), (string) $header, (int) $index, (string) $value);
}
}
}
Expand All @@ -53,23 +53,23 @@ public function withQueryParameters(array $queryParams): void
{
foreach ($queryParams as $key => $values) {
foreach (array_values($values) as $index => $value) {
$this->proxy->call('pactffi_with_query_parameter_v2', $this->id, (string) $key, (int) $index, (string) $value);
$this->client->call('pactffi_with_query_parameter_v2', $this->id, (string) $key, (int) $index, (string) $value);
}
}
}

public function withRequest(string $method, string $path): void
{
$this->proxy->call('pactffi_with_request', $this->id, $method, $path);
$this->client->call('pactffi_with_request', $this->id, $method, $path);
}

public function withResponse(int $status): void
{
$this->proxy->call('pactffi_response_status', $this->id, $status);
$this->client->call('pactffi_response_status', $this->id, $status);
}

private function getPart(bool $isRequest): int
{
return $this->proxy->get($isRequest ? self::REQUEST : self::RESPONSE);
return $this->client->get($isRequest ? self::REQUEST : self::RESPONSE);
}
}
26 changes: 13 additions & 13 deletions src/PhpPact/Consumer/Driver/Pact/PactDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
use Composer\Semver\Comparator;
use PhpPact\Config\PactConfigInterface;
use PhpPact\Consumer\Exception\PactFileNotWroteException;
use PhpPact\FFI\ProxyInterface;
use PhpPact\FFI\ClientInterface;

class PactDriver implements PactDriverInterface
{
protected int $id;

public function __construct(
private ProxyInterface $proxy,
private ClientInterface $client,
private PactConfigInterface $config
) {
$this->setUp();
Expand All @@ -25,13 +25,13 @@ public function getId(): int

public function cleanUp(): void
{
$this->proxy->call('pactffi_free_pact_handle', $this->id);
$this->client->call('pactffi_free_pact_handle', $this->id);
unset($this->id);
}

public function writePact(): void
{
$error = $this->proxy->call(
$error = $this->client->call(
'pactffi_pact_handle_write_file',
$this->id,
$this->config->getPactDir(),
Expand All @@ -53,15 +53,15 @@ protected function setUp(): void
protected function getSpecification(): int
{
return match (true) {
$this->versionEqualTo('1.0.0') => $this->proxy->get('PactSpecification_V1'),
$this->versionEqualTo('1.1.0') => $this->proxy->get('PactSpecification_V1_1'),
$this->versionEqualTo('2.0.0') => $this->proxy->get('PactSpecification_V2'),
$this->versionEqualTo('3.0.0') => $this->proxy->get('PactSpecification_V3'),
$this->versionEqualTo('4.0.0') => $this->proxy->get('PactSpecification_V4'),
$this->versionEqualTo('1.0.0') => $this->client->get('PactSpecification_V1'),
$this->versionEqualTo('1.1.0') => $this->client->get('PactSpecification_V1_1'),
$this->versionEqualTo('2.0.0') => $this->client->get('PactSpecification_V2'),
$this->versionEqualTo('3.0.0') => $this->client->get('PactSpecification_V3'),
$this->versionEqualTo('4.0.0') => $this->client->get('PactSpecification_V4'),
default => function () {
trigger_error(sprintf("Specification version '%s' is unknown", $this->config->getPactSpecificationVersion()), E_USER_WARNING);

return $this->proxy->get('PactSpecification_Unknown');
return $this->client->get('PactSpecification_Unknown');
},
};
}
Expand All @@ -75,22 +75,22 @@ private function initWithLogLevel(): self
{
$logLevel = $this->config->getLogLevel();
if ($logLevel) {
$this->proxy->call('pactffi_init_with_log_level', $logLevel);
$this->client->call('pactffi_init_with_log_level', $logLevel);
}

return $this;
}

private function newPact(): self
{
$this->id = $this->proxy->call('pactffi_new_pact', $this->config->getConsumer(), $this->config->getProvider());
$this->id = $this->client->call('pactffi_new_pact', $this->config->getConsumer(), $this->config->getProvider());

return $this;
}

private function withSpecification(): self
{
$this->proxy->call('pactffi_with_specification', $this->id, $this->getSpecification());
$this->client->call('pactffi_with_specification', $this->id, $this->getSpecification());

return $this;
}
Expand Down
10 changes: 5 additions & 5 deletions src/PhpPact/Consumer/Factory/InteractionRegistryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
use PhpPact\Consumer\Driver\Pact\PactDriver;
use PhpPact\Consumer\Service\InteractionRegistry;
use PhpPact\Consumer\Service\InteractionRegistryInterface;
use PhpPact\FFI\Proxy;
use PhpPact\FFI\Client;
use PhpPact\Standalone\MockService\MockServerConfigInterface;
use PhpPact\Consumer\Service\MockServer;

class InteractionRegistryFactory
{
public static function create(MockServerConfigInterface $config): InteractionRegistryInterface
{
$proxy = new Proxy();
$pactDriver = new PactDriver($proxy, $config);
$interactionDriver = new InteractionDriver($proxy, $pactDriver);
$mockServer = new MockServer($proxy, $pactDriver, $config);
$client = new Client();
$pactDriver = new PactDriver($client, $config);
$interactionDriver = new InteractionDriver($client, $pactDriver);
$mockServer = new MockServer($client, $pactDriver, $config);

return new InteractionRegistry($interactionDriver, $mockServer);
}
Expand Down
12 changes: 6 additions & 6 deletions src/PhpPact/Consumer/Service/MockServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
use PhpPact\Consumer\Driver\Pact\PactDriverInterface;
use PhpPact\Consumer\Exception\MockServerNotStartedException;
use PhpPact\Consumer\Exception\MockServerNotWrotePactFileException;
use PhpPact\FFI\ProxyInterface;
use PhpPact\FFI\ClientInterface;
use PhpPact\Standalone\MockService\MockServerConfigInterface;

class MockServer implements MockServerInterface
{
public function __construct(
private ProxyInterface $proxy,
private ClientInterface $client,
private PactDriverInterface $pactDriver,
private MockServerConfigInterface $config
) {
}

public function start(): void
{
$port = $this->proxy->call(
$port = $this->client->call(
'pactffi_create_mock_server_for_transport',
$this->pactDriver->getId(),
$this->config->getHost(),
Expand All @@ -37,12 +37,12 @@ public function start(): void

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

public function writePact(): void
{
$error = $this->proxy->call(
$error = $this->client->call(
'pactffi_write_pact_file',
$this->config->getPort(),
$this->config->getPactDir(),
Expand All @@ -55,7 +55,7 @@ public function writePact(): void

public function cleanUp(): void
{
$this->proxy->call('pactffi_cleanup_mock_server', $this->config->getPort());
$this->client->call('pactffi_cleanup_mock_server', $this->config->getPort());
$this->pactDriver->cleanUp();
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpPact/FFI/Proxy.php → src/PhpPact/FFI/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use PhpPact\FFI\Exception\HeaderNotReadException;
use PhpPact\Standalone\Installer\Model\Scripts;

class Proxy implements ProxyInterface
class Client implements ClientInterface
{
private FFI $ffi;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PhpPact\FFI;

interface ProxyInterface
interface ClientInterface
{
/**
* @param array<int, mixed> $arguments
Expand Down

0 comments on commit 693daad

Please sign in to comment.