UserTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * User: junade
  4. * Date: 01/02/2017
  5. * Time: 12:50
  6. */
  7. class UserTest extends TestCase
  8. {
  9. public function testGetUserDetails()
  10. {
  11. $response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserDetails.json');
  12. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  13. $mock->method('get')->willReturn($response);
  14. $user = new \Cloudflare\API\Endpoints\User($mock);
  15. $details = $user->getUserDetails();
  16. $this->assertObjectHasAttribute('id', $details);
  17. $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $details->id);
  18. $this->assertObjectHasAttribute('email', $details);
  19. $this->assertEquals('user@example.com', $details->email);
  20. $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
  21. }
  22. public function testGetUserID()
  23. {
  24. $response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserId.json');
  25. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  26. $mock->method('get')->willReturn($response);
  27. $user = new \Cloudflare\API\Endpoints\User($mock);
  28. $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getUserID());
  29. $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
  30. }
  31. public function testGetUserEmail()
  32. {
  33. $response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserEmail.json');
  34. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  35. $mock->method('get')->willReturn($response);
  36. $mock->expects($this->once())->method('get');
  37. $user = new \Cloudflare\API\Endpoints\User($mock);
  38. $this->assertEquals('user@example.com', $user->getUserEmail());
  39. $this->assertEquals('user@example.com', $user->getBody()->result->email);
  40. }
  41. public function testUpdateUserDetails()
  42. {
  43. $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateUserDetails.json');
  44. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  45. $mock->method('patch')->willReturn($response);
  46. $mock->expects($this->once())
  47. ->method('patch')
  48. ->with($this->equalTo('user'), $this->equalTo(['email' => 'user2@example.com']));
  49. $user = new \Cloudflare\API\Endpoints\User($mock);
  50. $user->updateUserDetails(['email' => 'user2@example.com']);
  51. $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
  52. }
  53. }