diff --git a/src/PhpPact/Consumer/Driver/Interaction/AbstractDriver.php b/src/PhpPact/Consumer/Driver/Interaction/AbstractDriver.php index 887e9c78..105e413b 100644 --- a/src/PhpPact/Consumer/Driver/Interaction/AbstractDriver.php +++ b/src/PhpPact/Consumer/Driver/Interaction/AbstractDriver.php @@ -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 ) { } diff --git a/src/PhpPact/Consumer/Driver/Interaction/InteractionDriver.php b/src/PhpPact/Consumer/Driver/Interaction/InteractionDriver.php index 6b4692de..66279746 100644 --- a/src/PhpPact/Consumer/Driver/Interaction/InteractionDriver.php +++ b/src/PhpPact/Consumer/Driver/Interaction/InteractionDriver.php @@ -11,12 +11,12 @@ 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 @@ -24,7 +24,7 @@ public function withBody(bool $isRequest, ?string $contentType = null, ?string $ 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(); } @@ -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); } } } @@ -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); } } } @@ -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); } } diff --git a/src/PhpPact/Consumer/Driver/Pact/PactDriver.php b/src/PhpPact/Consumer/Driver/Pact/PactDriver.php index 02197081..eda28ab6 100644 --- a/src/PhpPact/Consumer/Driver/Pact/PactDriver.php +++ b/src/PhpPact/Consumer/Driver/Pact/PactDriver.php @@ -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(); @@ -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(), @@ -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'); }, }; } @@ -75,7 +75,7 @@ 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; @@ -83,14 +83,14 @@ private function initWithLogLevel(): self 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; } diff --git a/src/PhpPact/Consumer/Factory/InteractionRegistryFactory.php b/src/PhpPact/Consumer/Factory/InteractionRegistryFactory.php index b7a9ccf5..bdf392f1 100644 --- a/src/PhpPact/Consumer/Factory/InteractionRegistryFactory.php +++ b/src/PhpPact/Consumer/Factory/InteractionRegistryFactory.php @@ -6,7 +6,7 @@ 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; @@ -14,10 +14,10 @@ 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); } diff --git a/src/PhpPact/Consumer/Service/MockServer.php b/src/PhpPact/Consumer/Service/MockServer.php index edbc5158..31378257 100644 --- a/src/PhpPact/Consumer/Service/MockServer.php +++ b/src/PhpPact/Consumer/Service/MockServer.php @@ -6,13 +6,13 @@ 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 ) { @@ -20,7 +20,7 @@ public function __construct( public function start(): void { - $port = $this->proxy->call( + $port = $this->client->call( 'pactffi_create_mock_server_for_transport', $this->pactDriver->getId(), $this->config->getHost(), @@ -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(), @@ -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(); } diff --git a/src/PhpPact/FFI/Proxy.php b/src/PhpPact/FFI/Client.php similarity index 94% rename from src/PhpPact/FFI/Proxy.php rename to src/PhpPact/FFI/Client.php index e36f1ba6..38b54a2b 100644 --- a/src/PhpPact/FFI/Proxy.php +++ b/src/PhpPact/FFI/Client.php @@ -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; diff --git a/src/PhpPact/FFI/ProxyInterface.php b/src/PhpPact/FFI/ClientInterface.php similarity index 88% rename from src/PhpPact/FFI/ProxyInterface.php rename to src/PhpPact/FFI/ClientInterface.php index 9f4a1a29..c0e767ff 100644 --- a/src/PhpPact/FFI/ProxyInterface.php +++ b/src/PhpPact/FFI/ClientInterface.php @@ -2,7 +2,7 @@ namespace PhpPact\FFI; -interface ProxyInterface +interface ClientInterface { /** * @param array $arguments