Skip to content

Commit 97ff494

Browse files
authored
Merge pull request #4 from shadiakiki1986/master
allow to skip parameter to get
2 parents 4bb269f + 9e48bd5 commit 97ff494

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

specs/Endpoint/abstract-wp-endpoint.spec.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@
1919
$data = $endpoint->get(55);
2020
expect($data)->to->equal(['foo' => 'bar']);
2121
});
22+
23+
it('should make a GET request without any ID', function () {
24+
$client = $this->getProphet()->prophesize(WpClient::class);
25+
26+
$request = new Request('GET', '/foo');
27+
$response = new \GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], '{"foo": "bar"}');
28+
29+
$client->send($request)->willReturn($response)->shouldBeCalled();
30+
31+
$endpoint = new FakeEndpoint($client->reveal());
32+
33+
$data = $endpoint->get();
34+
expect($data)->to->equal(['foo' => 'bar']);
35+
});
36+
2237
});
2338

2439
describe('save()', function () {

src/Endpoint/AbstractWpEndpoint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ abstract protected function getEndpoint();
3232
* @param int $id
3333
* @return array
3434
*/
35-
public function get($id)
35+
public function get($id = null)
3636
{
37-
$request = new Request('GET', $this->getEndpoint() . '/' . $id);
37+
$request = new Request('GET', $this->getEndpoint() . (is_null($id)?'': '/' . $id));
3838
$response = $this->client->send($request);
3939

4040
if ($response->hasHeader('Content-Type')

0 commit comments

Comments
 (0)