22
33namespace SendGrid \Test ;
44
5+ use SendGrid \Client ;
6+
57class 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