123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- /**
- * User: junade
- * Date: 01/02/2017
- * Time: 12:50
- */
- class UserTest extends TestCase
- {
- public function testGetUserDetails()
- {
- $response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserDetails.json');
- $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
- $mock->method('get')->willReturn($response);
- $user = new \Cloudflare\API\Endpoints\User($mock);
- $details = $user->getUserDetails();
- $this->assertObjectHasAttribute('id', $details);
- $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $details->id);
- $this->assertObjectHasAttribute('email', $details);
- $this->assertEquals('user@example.com', $details->email);
- $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
- }
- public function testGetUserID()
- {
- $response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserId.json');
- $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
- $mock->method('get')->willReturn($response);
- $user = new \Cloudflare\API\Endpoints\User($mock);
- $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getUserID());
- $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
- }
- public function testGetUserEmail()
- {
- $response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserEmail.json');
- $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
- $mock->method('get')->willReturn($response);
- $mock->expects($this->once())->method('get');
- $user = new \Cloudflare\API\Endpoints\User($mock);
- $this->assertEquals('user@example.com', $user->getUserEmail());
- $this->assertEquals('user@example.com', $user->getBody()->result->email);
- }
- public function testUpdateUserDetails()
- {
- $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateUserDetails.json');
- $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
- $mock->method('patch')->willReturn($response);
- $mock->expects($this->once())
- ->method('patch')
- ->with($this->equalTo('user'), $this->equalTo(['email' => 'user2@example.com']));
- $user = new \Cloudflare\API\Endpoints\User($mock);
- $user->updateUserDetails(['email' => 'user2@example.com']);
- $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
- }
- }
|