Skip to content

Commit

Permalink
Move endpoint from config to parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
tienvx committed May 12, 2023
1 parent e96453f commit cd49913
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 36 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,12 @@ $endpoint = 'test';

$config = (new StubServerConfig())
->setFiles($files)
->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"}]}
```
7 changes: 7 additions & 0 deletions UPGRADE-9.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ UPGRADE FROM 8.x to 9.0

$this->assertTrue($verifyResult);
```

* Stub Server
* Endpoint now can be set by:
```php
$service = new StubServerHttpService(new GuzzleClient(), $this->config);
$service->getJson($endpoint);
```
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public function __construct(ClientInterface $client, StubServerConfigInterface $
* {@inheritdoc}
* @throws \JsonException
*/
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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ interface StubServerHttpServiceInterface
/**
* Get the current state of the PACT JSON file and write it to disk.
*/
public function getJson(): string;
public function getJson(string $endpoint): string;
}
15 changes: 0 additions & 15 deletions src/PhpPact/Standalone/StubService/StubServerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class StubServerConfig implements StubServerConfigInterface
private bool $emptyProviderState = false;
private bool $insecureTls = false;

private string $endpoint;

public function getBrokerUrl(): ?UriInterface
{
return $this->brokerUrl;
Expand Down Expand Up @@ -256,17 +254,4 @@ public function getBaseUri(): UriInterface
{
return new Uri("http://localhost:{$this->getPort()}");
}


public function getEndpoint(): string
{
return $this->endpoint;
}

public function setEndpoint(string $endpoint): StubServerConfigInterface
{
$this->endpoint = $endpoint;

return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,4 @@ public function setProviderNames(array $providerNames): self;
public function getProviderNames(): array;

public function getBaseUri(): UriInterface;

public function getEndpoint(): string;

public function setEndpoint(string $endpoint): self;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ class StubServerHttpServiceTest extends TestCase
*/
protected function setUp(): void
{
$files = [__DIR__ . '/../../../../_resources/someconsumer-someprovider.json'];
$port = 7201;
$endpoint = 'test';
$files = [__DIR__ . '/../../../../_resources/someconsumer-someprovider.json'];
$port = 7201;

$this->config = (new StubServerConfig())
->setFiles($files)
->setPort($port)
->setEndpoint($endpoint);
->setPort($port);

$this->stubServer = new StubServer($this->config);
$this->stubServer->start();
Expand All @@ -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);
}
}
8 changes: 3 additions & 5 deletions tests/PhpPact/Standalone/StubServer/StubServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ class StubServerTest extends TestCase
public function testStartAndStop()
{
try {
$files = [__DIR__ . '/../../../_resources/someconsumer-someprovider.json'];
$port = 7201;
$endpoint= 'test';
$files = [__DIR__ . '/../../../_resources/someconsumer-someprovider.json'];
$port = 7201;

$subject = (new StubServerConfig())
->setFiles($files)
->setPort($port)
->setEndpoint($endpoint);
->setPort($port);

$stubServer = new StubServer($subject);
$pid = $stubServer->start();
Expand Down

0 comments on commit cd49913

Please sign in to comment.