From 18415fc7eef5ce2e3d16ba8b9c4077ad7cc630f3 Mon Sep 17 00:00:00 2001 From: Arjan Keeman Date: Thu, 22 Sep 2016 10:45:27 +0200 Subject: Increase testability by providing getters. --- lib/Client.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/Client.php b/lib/Client.php index c14344a..d5f997b 100644 --- a/lib/Client.php +++ b/lib/Client.php @@ -48,6 +48,38 @@ class Client // 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 -- cgit v1.1 From 6b07cdc9a3c78523d22f45a6b304e2eb2c88a088 Mon Sep 17 00:00:00 2001 From: Arjan Keeman Date: Thu, 22 Sep 2016 10:58:13 +0200 Subject: update tests --- test/unit/ClientTest.php | 53 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/test/unit/ClientTest.php b/test/unit/ClientTest.php index 18cab59..98218ac 100644 --- a/test/unit/ClientTest.php +++ b/test/unit/ClientTest.php @@ -2,6 +2,8 @@ namespace SendGrid\Test; +use SendGrid\Client; + class ClientTest extends \PHPUnit_Framework_TestCase { /** @var MockClient */ @@ -10,7 +12,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase private $host; /** @var array */ private $headers; - + protected function setUp() { $this->host = 'https://localhost:4010'; @@ -20,7 +22,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase ]; $this->client = new MockClient($this->host, $this->headers, '/v3', null); } - + public function testConstructor() { $this->assertAttributeEquals($this->host, 'host', $this->client); @@ -29,36 +31,69 @@ class ClientTest extends \PHPUnit_Framework_TestCase $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()); + } } \ No newline at end of file -- cgit v1.1