From 4d4c14b6d7485cc0ef9c748e01b503f123eccdc9 Mon Sep 17 00:00:00 2001 From: Neuman Date: Mon, 7 Mar 2011 09:40:40 -0800 Subject: [PATCH] Reload internal object with response on update --- Services/Twilio/InstanceResource.php | 4 +++- tests/TwilioTest.php | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Services/Twilio/InstanceResource.php b/Services/Twilio/InstanceResource.php index 03ce5ef..4370b0f 100644 --- a/Services/Twilio/InstanceResource.php +++ b/Services/Twilio/InstanceResource.php @@ -14,7 +14,9 @@ public function update($params, $value = NULL) { if (!is_array($params)) { $params = array($params => $value); } - $this->proxy->createData($this->sid, $params); + $object = $this->proxy->createData($this->sid, $params); + $this->_load($object); + return $this; } public function setObject($object) { $this->_load($object); diff --git a/tests/TwilioTest.php b/tests/TwilioTest.php index ce59250..43b6f7a 100644 --- a/tests/TwilioTest.php +++ b/tests/TwilioTest.php @@ -255,6 +255,24 @@ function testUnmute() { } } + function testResourcePropertiesReflectUpdates() { + $http = m::mock(); + $http->shouldReceive('get')->once() + ->with('/2010-04-01/Accounts/AC123.json') + ->andReturn(array(200, array('Content-Type' => 'application/json'), + json_encode(array('friendly_name' => 'foo')) + )); + $http->shouldReceive('post')->once() + ->with('/2010-04-01/Accounts/AC123.json', m::any(), m::any()) + ->andReturn(array(200, array('Content-Type' => 'application/json'), + json_encode(array('friendly_name' => 'bar')) + )); + $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); + $this->assertEquals('foo', $client->account->friendly_name); + $client->account->update('FriendlyName', 'bar'); + $this->assertEquals('bar', $client->account->friendly_name); + } + //function testAccessingNonExistentPropertiesErrorsOut }