Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added filters support for stub #270

Merged
merged 3 commits into from
Sep 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Added `Recurly_AccountAcquisition` [#259](https://github.com/recurly/recurly-client-php/pull/259)
* Added support for automated exports [#260](https://github.com/recurly/recurly-client-php/pull/260)
* Added support for shipping addresses [#269](https://github.com/recurly/recurly-client-php/pull/269)
* Added filters to `Recurly_Stub` allowing `$account->invoices->get(array('state' => 'past_due'))` (thanks to [developer-devPHP](https://github.com/developer-devPHP)) [#270](https://github.com/recurly/recurly-client-php/pull/270)

## Version 2.6.0 (August 9th, 2016)

Expand Down
35 changes: 35 additions & 0 deletions Tests/Recurly/Recurly_Stub_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

class Recurly_StubTest extends Recurly_TestCase {

public function testConstructor() {
$href = 'http://example.com/';
$stub = new Recurly_Stub('foo', $href, $this->client);

$this->assertEquals($href, $stub->getHref());
}

public function testGet() {
$url = 'https://api.recurly.com/v2/accounts/abcdef1234567890/invoices';
$this->client->addResponse('GET', $url, 'invoices/index-200.xml');

$stub = new Recurly_Stub('foo', $url, $this->client);
$obj = $stub->get();

$this->assertInstanceOf('Recurly_InvoiceList', $obj);
$this->assertEquals($url, $obj->getHref());
}

public function testGetParams() {
$base_url = 'https://api.recurly.com/v2/accounts/abcdef1234567890/invoices';
$filtered_url = "{$base_url}?state=open";
$this->client->addResponse('GET', $filtered_url, 'invoices/index-200.xml');

$stub = new Recurly_Stub('foo', $base_url, $this->client);
$obj = $stub->get(array('state' => 'open'));

$this->assertInstanceOf('Recurly_InvoiceList', $obj);
$this->assertEquals($filtered_url, $obj->getHref());
}

}
11 changes: 6 additions & 5 deletions lib/recurly/stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ function __construct($objectType, $href, $client = null)
/**
* Retrieve the stubbed resource.
*/
function get() {
$stub = self::_get($this->_href, $this->_client);
if ($this->_href && !$stub->getHref()) {
$stub->setHref($this->_href);
function get($params = null) {
$uri = self::_uriWithParams($this->_href, $params);
$object = self::_get($uri, $this->_client);
if ($this->_href && !$object->getHref()) {
$object->setHref($this->_href);
}
return $stub;
return $object;
}

public function __toString()
Expand Down