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 Mar 21, 2023
1 parent 0546c98 commit 6ab0327
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 45 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]}
```
3 changes: 3 additions & 0 deletions UPGRADE-9.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ UPGRADE FROM 8.x to 9.0

$this->assertTrue($verifier->verify());
```

* Stub Server
* `$endpoint` has been moved from `StubServerConfig` to `StubServerHttpService::getJson`
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ interface StubServerHttpServiceInterface
*
* @return string
*/
public function getJson(): string;
public function getJson(string $endpoint): string;
}
20 changes: 0 additions & 20 deletions src/PhpPact/Standalone/StubService/StubServerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class StubServerConfig implements StubServerConfigInterface
private bool $emptyProviderState = false;
private bool $insecureTls = false;

private string $endpoint;

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -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;
}
}
12 changes: 0 additions & 12 deletions src/PhpPact/Standalone/StubService/StubServerConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
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);
}
}
4 changes: 1 addition & 3 deletions tests/PhpPact/Standalone/StubServer/StubServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6ab0327

Please sign in to comment.