From 4f23e8d1e7fd0470eaffc10c6da7124d48f403e0 Mon Sep 17 00:00:00 2001 From: tienvx Date: Mon, 6 Mar 2023 16:26:26 +0700 Subject: [PATCH] Move endpoint from config to parameter --- README.md | 5 ++--- .../Service/StubServerHttpService.php | 4 ++-- .../StubServerHttpServiceInterface.php | 2 +- .../StubService/StubServerConfig.php | 20 ------------------- .../StubService/StubServerConfigInterface.php | 12 ----------- .../Service/StubServerHttpServiceTest.php | 7 +++---- .../Standalone/StubServer/StubServerTest.php | 4 +--- 7 files changed, 9 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 9db9fc453..dd2d2012d 100644 --- a/README.md +++ b/README.md @@ -390,13 +390,12 @@ $endpoint = 'test'; $config = (new StubServerConfig()) ->setFiles($pactLocation) - ->setPort($port) - ->setEndpoint($endpoint); + ->setPort($port); $stubServer = new StubServer($config); $stubServer->start(); $service = new StubServerHttpService(new GuzzleClient(), $config); -echo $service->getJson(); // output: {"results":[{"name":"Games"}]} +echo $service->getJson($endpoint); // output: {"results":[{"name":"Games"}]} ``` diff --git a/src/PhpPact/Standalone/StubService/Service/StubServerHttpService.php b/src/PhpPact/Standalone/StubService/Service/StubServerHttpService.php index 592e6e181..d11db3654 100644 --- a/src/PhpPact/Standalone/StubService/Service/StubServerHttpService.php +++ b/src/PhpPact/Standalone/StubService/Service/StubServerHttpService.php @@ -38,9 +38,9 @@ public function __construct(ClientInterface $client, StubServerConfigInterface $ /** * {@inheritdoc} */ - public function getJson(): string + public function getJson(string $endpoint): string { - $uri = $this->config->getBaseUri()->withPath('/' . $this->config->getEndpoint()); + $uri = $this->config->getBaseUri()->withPath('/' . $endpoint); $response = $this->client->get($uri, [ 'headers' => [ 'Content-Type' => 'application/json', diff --git a/src/PhpPact/Standalone/StubService/Service/StubServerHttpServiceInterface.php b/src/PhpPact/Standalone/StubService/Service/StubServerHttpServiceInterface.php index f0ba6b54f..ea2c6a2dc 100644 --- a/src/PhpPact/Standalone/StubService/Service/StubServerHttpServiceInterface.php +++ b/src/PhpPact/Standalone/StubService/Service/StubServerHttpServiceInterface.php @@ -12,5 +12,5 @@ interface StubServerHttpServiceInterface * * @return string */ - public function getJson(): string; + public function getJson(string $endpoint): string; } diff --git a/src/PhpPact/Standalone/StubService/StubServerConfig.php b/src/PhpPact/Standalone/StubService/StubServerConfig.php index 0d54cc57d..c114514c2 100644 --- a/src/PhpPact/Standalone/StubService/StubServerConfig.php +++ b/src/PhpPact/Standalone/StubService/StubServerConfig.php @@ -32,8 +32,6 @@ class StubServerConfig implements StubServerConfigInterface private bool $emptyProviderState = false; private bool $insecureTls = false; - private string $endpoint; - /** * {@inheritdoc} */ @@ -347,22 +345,4 @@ public function getBaseUri(): UriInterface { return new Uri("http://localhost:{$this->getPort()}"); } - - /** - * {@inheritdoc} - */ - public function getEndpoint(): string - { - return $this->endpoint; - } - - /** - * {@inheritdoc} - */ - public function setEndpoint(string $endpoint): StubServerConfigInterface - { - $this->endpoint = $endpoint; - - return $this; - } } diff --git a/src/PhpPact/Standalone/StubService/StubServerConfigInterface.php b/src/PhpPact/Standalone/StubService/StubServerConfigInterface.php index dd2848fa8..48f703e4f 100644 --- a/src/PhpPact/Standalone/StubService/StubServerConfigInterface.php +++ b/src/PhpPact/Standalone/StubService/StubServerConfigInterface.php @@ -220,16 +220,4 @@ public function getProviderNames(): array; * @return UriInterface */ public function getBaseUri(): UriInterface; - - /** - * @return string - */ - public function getEndpoint(): string; - - /** - * @param string $endpoint - * - * @return StubServerConfigInterface - */ - public function setEndpoint(string $endpoint): self; } diff --git a/tests/PhpPact/Standalone/StubServer/Service/StubServerHttpServiceTest.php b/tests/PhpPact/Standalone/StubServer/Service/StubServerHttpServiceTest.php index 0bd0dd9ca..65cf13549 100644 --- a/tests/PhpPact/Standalone/StubServer/Service/StubServerHttpServiceTest.php +++ b/tests/PhpPact/Standalone/StubServer/Service/StubServerHttpServiceTest.php @@ -30,12 +30,10 @@ protected function setUp(): void { $pactLocation = __DIR__ . '/../../../../_resources/someconsumer-someprovider.json'; $port = 7201; - $endpoint = 'test'; $this->config = (new StubServerConfig()) ->setFiles($pactLocation) - ->setPort($port) - ->setEndpoint($endpoint); + ->setPort($port); $this->stubServer = new StubServer($this->config); $this->stubServer->start(); @@ -49,7 +47,8 @@ protected function tearDown(): void public function testGetJson() { - $result = $this->service->getJson(); + $endpoint = 'test'; + $result = $this->service->getJson($endpoint); $this->assertEquals('{"results":[{"name":"Games"}]}', $result); } } diff --git a/tests/PhpPact/Standalone/StubServer/StubServerTest.php b/tests/PhpPact/Standalone/StubServer/StubServerTest.php index 3fb609fa0..910ac717d 100644 --- a/tests/PhpPact/Standalone/StubServer/StubServerTest.php +++ b/tests/PhpPact/Standalone/StubServer/StubServerTest.php @@ -16,12 +16,10 @@ public function testStartAndStop() try { $pactLocation = __DIR__ . '/../../../_resources/someconsumer-someprovider.json'; $port = 7201; - $endpoint = 'test'; $subject = (new StubServerConfig()) ->setFiles($pactLocation) - ->setPort($port) - ->setEndpoint($endpoint); + ->setPort($port); $stubServer = new StubServer($subject); $pid = $stubServer->start();