示例#1
0
 /**
  * Test parseJSON().
  */
 public function testParseJSON()
 {
     $http = new Http();
     $http->setClient($this->getGuzzleWithResponse('{"foo:"bar"}'));
     $this->assertEquals(null, $http->parseJSON($http->request('http://overtrue.me', 'GET')));
     $http->setClient($this->getGuzzleWithResponse('{"foo":"bar"}'));
     $this->assertEquals(['foo' => 'bar'], $http->parseJSON($http->request('http://overtrue.me', 'GET')));
     $http = new Http();
     $http->setClient($this->getGuzzleWithResponse());
     $this->assertEquals(null, $http->parseJSON($http->request('http://overtrue.me', 'GET')));
 }
示例#2
0
 /**
  * Test parseJSON().
  */
 public function testParseJSON()
 {
     $http = new Http();
     $http->setClient($this->getGuzzleWithResponse('{"foo:"bar"}'));
     try {
         $http->parseJSON($http->request('http://overtrue.me', 'GET'));
         $this->assertFail('Invalid json body check fail.');
     } catch (\Exception $e) {
         $this->assertInstanceOf("\\EasyWeChat\\Core\\Exceptions\\HttpException", $e);
     }
     $http->setClient($this->getGuzzleWithResponse('{"foo":"bar"}'));
     $this->assertEquals(['foo' => 'bar'], $http->parseJSON($http->request('http://overtrue.me', 'GET')));
     $http = new Http();
     $http->setClient($this->getGuzzleWithResponse(''));
     $this->assertEquals(null, $http->parseJSON($http->request('http://overtrue.me', 'GET')));
 }
 public function json($url, $options = [], $encodeOption = JSON_UNESCAPED_UNICODE)
 {
     $url .= (stripos($url, '?') ? '&' : '?') . 'component_access_token=' . $this->component_access_token;
     return parent::parseJSON(parent::json($url, $options, $encodeOption));
 }