php-censor/tests/B8Framework/HttpClientTest.php

64 lines
1.5 KiB
PHP
Raw Normal View History

2016-04-12 19:31:39 +02:00
<?php
2016-04-17 08:34:12 +02:00
namespace Tests\b8;
2016-04-12 19:31:39 +02:00
2016-04-17 08:34:12 +02:00
use b8\HttpClient;
2016-04-12 19:31:39 +02:00
class HttpClientTest extends \PHPUnit_Framework_TestCase
{
2016-04-21 19:06:58 +02:00
public function testSimpleRequest()
{
$http = new HttpClient();
2017-03-16 15:12:56 +01:00
$html = $http->request('GET', 'https://www.google.com');
2016-04-12 19:31:39 +02:00
2017-03-16 15:12:56 +01:00
$this->assertContains('Google', $html['body']);
2016-04-21 19:06:58 +02:00
}
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
public function testBaseUrl()
{
2017-03-16 15:12:56 +01:00
$http = new HttpClient('https://www.google.com');
2016-04-21 19:06:58 +02:00
$html = $http->request('GET', '/');
2016-04-12 19:31:39 +02:00
2017-03-16 15:12:56 +01:00
$this->assertContains('Google', $html['body']);
2016-04-21 19:06:58 +02:00
}
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
public function testGet()
{
2017-03-16 15:12:56 +01:00
$http = new HttpClient('https://www.google.com');
2016-04-21 19:06:58 +02:00
$html = $http->get('overview', ['x' => 1]);
2016-04-12 19:31:39 +02:00
2017-03-16 15:12:56 +01:00
$this->assertContains('Google', $html['body']);
2016-04-21 19:06:58 +02:00
}
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
public function testGetJson()
{
$http = new HttpClient('http://echo.jsontest.com');
$data = $http->get('/key/value');
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
$this->assertArrayHasKey('key', $data['body']);
}
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
public function testPost()
{
$http = new HttpClient('http://echo.jsontest.com');
$data = $http->post('/key/value', ['test' => 'x']);
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
$this->assertTrue(is_array($data));
}
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
public function testPut()
{
$http = new HttpClient('http://echo.jsontest.com');
$data = $http->put('/key/value', ['test' => 'x']);
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
$this->assertTrue(is_array($data));
}
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
public function testDelete()
{
$http = new HttpClient('http://echo.jsontest.com');
$data = $http->delete('/key/value', ['test' => 'x']);
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
$this->assertTrue(is_array($data));
}
2016-04-12 19:31:39 +02:00
}