@@ -10,20 +10,23 @@ class GraphResponseTest extends TestCase
1010{
1111 public $ client ;
1212 public $ request ;
13+ public $ response ;
1314 public $ responseBody ;
1415
1516 public function setUp ()
1617 {
1718 $ this ->responseBody = array ('body ' => 'content ' , 'displayName ' => 'Bob Barker ' );
18- $ body = json_encode ($ this ->responseBody );
19+ $ this ->collectionBody = array ("value " => array (array ('displayName ' => 'Bob Barker ' ), array ('displayName ' => 'Drew Carey ' )));
20+
1921 $ mock = new GuzzleHttp \Handler \MockHandler ([
20- new GuzzleHttp \Psr7 \Response (200 , ['foo ' => 'bar ' ], $ body ),
21- new GuzzleHttp \Psr7 \Response (200 , ['foo ' => 'bar ' ], $ body )
22+ new GuzzleHttp \Psr7 \Response (200 , ['foo ' => 'bar ' ], json_encode ( $ this -> responseBody ) ),
23+ new GuzzleHttp \Psr7 \Response (200 , ['foo ' => 'bar ' ], json_encode ( $ this -> collectionBody ) )
2224 ]);
2325 $ handler = GuzzleHttp \HandlerStack::create ($ mock );
2426 $ this ->client = new GuzzleHttp \Client (['handler ' => $ handler ]);
2527
2628 $ this ->request = new GraphRequest ("GET " , "/endpoint " , "token " , "baseUrl " , "/version " );
29+ $ this ->response = new GraphResponse ($ this ->request , "{response} " , "200 " , ["foo " => "bar " ]);
2730 }
2831
2932 public function testGetResponseAsObject ()
@@ -33,7 +36,17 @@ public function testGetResponseAsObject()
3336
3437 $ this ->assertInstanceOf (Model \User::class, $ response );
3538 $ this ->assertEquals ($ this ->responseBody ['displayName ' ], $ response ->getDisplayName ());
39+ }
40+
41+ public function testGetResponseAsListOfObjects ()
42+ {
43+ $ this ->request ->setReturnType (Model \User::class);
44+ $ response = $ this ->request ->execute ($ this ->client );
45+ $ response = $ this ->request ->execute ($ this ->client );
3646
47+ $ this ->assertContainsOnlyInstancesOf (Model \User::class, $ response );
48+ $ this ->assertEquals ('Drew Carey ' , $ response [1 ]->getDisplayName ());
49+ $ this ->assertEquals (2 , count ($ response ));
3750 }
3851
3952 public function testGetSkipToken ()
@@ -49,6 +62,19 @@ public function testGetSkipToken()
4962 $ this ->assertEquals ('10 ' , $ token );
5063 }
5164
65+ public function testNoSkipToken ()
66+ {
67+ //Temporarily make getSkipToken() public
68+ $ reflectionMethod = new ReflectionMethod ('Microsoft\Graph\Http\GraphResponse ' , 'getSkipToken ' );
69+ $ reflectionMethod ->setAccessible (true );
70+
71+ $ body = json_encode (array ('@odata.nextLink ' => 'https://url.com/resource ' ));
72+ $ response = new GraphResponse ($ this ->request , $ body );
73+
74+ $ token = $ reflectionMethod ->invokeArgs ($ response , array ());
75+ $ this ->assertNull ($ token );
76+ }
77+
5278 public function testDecodeBody ()
5379 {
5480 //Temporarily make decodeBody() public
@@ -73,6 +99,12 @@ public function testDecodeEmptyBody()
7399 $ this ->assertEquals (array (), $ decodedBody );
74100 }
75101
102+ public function testGetHeaders ()
103+ {
104+ $ headers = $ this ->response ->getHeaders ();
105+ $ this ->assertEquals (["foo " => "bar " ], $ headers );
106+ }
107+
76108 public function testGetBody ()
77109 {
78110 $ response = $ this ->request ->execute ($ this ->client );
0 commit comments