1313
1414class LtiServiceConnectorTest extends TestCase
1515{
16+ /**
17+ * @var Mockery\MockInterface
18+ */
19+ private $ registration ;
20+ /**
21+ * @var Mockery\MockInterface
22+ */
23+ private $ cache ;
24+ /**
25+ * @var Mockery\MockInterface
26+ */
27+ private $ client ;
28+ /**
29+ * @var Mockery\MockInterface
30+ */
31+ private $ response ;
32+ /**
33+ * @var string
34+ */
35+ private $ token ;
36+ /**
37+ * @var LtiServiceConnector
38+ */
39+ private $ connector ;
40+
1641 public function setUp (): void
1742 {
1843 $ this ->registration = Mockery::mock (ILtiRegistration::class);
@@ -69,30 +94,33 @@ public function testItMakesPostServiceRequest()
6994 $ scopes = ['scopeKey ' ];
7095 $ method = 'post ' ;
7196 $ url = 'https://example.com ' ;
72- $ body = ['post ' => 'body ' ];
97+ $ body = json_encode ( ['post ' => 'body ' ]) ;
7398 $ requestHeaders = [
7499 'Authorization ' => 'Bearer ' .$ this ->token ,
75100 'Accept ' => 'application/json ' ,
76101 'Content-Type ' => 'application/json ' ,
77102 ];
78103 $ responseHeaders = [
79- 'Content-Type: application/json ' ,
80- 'Accept: application/json ' ,
104+ 'Content-Type ' => [ ' application/json '] ,
105+ 'Server ' => [ ' nginx ' ] ,
81106 ];
82107 $ responseBody = ['some ' => 'response ' ];
83108 $ expected = [
84- 'headers ' => $ responseHeaders ,
109+ 'headers ' => [
110+ 'Content-Type ' => 'application/json ' ,
111+ 'Server ' => 'nginx ' ,
112+ ],
85113 'body ' => $ responseBody ,
86114 ];
87115
88116 $ this ->mockCacheHasAccessToken ();
89117 $ this ->client ->shouldReceive ('request ' )
90118 ->with ($ method , $ url , [
91119 'headers ' => $ requestHeaders ,
92- 'json ' => $ body ,
120+ 'body ' => $ body ,
93121 ])->once ()->andReturn ($ this ->response );
94122 $ this ->response ->shouldReceive ('getHeaders ' )
95- ->once ()->andReturn (implode ( "\r\n" , $ responseHeaders) );
123+ ->once ()->andReturn ($ responseHeaders );
96124 $ this ->response ->shouldReceive ('getBody ' )
97125 ->once ()->andReturn (json_encode ($ responseBody ));
98126
@@ -111,12 +139,15 @@ public function testItMakesDefaultServiceRequest()
111139 'Accept ' => 'application/json ' ,
112140 ];
113141 $ responseHeaders = [
114- 'Content-Type: application/json ' ,
115- 'Accept: application/json ' ,
142+ 'Content-Type ' => [ ' application/json '] ,
143+ 'Server ' => [ ' nginx ' ] ,
116144 ];
117145 $ responseBody = ['some ' => 'response ' ];
118146 $ expected = [
119- 'headers ' => $ responseHeaders ,
147+ 'headers ' => [
148+ 'Content-Type ' => 'application/json ' ,
149+ 'Server ' => 'nginx ' ,
150+ ],
120151 'body ' => $ responseBody ,
121152 ];
122153
@@ -126,7 +157,7 @@ public function testItMakesDefaultServiceRequest()
126157 'headers ' => $ requestHeaders ,
127158 ])->once ()->andReturn ($ this ->response );
128159 $ this ->response ->shouldReceive ('getHeaders ' )
129- ->once ()->andReturn (implode ( "\r\n" , $ responseHeaders) );
160+ ->once ()->andReturn ($ responseHeaders );
130161 $ this ->response ->shouldReceive ('getBody ' )
131162 ->once ()->andReturn (json_encode ($ responseBody ));
132163
0 commit comments