3 class ProgressObserver1
implements SplObserver
{
4 function update(SplSubject
$c, $r = null) {
5 if ($c->getProgressInfo($r)) $c->pi
.= "-";
8 class ProgressObserver2
implements SplObserver
{
9 function update(SplSubject
$c, $r = null) {
10 if ($c->getProgressInfo($r)) $c->pi
.= ".";
13 class CallbackObserver
implements SplObserver
{
15 function __construct($callback) {
16 $this->callback
= $callback;
18 function update(SplSubject
$c, $r = null) {
19 call_user_func($this->callback
, $c, $r);
23 class RequestTest
extends PHPUnit_Framework_TestCase
31 $this->r
= new http\Client
;
35 "connecttimeout" => 30,
46 "connecttimeout" => 30,
49 $this->r
->getOptions()
53 function testObserver() {
55 $this->r
->attach($o1 = new ProgressObserver1
);
56 $this->r
->attach($o2 = new ProgressObserver2
);
58 $o3 = new CallbackObserver(
59 function ($c, $r) use ($test) {
60 $p = (array) $c->getProgressInfo($r);
61 $test->assertArrayHasKey("started", $p);
62 $test->assertArrayHasKey("finished", $p);
63 $test->assertArrayHasKey("dlnow", $p);
64 $test->assertArrayHasKey("ulnow", $p);
65 $test->assertArrayHasKey("dltotal", $p);
66 $test->assertArrayHasKey("ultotal", $p);
67 $test->assertArrayHasKey("info", $p);
71 $this->r
->enqueue(new http\Client\
Request("GET", "http://dev.iworks.at/ext-http/"))->send();
72 $this->assertRegexp("/(\.-)+/", $this->r
->pi
);
73 $this->assertCount(3, $this->r
->getObservers());
74 $this->r
->detach($o1);
75 $this->assertCount(2, $this->r
->getObservers());
76 $this->r
->detach($o2);
77 $this->assertCount(1, $this->r
->getObservers());
78 $this->r
->detach($o3);
79 $this->assertCount(0, $this->r
->getObservers());
83 $this->r
->setSslOptions(array("verify_peer" => true));
84 $this->r
->addSslOptions(array("verify_host" => 2));
87 "verify_peer" => true,
90 $this->r
->getSslOptions()
92 $this->r
->enqueue($req = new http\Client\
Request("GET", "https://twitter.com/"));
94 $ti = $this->r
->getTransferInfo($req);
95 $this->assertArrayHasKey("ssl_engines", $ti);
96 $this->assertGreaterThan(0, count($ti["ssl_engines"]));
99 function testHistory() {
100 $body = new http\Message\Body
;
101 $body->append("foobar");
103 $request = new http\Client\Request
;
104 $request->setBody($body);
105 $request->setRequestMethod("POST");
106 $request->setRequestUrl("http://dev.iworks.at/ext-http/.print_request.php");
108 $this->r
->recordHistory
= true;
109 $this->r
->enqueue($request)->send();
111 $this->assertStringMatchesFormat(<<<HTTP
112 POST /ext-http/.print_request.php HTTP/1.1
117 Content
-Type
: application
/x
-www
-form
-urlencoded
118 X
-Original
-Content
-Length
: 6
126 Content
-Type
: text
/html
127 X
-Original
-Content
-Length
: 19
132 , str_replace("\r", "", $this->r
->getHistory()->toString(true))
136 $this->r
->requeue($request)->send();
138 $this->assertStringMatchesFormat(<<<HTTP
139 POST /ext-http/.print_request.php HTTP/1.1
144 Content
-Type
: application
/x
-www
-form
-urlencoded
145 X
-Original
-Content
-Length
: 6
153 Content
-Type
: text
/html
154 X
-Original
-Content
-Length
: 19
158 POST
/ext
-http
/.print_request
.php HTTP
/1.1
163 Content
-Type
: application
/x
-www
-form
-urlencoded
164 X
-Original
-Content
-Length
: 6
172 Content
-Type
: text
/html
173 X
-Original
-Content
-Length
: 19
178 , str_replace("\r", "", $this->r
->getHistory()->toString(true))