Skip to content

Commit 865e525

Browse files
Merge pull request #9 from akeeman/patch-1
Add getters for certain properties
2 parents 137c48b + 6b07cdc commit 865e525

File tree

2 files changed

+76
-9
lines changed

2 files changed

+76
-9
lines changed

lib/Client.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,38 @@ public function __construct($host, $headers = null, $version = null, $path = nul
4848
// These are the supported HTTP verbs
4949
$this->methods = ['delete', 'get', 'patch', 'post', 'put'];
5050
}
51+
52+
/**
53+
* @return string
54+
*/
55+
public function getHost()
56+
{
57+
return $this->host;
58+
}
59+
60+
/**
61+
* @return array
62+
*/
63+
public function getHeaders()
64+
{
65+
return $this->headers;
66+
}
67+
68+
/**
69+
* @return string|null
70+
*/
71+
public function getVersion()
72+
{
73+
return $this->version;
74+
}
75+
76+
/**
77+
* @return array
78+
*/
79+
public function getPath()
80+
{
81+
return $this->path;
82+
}
5183

5284
/**
5385
* Make a new Client object

test/unit/ClientTest.php

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace SendGrid\Test;
44

5+
use SendGrid\Client;
6+
57
class ClientTest extends \PHPUnit_Framework_TestCase
68
{
79
/** @var MockClient */
@@ -10,7 +12,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
1012
private $host;
1113
/** @var array */
1214
private $headers;
13-
15+
1416
protected function setUp()
1517
{
1618
$this->host = 'https://localhost:4010';
@@ -20,7 +22,7 @@ protected function setUp()
2022
];
2123
$this->client = new MockClient($this->host, $this->headers, '/v3', null);
2224
}
23-
25+
2426
public function testConstructor()
2527
{
2628
$this->assertAttributeEquals($this->host, 'host', $this->client);
@@ -29,36 +31,69 @@ public function testConstructor()
2931
$this->assertAttributeEquals([], 'path', $this->client);
3032
$this->assertAttributeEquals(['delete', 'get', 'patch', 'post', 'put'], 'methods', $this->client);
3133
}
32-
34+
3335
public function test_()
3436
{
3537
$client = $this->client->_('test');
3638
$this->assertAttributeEquals(['test'], 'path', $client);
3739
}
38-
40+
3941
public function test__call()
4042
{
4143
$client = $this->client->get();
4244
$this->assertAttributeEquals('https://localhost:4010/v3/', 'url', $client);
43-
45+
4446
$queryParams = ['limit' => 100, 'offset' => 0];
4547
$client = $this->client->get(null, $queryParams);
4648
$this->assertAttributeEquals('https://localhost:4010/v3/?limit=100&offset=0', 'url', $client);
47-
49+
4850
$requestBody = ['name' => 'A New Hope'];
4951
$client = $this->client->get($requestBody);
5052
$this->assertAttributeEquals($requestBody, 'requestBody', $client);
51-
53+
5254
$requestHeaders = ['X-Mock: 200'];
5355
$client = $this->client->get(null, null, $requestHeaders);
5456
$this->assertAttributeEquals($requestHeaders, 'requestHeaders', $client);
55-
57+
5658
$client = $this->client->version('/v4');
5759
$this->assertAttributeEquals('/v4', 'version', $client);
58-
60+
5961
$client = $this->client->path_to_endpoint();
6062
$this->assertAttributeEquals(['path_to_endpoint'], 'path', $client);
6163
$client = $client->one_more_segment();
6264
$this->assertAttributeEquals(['path_to_endpoint', 'one_more_segment'], 'path', $client);
6365
}
66+
67+
public function testGetHost()
68+
{
69+
$client = new Client('https://localhost:4010');
70+
$this->assertSame('https://localhost:4010', $client->getHost());
71+
}
72+
73+
public function testGetHeaders()
74+
{
75+
$client = new Client('https://localhost:4010', ['Content-Type: application/json', 'Authorization: Bearer SG.XXXX']);
76+
$this->assertSame(['Content-Type: application/json', 'Authorization: Bearer SG.XXXX'], $client->getHeaders());
77+
78+
$client2 = new Client('https://localhost:4010', null);
79+
$this->assertSame([], $client2->getHeaders());
80+
}
81+
82+
public function testGetVersion()
83+
{
84+
$client = new Client('https://localhost:4010', null, '/v3');
85+
$this->assertSame('/v3', $client->getVersion());
86+
87+
$client = new Client('https://localhost:4010', null, null);
88+
$this->assertSame(null, $client->getVersion());
89+
}
90+
91+
public function testGetPath()
92+
{
93+
$client = new Client('https://localhost:4010', null, null, ['/foo/bar']);
94+
$this->assertSame(['/foo/bar'], $client->getPath());
95+
96+
$client = new Client('https://localhost:4010', null, null, null);
97+
$this->assertSame([], $client->getPath());
98+
}
6499
}

0 commit comments

Comments
 (0)