Skip to content
Open
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
10 changes: 10 additions & 0 deletions src/Endpoints/Accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ public function listAccounts(
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}

public function deleteAccount(string $account_id): \stdClass
{
$identifier = $account_id;

$user = $this->adapter->delete('accounts/' . $identifier);
$this->body = json_decode($user->getBody());

return (object)['result' => $this->body->result];
}
Comment on lines +57 to +65
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function deleteAccount(string $account_id): \stdClass
{
$identifier = $account_id;
$user = $this->adapter->delete('accounts/' . $identifier);
$this->body = json_decode($user->getBody());
return (object)['result' => $this->body->result];
}
public function deleteAccount(string $account_id): \stdClass
{
$user = $this->adapter->delete('accounts/' . $account_id);
$this->body = json_decode($user->getBody());
return (object)['result' => $this->body->result];
}


public function getDomains(string $accountID): array
{
$response = $this->adapter->get('accounts/' . $accountID . '/registrar/domains');
Expand Down
21 changes: 19 additions & 2 deletions tests/Endpoints/AccountsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public function testListZones()
->with(
$this->equalTo('accounts'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'page' => 1,
'per_page' => 20,
'direction' => 'desc',
])
);
Expand Down Expand Up @@ -83,4 +83,21 @@ public function testAddAccountWithCustomType()
$accounts->addAccount('Foo Bar', 'enterprise');
$this->assertEquals('2bab6ace8c72ed3f09b9eca6db1396bb', $accounts->getBody()->result->id);
}

public function testDeleteAccount()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteAccount.json');

$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('accounts/91b86b19a774dab78915108354eef39b')
);

$account = new Accounts($mock);
$result = $account->deleteAccount('91b86b19a774dab78915108354eef39b');
$this->assertEquals('91b86b19a774dab78915108354eef39b', $result->result->id);
}
}
8 changes: 8 additions & 0 deletions tests/Fixtures/Endpoints/deleteAccount.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"result": {
"id": "91b86b19a774dab78915108354eef39b"
},
"success": true,
"errors": [],
"messages": []
}