File tree 4 files changed +36
-6
lines changed
lib/Github/HttpClient/Message 4 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -9,14 +9,15 @@ class ResponseMediator
9
9
{
10
10
public static function getContent (Response $ response )
11
11
{
12
- $ body = $ response ->getBody (true );
13
- $ content = json_decode ($ body , true );
14
-
15
- if (JSON_ERROR_NONE !== json_last_error ()) {
16
- return $ body ;
12
+ $ body = $ response ->getBody (true );
13
+ if (strpos ($ response ->getContentType (), 'application/json ' ) === 0 ) {
14
+ $ content = json_decode ($ body , true );
15
+ if (JSON_ERROR_NONE === json_last_error ()) {
16
+ return $ content ;
17
+ }
17
18
}
18
19
19
- return $ content ;
20
+ return $ body ;
20
21
}
21
22
22
23
public static function getPagination (Response $ response )
Original file line number Diff line number Diff line change @@ -42,6 +42,24 @@ public function shouldRetrieveRawBlob()
42
42
$ this ->assertStringStartsWith ('<?php ' , $ contents );
43
43
}
44
44
45
+ /**
46
+ * @test
47
+ */
48
+ public function shouldNotDecodeRawBlob ()
49
+ {
50
+ $ api = $ this ->client ->api ('git_data ' )->blobs ();
51
+ $ api ->configure ('raw ' );
52
+
53
+ $ contents = $ api ->show (
54
+ 'KnpLabs ' ,
55
+ 'php-github-api ' ,
56
+ 'dc16d3e77fd4e40638cb722927ffe15fa85b1434 '
57
+ );
58
+
59
+ $ this ->assertInternalType ('string ' , $ contents );
60
+ $ this ->assertStringStartsWith ('{ ' , $ contents );
61
+ }
62
+
45
63
/**
46
64
* @test
47
65
*/
Original file line number Diff line number Diff line change @@ -120,6 +120,9 @@ public function shouldNotPassWhen400IsSent()
120
120
$ response ->expects ($ this ->once ())
121
121
->method ('getBody ' )
122
122
->will ($ this ->returnValue (json_encode (array ('message ' => 'test ' ))));
123
+ $ response ->expects ($ this ->once ())
124
+ ->method ('getContentType ' )
125
+ ->will ($ this ->returnValue ('application/json ' ));
123
126
$ response ->expects ($ this ->any ())
124
127
->method ('getStatusCode ' )
125
128
->will ($ this ->returnValue (400 ));
@@ -159,6 +162,9 @@ public function shouldNotPassWhen422IsSentWithErrorCode($errorCode)
159
162
->method ('getHeader ' )
160
163
->with ('X-RateLimit-Limit ' )
161
164
->will ($ this ->returnValue (5000 ));
165
+ $ response ->expects ($ this ->once ())
166
+ ->method ('getContentType ' )
167
+ ->will ($ this ->returnValue ('application/json ' ));
162
168
$ response ->expects ($ this ->once ())
163
169
->method ('getBody ' )
164
170
->will ($ this ->returnValue ($ content ));
Original file line number Diff line number Diff line change @@ -36,4 +36,9 @@ public function getHeader($header = null)
36
36
37
37
return $ header ;
38
38
}
39
+
40
+ public function getContentType ()
41
+ {
42
+ return 'application/json ' ;
43
+ }
39
44
}
You can’t perform that action at this time.
0 commit comments