fetch() public method

Grab informations from an url: - final url (after potential redirection) - raw content - content type header.
public fetch ( string $url, boolean $skipTypeVerification = false, array $httpHeader = [] ) : array
$url string
$skipTypeVerification boolean Avoid mime detection which means, force GET instead of potential HEAD
$httpHeader array Custom HTTP Headers from SiteConfig
return array With keys effective_url, body & headers
Beispiel #1
0
 public function testWith404ResponseWithoutResponse()
 {
     $request = $this->getMockBuilder('GuzzleHttp\\Message\\Request')->disableOriginalConstructor()->getMock();
     $response = $this->getMockBuilder('GuzzleHttp\\Message\\Response')->disableOriginalConstructor()->getMock();
     $client = $this->getMockBuilder('GuzzleHttp\\Client')->disableOriginalConstructor()->getMock();
     $client->expects($this->once())->method('get')->willThrowException(new RequestException('oops', $request));
     $http = new HttpClient($client);
     $res = $http->fetch('http://0.0.0.0');
     $this->assertEquals('http://0.0.0.0', $res['effective_url']);
     $this->assertEquals('', $res['body']);
     $this->assertEquals('', $res['headers']);
     $this->assertEquals(500, $res['status']);
 }