- less custom macro cruft
[m6w6/ext-http] / phpunit / ClientRequestTest.php
1 <?php
2
3 use http\Client\Request;
4 use http\Message\Body;
5
6 class ClientRequestTest extends PHPUnit_Framework_TestCase
7 {
8 function testStandard() {
9 $r = new Request($m = "POST", $u = "http://localhost/foo", $h = array("header", "value"),
10 $b = new Body(fopen(__FILE__, "r+b"))
11 );
12
13 $this->assertEquals($b, $r->getBody());
14 $this->assertEquals($h, $r->getHeaders());
15 $this->assertEquals($u, $r->getRequestUrl());
16 $this->assertEquals($m, $r->getRequestMethod());
17 }
18
19 function testContentType() {
20 $r = new Request("POST", "http://localhost/");
21 $this->assertEquals($r, $r->setContentType($ct = "text/plain; charset=utf-8"));
22 $this->assertEquals($ct, $r->getContentType());
23 }
24
25 function testQuery() {
26 $r = new Request("GET", "http://localhost/");
27 $this->assertEquals(null, $r->getQuery());
28 $this->assertEquals($r, $r->setQuery($q = "foo=bar"));
29 $this->assertEquals($q, $r->getQuery());
30 $this->assertEquals($r, $r->addQuery("a[]=1&a[]=2"));
31 $this->assertEquals("foo=bar&a%5B0%5D=1&a%5B1%5D=2", $r->getQuery());
32 $this->assertEquals(null, $r->setQuery(null)->getQuery());
33 }
34
35 function testOptions() {
36 $r = new Request("GET", "http://localhost");
37 $this->assertEquals($r, $r->setOptions($o = array("redirect"=>5, "timeout"=>5)));
38 $this->assertEquals($o, $r->getOptions());
39 $this->assertEquals($r, $r->setSslOptions($o = array("verify_peer"=>false)));
40 $this->assertEquals($o, $r->getSslOptions());
41 }
42 }
43