-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
executable file
·79 lines (64 loc) · 2.43 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
use PHPUnit\Framework\TestCase;
use Rhio\Rhio;
final class RhioTest extends TestCase
{
public function testCanExecuteGetRequest()
{
$rhio = new Rhio();
$result = $rhio->get("http://postman-echo.com");
$this->assertEquals('200', $result['http_code']);
}
public function testCanExecuteGetRequestWithParameters()
{
$rhio = new Rhio();
$data = array(
'q' => 'blobfish'
);
$result = $rhio->get("http://postman-echo.com/get", $data);
$json = json_decode($result['body']);
$this->assertEquals('200', $result['http_code']);
$this->assertEquals('blobfish', $json->args->q);
}
public function testCanExecuteGetRequestWithCustomHeader() {
$rhio = new Rhio(True);
$header_key = 'test-header-key';
$header_value = '123456789';
$header = $header_key.': '.$header_value;
$rhio->set_header($header);
$result = $rhio->get("https://postman-echo.com/headers");
$json = json_decode($result['body']);
$this->assertEquals('200', $result['http_code']);
$this->assertEquals($header_value, $json->headers->$header_key);
}
public function testCanExecutePostRequest()
{
$rhio = new Rhio(True);
$result = $rhio->post("http://postman-echo.com/post", array('foo' => 'bar'));
$json = json_decode($result['body']);
$this->assertEquals('200', $result['http_code']);
$this->assertEquals('bar', $json->form->foo);
}
public function testCanExecutePutRequest()
{
$rhio = new Rhio(True);
$result = $rhio->put("http://postman-echo.com/put", array('foo' => 'bar'));
$json = json_decode($result['body']);
$this->assertEquals('200', $result['http_code']);
$this->assertEquals('bar', $json->form->foo);
}
public function testCanExecuteDeleteRequest()
{
$rhio = new Rhio(True);
$result = $rhio->delete("http://postman-echo.com/delete", array('foo' => 'bar'));
$json = json_decode($result['body']);
$this->assertEquals('200', $result['http_code']);
$this->assertEquals('bar', $json->form->foo);
}
public function testCanExecuteGetWithAuth()
{
$rhio = new Rhio();
$result = $rhio->get("http://postman:password@postman-echo.com/digest-auth");
$this->assertEquals('200', $result['http_code']);
}
}