2
2
3
3
namespace SendGrid \Test ;
4
4
5
+ use SendGrid \Client ;
6
+
5
7
class ClientTest extends \PHPUnit_Framework_TestCase
6
8
{
7
9
/** @var MockClient */
@@ -10,7 +12,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
10
12
private $ host ;
11
13
/** @var array */
12
14
private $ headers ;
13
-
15
+
14
16
protected function setUp ()
15
17
{
16
18
$ this ->host = 'https://localhost:4010 ' ;
@@ -20,7 +22,7 @@ protected function setUp()
20
22
];
21
23
$ this ->client = new MockClient ($ this ->host , $ this ->headers , '/v3 ' , null );
22
24
}
23
-
25
+
24
26
public function testConstructor ()
25
27
{
26
28
$ this ->assertAttributeEquals ($ this ->host , 'host ' , $ this ->client );
@@ -29,36 +31,69 @@ public function testConstructor()
29
31
$ this ->assertAttributeEquals ([], 'path ' , $ this ->client );
30
32
$ this ->assertAttributeEquals (['delete ' , 'get ' , 'patch ' , 'post ' , 'put ' ], 'methods ' , $ this ->client );
31
33
}
32
-
34
+
33
35
public function test_ ()
34
36
{
35
37
$ client = $ this ->client ->_ ('test ' );
36
38
$ this ->assertAttributeEquals (['test ' ], 'path ' , $ client );
37
39
}
38
-
40
+
39
41
public function test__call ()
40
42
{
41
43
$ client = $ this ->client ->get ();
42
44
$ this ->assertAttributeEquals ('https://localhost:4010/v3/ ' , 'url ' , $ client );
43
-
45
+
44
46
$ queryParams = ['limit ' => 100 , 'offset ' => 0 ];
45
47
$ client = $ this ->client ->get (null , $ queryParams );
46
48
$ this ->assertAttributeEquals ('https://localhost:4010/v3/?limit=100&offset=0 ' , 'url ' , $ client );
47
-
49
+
48
50
$ requestBody = ['name ' => 'A New Hope ' ];
49
51
$ client = $ this ->client ->get ($ requestBody );
50
52
$ this ->assertAttributeEquals ($ requestBody , 'requestBody ' , $ client );
51
-
53
+
52
54
$ requestHeaders = ['X-Mock: 200 ' ];
53
55
$ client = $ this ->client ->get (null , null , $ requestHeaders );
54
56
$ this ->assertAttributeEquals ($ requestHeaders , 'requestHeaders ' , $ client );
55
-
57
+
56
58
$ client = $ this ->client ->version ('/v4 ' );
57
59
$ this ->assertAttributeEquals ('/v4 ' , 'version ' , $ client );
58
-
60
+
59
61
$ client = $ this ->client ->path_to_endpoint ();
60
62
$ this ->assertAttributeEquals (['path_to_endpoint ' ], 'path ' , $ client );
61
63
$ client = $ client ->one_more_segment ();
62
64
$ this ->assertAttributeEquals (['path_to_endpoint ' , 'one_more_segment ' ], 'path ' , $ client );
63
65
}
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
+ }
64
99
}
0 commit comments