AccountMembersTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. use Cloudflare\API\Adapter\Adapter;
  3. use Cloudflare\API\Endpoints\AccountMembers;
  4. class AccountMembersTest extends TestCase
  5. {
  6. public function testAddAccountMember()
  7. {
  8. $response = $this->getPsr7JsonResponseForFixture('Endpoints/createAccountMember.json');
  9. $mock = $this->getMockBuilder(Adapter::class)->getMock();
  10. $mock->method('post')->willReturn($response);
  11. $mock->expects($this->once())
  12. ->method('post')
  13. ->with(
  14. $this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/members'),
  15. $this->equalTo([
  16. 'email' => 'user@example.com',
  17. 'roles' => [
  18. '3536bcfad5faccb999b47003c79917fb',
  19. ],
  20. ])
  21. );
  22. $accountMembers = new AccountMembers($mock);
  23. $accountMembers->addAccountMember('01a7362d577a6c3019a474fd6f485823', 'user@example.com', ['3536bcfad5faccb999b47003c79917fb']);
  24. $this->assertEquals('4536bcfad5faccb111b47003c79917fa', $accountMembers->getBody()->result->id);
  25. }
  26. public function testListAccountMembers()
  27. {
  28. $response = $this->getPsr7JsonResponseForFixture('Endpoints/listAccountMembers.json');
  29. $mock = $this->getMockBuilder(Adapter::class)->getMock();
  30. $mock->method('get')->willReturn($response);
  31. $mock->expects($this->once())
  32. ->method('get')
  33. ->with(
  34. $this->equalTo('accounts/023e105f4ecef8ad9ca31a8372d0c353/members'),
  35. $this->equalTo([
  36. 'page' => 1,
  37. 'per_page' => 20,
  38. ])
  39. );
  40. $accountMembers = new AccountMembers($mock);
  41. $result = $accountMembers->listAccountMembers('023e105f4ecef8ad9ca31a8372d0c353', 1, 20);
  42. $this->assertObjectHasAttribute('result', $result);
  43. $this->assertEquals('4536bcfad5faccb111b47003c79917fa', $result->result[0]->id);
  44. $this->assertEquals(1, $result->result_info->count);
  45. $this->assertEquals('4536bcfad5faccb111b47003c79917fa', $accountMembers->getBody()->result[0]->id);
  46. }
  47. }