Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Zogg committed Oct 24, 2014
1 parent 44179fe commit 0e594b6
Showing 1 changed file with 95 additions and 3 deletions.
98 changes: 95 additions & 3 deletions tests/HttpClientTest.php
Expand Up @@ -7,22 +7,114 @@

class HttpClientTest extends \PHPUnit_Framework_TestCase
{
public function testHttpClient()
public function testGet()
{
$httpClient = new HttpClient();

$response = $httpClient->request(new Request(
'1.1',
Request::METHOD_GET,
'http://en.wikipedia.org',
'http://httpbin.org/get?key=value',
array(
'Connection' => 'close',
)
));

$content = json_decode($response->getContent(), true);

$this->assertEquals('1.1', $response->getProtocolVersion());
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('OK', $response->getStatusMessage());
$this->assertEquals('application/json', $response->getHeader('Content-Type'));
$this->assertEquals(array('key' => 'value'), $content['args']);
}

public function testPost()
{
$httpClient = new HttpClient();

$response = $httpClient->request(new Request(
'1.1',
Request::METHOD_POST,
'http://httpbin.org/post',
array(
'Connection' => 'close',
),
'key=value'
));

$content = json_decode($response->getContent(), true);

$this->assertEquals('1.1', $response->getProtocolVersion());
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('OK', $response->getStatusMessage());
$this->assertEquals('application/json', $response->getHeader('Content-Type'));
$this->assertEquals(array('key' => 'value'), $content['form']);
}

public function testPut()
{
$httpClient = new HttpClient();

$response = $httpClient->request(new Request(
'1.1',
Request::METHOD_PUT,
'http://httpbin.org/put',
array(
'Connection' => 'close',
),
'key=value'
));

$content = json_decode($response->getContent(), true);
$this->assertEquals('1.1', $response->getProtocolVersion());
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('OK', $response->getStatusMessage());
$this->assertEquals('application/json', $response->getHeader('Content-Type'));
$this->assertEquals(array('key' => 'value'), $content['form']);
}

public function testDelete()
{
$httpClient = new HttpClient();

$response = $httpClient->request(new Request(
'1.1',
Request::METHOD_DELETE,
'http://httpbin.org/delete?key=value',
array(
'Connection' => 'close',
)
));

$content = json_decode($response->getContent(), true);

$this->assertEquals('1.1', $response->getProtocolVersion());
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('OK', $response->getStatusMessage());
$this->assertEquals('application/json', $response->getHeader('Content-Type'));
$this->assertEquals(array('key' => 'value'), $content['args']);
}

public function testPatch()
{
$httpClient = new HttpClient();

$response = $httpClient->request(new Request(
'1.1',
Request::METHOD_PATCH,
'http://httpbin.org/patch',
array(
'Connection' => 'close',
),
'key=value'
));

$content = json_decode($response->getContent(), true);
$this->assertEquals('1.1', $response->getProtocolVersion());
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('OK', $response->getStatusMessage());
$this->assertEquals('text/html; charset=UTF-8', $response->getHeader('Content-Type'));
$this->assertEquals('application/json', $response->getHeader('Content-Type'));
$this->assertEquals(array('key' => 'value'), $content['form']);
}
}

0 comments on commit 0e594b6

Please sign in to comment.