From 8550854116afc761daabd8df0c63b908fd44ea8a Mon Sep 17 00:00:00 2001 From: Nuno Rafael Rocha Date: Thu, 1 Sep 2016 11:58:39 +0100 Subject: [PATCH] Update card.getAddresses method to retrieve from API --- lib/Uphold/Model/Card.php | 37 ++++++----------------- lib/Uphold/Model/CardInterface.php | 14 ++++----- test/Uphold/Tests/Unit/Model/CardTest.php | 23 +++++++++++--- 3 files changed, 34 insertions(+), 40 deletions(-) diff --git a/lib/Uphold/Model/Card.php b/lib/Uphold/Model/Card.php index 19182e9..103ac7f 100644 --- a/lib/Uphold/Model/Card.php +++ b/lib/Uphold/Model/Card.php @@ -25,13 +25,6 @@ class Card extends BaseModel implements CardInterface */ protected $address; - /** - * List of card addresses. - * - * @var array - */ - protected $addresses; - /** * Available amount. * @@ -95,14 +88,6 @@ public function getAddress() return $this->address; } - /** - * {@inheritdoc} - */ - public function getAddresses() - { - return $this->addresses; - } - /** * {@inheritdoc} */ @@ -159,6 +144,14 @@ public function getSettings() return $this->settings; } + /** + * {@inheritdoc} + */ + public function getAddresses() + { + return $this->client->get(sprintf('/me/cards/%s/addresses', $this->id))->getContent(); + } + /** * {@inheritdoc} */ @@ -175,9 +168,7 @@ public function getTransactions() */ public function createCryptoAddress($network) { - $response = $this->client->post(sprintf('/me/cards/%s/addresses', $this->id), array('network' => $network)); - - $this->addAddress($response->getContent()); + $this->client->post(sprintf('/me/cards/%s/addresses', $this->id), array('network' => $network)); return $this; } @@ -214,14 +205,4 @@ public function update(array $data) return $this; } - - /** - * {@inheritdoc} - */ - private function addAddress($address) - { - $this->addresses[] = $address; - - return $this; - } } diff --git a/lib/Uphold/Model/CardInterface.php b/lib/Uphold/Model/CardInterface.php index 7a36a6e..198dbdf 100644 --- a/lib/Uphold/Model/CardInterface.php +++ b/lib/Uphold/Model/CardInterface.php @@ -14,13 +14,6 @@ interface CardInterface */ public function getAddress(); - /** - * Gets list of card addresses. - * - * @return $addresses - */ - public function getAddresses(); - /** * Checks if the card is currently available. * @@ -70,6 +63,13 @@ public function getLastTransactionAt(); */ public function getSettings(); + /** + * Gets list of card addresses. + * + * @return array + */ + public function getAddresses(); + /** * Gets the transactions associated with the card identified by the user. * diff --git a/test/Uphold/Tests/Unit/Model/CardTest.php b/test/Uphold/Tests/Unit/Model/CardTest.php index d7d440b..78755a2 100644 --- a/test/Uphold/Tests/Unit/Model/CardTest.php +++ b/test/Uphold/Tests/Unit/Model/CardTest.php @@ -177,13 +177,28 @@ public function shouldReturnSettings() */ public function shouldReturnAddresses() { - $data = array('addresses' => array(array('id' => '1GpBtJXXa1NdG94cYPGZTc3DfRY2P7EwzH', 'network' => 'bitcoin'))); + $cardData = array('id' => 'ade869d8-7913-4f67-bb4d-72719f0a2be0'); + $data = array(array( + 'id' => 'a97bb994-6e24-4a89-b653-e0a6d0bcf634', + 'status' => 'bitcoin', + ), array( + 'id' => 'b97bb994-6e24-4a89-b653-e0a6d0bcf635', + 'status' => 'foobar', + )); + $response = $this->getResponseMock($data); $client = $this->getUpholdClientMock(); - $card = new Card($client, $data); + $client + ->expects($this->once()) + ->method('get') + ->with(sprintf('/me/cards/%s/addresses', $cardData['id'])) + ->will($this->returnValue($response)) + ; + + $card = new Card($client, $cardData); - $this->assertEquals($data['addresses'], $card->getAddresses()); + $this->assertEquals($data, $card->getAddresses()); } /** @@ -253,8 +268,6 @@ public function shouldCreateNewCryptoAddress() $card = new Card($client, $cardData); $card->createCryptoAddress('foobar'); - - $this->assertEquals($card->getAddresses(), array($data)); } /**