Skip to content

Commit 0ed0d14

Browse files
committed
updates
1 parent ea07545 commit 0ed0d14

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

spec/PingSpec.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,36 @@ class PingSpec extends ObjectBehavior
1818
public function it_should_perform_start(ClientInterface $httpClient, ResponseInterface $response)
1919
{
2020
$httpClient->sendRequest(new TypeToken(RequestInterface::class))->shouldBeCalled()->willReturn($response);
21-
$this->beConstructedWith('none', 'https://foo.dev', null, $httpClient);
21+
$this->beConstructedWith('none', 'https://foo.dev', $httpClient);
2222
$this->start();
2323
}
2424

2525
public function it_should_perform_success(ClientInterface $httpClient, ResponseInterface $response)
2626
{
2727
$httpClient->sendRequest(new TypeToken(RequestInterface::class))->shouldBeCalled()->willReturn($response);
28-
$this->beConstructedWith('none', 'https://foo.dev', null, $httpClient);
28+
$this->beConstructedWith('none', 'https://foo.dev', $httpClient);
2929
$this->success();
3030
}
3131

3232
public function it_should_perform_fail(ClientInterface $httpClient, ResponseInterface $response)
3333
{
3434
$httpClient->sendRequest(new TypeToken(RequestInterface::class))->shouldBeCalled()->willReturn($response);
35-
$this->beConstructedWith('none', 'https://foo.dev', null, $httpClient);
35+
$this->beConstructedWith('none', 'https://foo.dev', $httpClient);
3636
$this->fail();
3737
}
3838

39-
public function it_should_change_uuid(ClientInterface $httpClient, ResponseInterface $response)
39+
public function it_should_change_uuid()
4040
{
41+
$this->beConstructedWith('none', 'https://foo.dev');
4142
$this->withUuid('test')->shouldReturnAnInstanceOf(Ping::class);
4243
}
4344

45+
public function it_should_change_http_client(ClientInterface $httpClient)
46+
{
47+
$this->beConstructedWith('none', 'https://foo.dev');
48+
$this->withHttpClient($httpClient)->shouldReturnAnInstanceOf(Ping::class);
49+
}
50+
4451
public function it_should_handle_HTTP_BAD_REQUEST(ClientInterface $httpClient, ResponseInterface $response, ClientExceptionInterface $error)
4552
{
4653
$httpClient->sendRequest(new TypeToken(RequestInterface::class))->shouldBeCalled()
@@ -58,7 +65,7 @@ public function getResponse(): ResponseInterface
5865
})
5966
;
6067
$response->getStatusCode()->shouldBeCalled()->willReturn(400);
61-
$this->beConstructedWith('none', 'https://foo.dev', null, $httpClient);
68+
$this->beConstructedWith('none', 'https://foo.dev', $httpClient);
6269
$this->shouldThrow(Exceptions\InvalidPayloadError::class)->duringStart();
6370
}
6471

@@ -79,7 +86,7 @@ public function getResponse(): ResponseInterface
7986
})
8087
;
8188
$response->getStatusCode()->shouldBeCalled()->willReturn(401);
82-
$this->beConstructedWith('none', 'https://foo.dev', null, $httpClient);
89+
$this->beConstructedWith('none', 'https://foo.dev', $httpClient);
8390
$this->shouldThrow(Exceptions\UnauthorisedError::class)->duringStart();
8491
}
8592

@@ -100,7 +107,7 @@ public function getResponse(): ResponseInterface
100107
})
101108
;
102109
$response->getStatusCode()->shouldBeCalled()->willReturn(403);
103-
$this->beConstructedWith('none', 'https://foo.dev', null, $httpClient);
110+
$this->beConstructedWith('none', 'https://foo.dev', $httpClient);
104111
$this->shouldThrow(Exceptions\AccountLimitReached::class)->duringStart();
105112
}
106113

@@ -121,7 +128,7 @@ public function getResponse(): ResponseInterface
121128
})
122129
;
123130
$response->getStatusCode()->shouldBeCalled()->willReturn(404);
124-
$this->beConstructedWith('none', 'https://foo.dev', null, $httpClient);
131+
$this->beConstructedWith('none', 'https://foo.dev', $httpClient);
125132
$this->shouldThrow(Exceptions\UuidNotFound::class)->duringStart();
126133
}
127134

@@ -142,7 +149,7 @@ public function getResponse(): ResponseInterface
142149
})
143150
;
144151
$response->getStatusCode()->shouldBeCalled()->willReturn(500);
145-
$this->beConstructedWith('none', 'https://foo.dev', null, $httpClient);
152+
$this->beConstructedWith('none', 'https://foo.dev', $httpClient);
146153
$this->shouldThrow(Exceptions\FailureError::class)->duringStart();
147154
}
148155

@@ -152,7 +159,7 @@ public function it_should_handle_Generic_HTTP_5xx(ClientInterface $httpClient, C
152159
->willThrow(new class('test') extends \Exception implements ClientExceptionInterface {
153160
})
154161
;
155-
$this->beConstructedWith('none', 'https://foo.dev', null, $httpClient);
162+
$this->beConstructedWith('none', 'https://foo.dev', $httpClient);
156163
$this->shouldThrow(Exceptions\FailureError::class)->duringStart();
157164
}
158165
}

src/Ping.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,31 @@ class Ping
1515

1616
protected string $uuid;
1717

18-
protected string $url = 'https://hc-ping.com';
18+
protected string $url;
1919

2020
protected RequestBuilder $requestBuilder;
2121

2222
final public function __construct(
2323
string $uuid,
24+
string $url = 'https://hc-ping.com',
2425
?ClientInterface $httpClient = null,
2526
?RequestBuilder $requestBuilder = null
2627
) {
2728
$this->uuid = $uuid;
29+
$this->url = $url;
2830
$factory = new Psr17Factory();
2931
$this->httpClient = $httpClient ?? new HttpClient($factory, $factory);
3032
$this->requestBuilder = $requestBuilder ?? new RequestBuilder($factory, $factory);
3133
}
3234

3335
public function withUuid(string $uuid): self
3436
{
35-
return new self($uuid, $this->httpClient, $this->requestBuilder);
37+
return new self($uuid, $this->url, $this->httpClient, $this->requestBuilder);
3638
}
3739

3840
public function withHttpClient(ClientInterface $httpClient): self
3941
{
40-
return new self($this->uuid, $httpClient, $this->requestBuilder);
42+
return new self($this->uuid, $this->url, $httpClient, $this->requestBuilder);
4143
}
4244

4345
protected function ping(string $action = ''): bool

0 commit comments

Comments
 (0)