Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getters for certain properties #9

Merged
merged 2 commits into from
Sep 27, 2016
Merged
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
32 changes: 32 additions & 0 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,38 @@ public function __construct($host, $headers = null, $version = null, $path = nul
// These are the supported HTTP verbs
$this->methods = ['delete', 'get', 'patch', 'post', 'put'];
}

/**
* @return string
*/
public function getHost()
{
return $this->host;
}

/**
* @return array
*/
public function getHeaders()
{
return $this->headers;
}

/**
* @return string|null
*/
public function getVersion()
{
return $this->version;
}

/**
* @return array
*/
public function getPath()
{
return $this->path;
}

/**
* Make a new Client object
Expand Down
53 changes: 44 additions & 9 deletions test/unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SendGrid\Test;

use SendGrid\Client;

class ClientTest extends \PHPUnit_Framework_TestCase
{
/** @var MockClient */
Expand All @@ -10,7 +12,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
private $host;
/** @var array */
private $headers;

protected function setUp()
{
$this->host = 'https://localhost:4010';
Expand All @@ -20,7 +22,7 @@ protected function setUp()
];
$this->client = new MockClient($this->host, $this->headers, '/v3', null);
}

public function testConstructor()
{
$this->assertAttributeEquals($this->host, 'host', $this->client);
Expand All @@ -29,36 +31,69 @@ public function testConstructor()
$this->assertAttributeEquals([], 'path', $this->client);
$this->assertAttributeEquals(['delete', 'get', 'patch', 'post', 'put'], 'methods', $this->client);
}

public function test_()
{
$client = $this->client->_('test');
$this->assertAttributeEquals(['test'], 'path', $client);
}

public function test__call()
{
$client = $this->client->get();
$this->assertAttributeEquals('https://localhost:4010/v3/', 'url', $client);

$queryParams = ['limit' => 100, 'offset' => 0];
$client = $this->client->get(null, $queryParams);
$this->assertAttributeEquals('https://localhost:4010/v3/?limit=100&offset=0', 'url', $client);

$requestBody = ['name' => 'A New Hope'];
$client = $this->client->get($requestBody);
$this->assertAttributeEquals($requestBody, 'requestBody', $client);

$requestHeaders = ['X-Mock: 200'];
$client = $this->client->get(null, null, $requestHeaders);
$this->assertAttributeEquals($requestHeaders, 'requestHeaders', $client);

$client = $this->client->version('/v4');
$this->assertAttributeEquals('/v4', 'version', $client);

$client = $this->client->path_to_endpoint();
$this->assertAttributeEquals(['path_to_endpoint'], 'path', $client);
$client = $client->one_more_segment();
$this->assertAttributeEquals(['path_to_endpoint', 'one_more_segment'], 'path', $client);
}

public function testGetHost()
{
$client = new Client('https://localhost:4010');
$this->assertSame('https://localhost:4010', $client->getHost());
}

public function testGetHeaders()
{
$client = new Client('https://localhost:4010', ['Content-Type: application/json', 'Authorization: Bearer SG.XXXX']);
$this->assertSame(['Content-Type: application/json', 'Authorization: Bearer SG.XXXX'], $client->getHeaders());

$client2 = new Client('https://localhost:4010', null);
$this->assertSame([], $client2->getHeaders());
}

public function testGetVersion()
{
$client = new Client('https://localhost:4010', null, '/v3');
$this->assertSame('/v3', $client->getVersion());

$client = new Client('https://localhost:4010', null, null);
$this->assertSame(null, $client->getVersion());
}

public function testGetPath()
{
$client = new Client('https://localhost:4010', null, null, ['/foo/bar']);
$this->assertSame(['/foo/bar'], $client->getPath());

$client = new Client('https://localhost:4010', null, null, null);
$this->assertSame([], $client->getPath());
}
}