Skip to content

Commit

Permalink
Merge pull request #4 from shadiakiki1986/master
Browse files Browse the repository at this point in the history
allow to skip parameter to get
  • Loading branch information
mrkrstphr authored Nov 9, 2016
2 parents 4bb269f + 9e48bd5 commit 97ff494
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions specs/Endpoint/abstract-wp-endpoint.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@
$data = $endpoint->get(55);
expect($data)->to->equal(['foo' => 'bar']);
});

it('should make a GET request without any ID', function () {
$client = $this->getProphet()->prophesize(WpClient::class);

$request = new Request('GET', '/foo');
$response = new \GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], '{"foo": "bar"}');

$client->send($request)->willReturn($response)->shouldBeCalled();

$endpoint = new FakeEndpoint($client->reveal());

$data = $endpoint->get();
expect($data)->to->equal(['foo' => 'bar']);
});

});

describe('save()', function () {
Expand Down
4 changes: 2 additions & 2 deletions src/Endpoint/AbstractWpEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ abstract protected function getEndpoint();
* @param int $id
* @return array
*/
public function get($id)
public function get($id = null)
{
$request = new Request('GET', $this->getEndpoint() . '/' . $id);
$request = new Request('GET', $this->getEndpoint() . (is_null($id)?'': '/' . $id));
$response = $this->client->send($request);

if ($response->hasHeader('Content-Type')
Expand Down

0 comments on commit 97ff494

Please sign in to comment.