Skip to content

Commit

Permalink
Pass the client from pager to its items
Browse files Browse the repository at this point in the history
Fixes #254
  • Loading branch information
drewish committed Aug 10, 2016
1 parent d184253 commit 4281d70
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Recurly PHP Client Library CHANGELOG

## (Unreleased)

* Fix for client not being passed from `Recurly_Pager` to its items (thanks to [cyruscollier](https://github.com/cyruscollier)) [#265](https://github.com/recurly/recurly-client-php/pull/265)

## Version 2.6.0 (August 9th, 2016)

* Upgraded to API V2.3: https://dev.recurly.com/v2.3/docs
Expand Down
30 changes: 23 additions & 7 deletions Tests/Recurly/Base_Test.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
<?php


class Recurly_BaseTest extends Recurly_TestCase {
// Do a song and dance to gain access to private/protected properties.
function getProtectedProperty($obj, $property) {
$reflection = new ReflectionClass($obj);
$property = $reflection->getProperty($property);
$property->setAccessible(true);
return $property->getValue($obj);
}

class Recurly_BaseTest extends Recurly_TestCase {
public function testParsingEmptyXML() {
$this->client->addResponse('GET', 'abcdef1234567890', 'accounts/empty.xml');

$account = Recurly_Base::_get('abcdef1234567890', $this->client);
$this->assertNull($account);
}

public function testPassingClientToPagerItems() {
$this->client->addResponse('GET', 'subscriptions', 'subscriptions/index-200.xml');

$subscriptions = Recurly_Base::_get('subscriptions', $this->client);
$this->assertInstanceOf('Recurly_SubscriptionList', $subscriptions);
$this->assertEquals(getProtectedProperty($subscriptions, '_client'), $this->client);

$subscription = $subscriptions->current();
$this->assertInstanceOf('Recurly_Subscription', $subscription);
$this->assertEquals(getProtectedProperty($subscription, '_client'), $this->client);
}

public function testPassingClientToStub() {
$this->client->addResponse('GET', 'abcdef1234567890', 'adjustments/show-200.xml');

$adjustment = Recurly_Base::_get('abcdef1234567890', $this->client);
$this->assertInstanceOf('Recurly_Adjustment', $adjustment);
$this->assertInstanceOf('Recurly_Stub', $adjustment->invoice);

// The client is protected so we do a little song and dance to access it:
$reflection = new \ReflectionClass($adjustment->invoice);
$property = $reflection->getProperty('_client');
$property->setAccessible(true);
$this->assertEquals($property->getValue($adjustment->invoice), $this->client);
$invoice = $adjustment->invoice;
$this->assertInstanceOf('Recurly_Stub', $invoice);
$this->assertEquals(getProtectedProperty($invoice, '_client'), $this->client);
}
}
1 change: 1 addition & 0 deletions lib/recurly/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ protected static function __parseXmlToObject($node, &$object)

if ($object instanceof Recurly_Pager) {
$new_obj = Recurly_Resource::__createNodeObject($node);
$new_obj->_client = $object->_client;
if (!is_null($new_obj)) {
Recurly_Resource::__parseXmlToObject($node->firstChild, $new_obj);
$object->_objects[] = $new_obj;
Expand Down

0 comments on commit 4281d70

Please sign in to comment.