コード例 #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
ファイル: CoreHttpTest.php プロジェクト: nextglory/wechat
 /**
  * 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')));
 }
コード例 #3
0
 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));
 }