Files
cloudflare-php/tests/Endpoints/UserTest.php
Anthony Sterling fbb5aac074 Moved JSON API Responses to test fixtures
This PR moves the JSON API responses used in the tests to fixture files
within the tests folder. This allows reuse and the ability to lint/validate
these fixtures if required - although not covered in this PR.

I've added TestCase::getPsr7StreamForFixture and TestCase::getPsr7JsonResponseForFixture
to reduce code duplication and enable some assertions around the expected fixures/responses.

Thanks,
2017-09-24 15:24:33 +01:00

65 lines
2.2 KiB
PHP

<?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);
}
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());
}
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());
}
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([]), $this->equalTo(['email' => 'user2@example.com']));
$user = new \Cloudflare\API\Endpoints\User($mock);
$user->updateUserDetails(['email' => "user2@example.com"]);
}
}