/** * 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'))); }
/** * 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)); }