Skip to content

Commit

Permalink
Merge pull request #9 from akeeman/patch-1
Browse files Browse the repository at this point in the history
Add getters for certain properties
  • Loading branch information
thinkingserious authored Sep 27, 2016
2 parents 137c48b + 6b07cdc commit 865e525
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 9 deletions.
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());
}
}

0 comments on commit 865e525

Please sign in to comment.