diff --git a/examples/partner-account-create.php b/examples/partner-account-create.php index 9f10f188..898962ea 100644 --- a/examples/partner-account-create.php +++ b/examples/partner-account-create.php @@ -6,7 +6,6 @@ $account = new \MessageBird\Objects\PartnerAccount\Account(); $account->name = 'Name Test'; -$account->email = 'testSDK@messagebird.com'; try { $partnerAccountResult = $messageBird->partnerAccounts->create($account); diff --git a/examples/partner-account-update.php b/examples/partner-account-update.php new file mode 100644 index 00000000..072d2aa8 --- /dev/null +++ b/examples/partner-account-update.php @@ -0,0 +1,20 @@ +name = 'Name Test'; + +try { + $partnerAccountResult = $messageBird->partnerAccounts->update($account, 1); + var_dump($partnerAccountResult); + +} catch (\MessageBird\Exceptions\AuthenticateException $e) { + // That means that your accessKey is unknown + echo 'wrong login'; + +} catch (\Exception $e) { + echo $e->getMessage(); +} diff --git a/src/MessageBird/Objects/PartnerAccount/Account.php b/src/MessageBird/Objects/PartnerAccount/Account.php index d4be3b4f..1182f2cf 100644 --- a/src/MessageBird/Objects/PartnerAccount/Account.php +++ b/src/MessageBird/Objects/PartnerAccount/Account.php @@ -20,7 +20,6 @@ public function loadToJson() { return json_encode([ 'name' => $this->name, - 'email' => $this->email, ]); } diff --git a/src/MessageBird/Resources/PartnerAccount/Accounts.php b/src/MessageBird/Resources/PartnerAccount/Accounts.php index 62bc76da..44145473 100644 --- a/src/MessageBird/Resources/PartnerAccount/Accounts.php +++ b/src/MessageBird/Resources/PartnerAccount/Accounts.php @@ -20,17 +20,13 @@ public function __construct(HttpClient $httpClient) public function create($object, $query = null) { - - list($status, , $body) = $this->HttpClient->performHttpRequest( + list(, , $body) = $this->HttpClient->performHttpRequest( HttpClient::REQUEST_POST, self::RESOURCE_NAME, null, $object->loadToJson() ); - var_dump($status); - var_dump($body); - return $this->processRequest($body); } @@ -55,4 +51,16 @@ public function getList($parameters = []) return $response; } + + public function update($object, $id) + { + list(, , $body) = $this->HttpClient->performHttpRequest( + HttpClient::REQUEST_PATCH, + sprintf('%s/%s', self::RESOURCE_NAME, $id), + null, + $object->loadToJson() + ); + + return $this->processRequest($body); + } } diff --git a/tests/integration/partneraccount/AccountTest.php b/tests/integration/partneraccount/AccountTest.php index 81fd6df5..1b9a5f7f 100644 --- a/tests/integration/partneraccount/AccountTest.php +++ b/tests/integration/partneraccount/AccountTest.php @@ -12,7 +12,6 @@ public function testCreateSubAccount() { $account = new \MessageBird\Objects\PartnerAccount\Account(); $account->name = 'MessageBird'; - $account->email = 'test@messagebird.com'; $this->mockClient ->expects($this->atLeastOnce()) @@ -45,7 +44,7 @@ public function testCreateSubAccount() 'POST', 'child-accounts', null, - '{"name":"MessageBird","email":"test@messagebird.com"}' + '{"name":"MessageBird"}' ); $response = $this->client->partnerAccounts->create($account); @@ -131,23 +130,46 @@ public function testReadSubAccount() public function testDeleteSubAccount() { $this->mockClient - ->expects($this->atLeastOnce()) + ->expects($this->once()) ->method('performHttpRequest') + ->with( + 'DELETE', + 'child-accounts/1' + ) ->willReturn([ 204, '', '' ]); + + $response = $this->client->partnerAccounts->delete(1); + + $this->assertTrue($response); + } + + public function testEditSubAccount() + { + $account = new \MessageBird\Objects\PartnerAccount\Account(); + $account->name = 'MessageBird'; + $this->mockClient ->expects($this->once()) ->method('performHttpRequest') ->with( - 'DELETE', - 'child-accounts/1' - ); - - $response = $this->client->partnerAccounts->delete(1); + 'PATCH', + 'child-accounts/1', + null, + '{"name":"MessageBird"}' + ) + ->willReturn([ + 204, + '', + '{ + "id": 6249799, + "name": "Partner Account Sub 1" + }' + ]); - $this->assertTrue($response); + $this->client->partnerAccounts->update($account,1); } }