27 $client =
new Client(
'http://127.0.0.1/');
28 for ($i = 0; $i < $num; $i++) {
29 $requests[$i] = $client->get();
30 $requests[$i]->setResponse(
new Response(200),
true);
31 $requests[$i]->send();
32 $h->
add($requests[$i]);
46 $this->assertSame($h, $h->setLimit(10));
47 $this->assertEquals(10, $h->getLimit());
54 $this->assertEquals(1, count($h));
55 $i = $h->getIterator();
56 $this->assertEquals(1, count($i));
57 $this->assertEquals($requests[0], $i[0]);
68 $this->assertEquals(2, count($h));
70 foreach ($h as $request) {
72 $this->assertSame($requests[$i], $request);
81 $this->assertSame(end($requests), $h->getLastRequest());
88 $this->assertSame(end($requests)->getResponse(), $h->getLastResponse());
95 $this->assertEquals(5, count($h));
97 $this->assertEquals(0, count($h));
106 $client =
new Client(
'http://127.0.0.1/');
107 $client->getEventDispatcher()->addSubscriber($h);
109 $request = $client->get();
110 $request->setResponse(
new Response(200),
true);
113 $this->assertSame($request, $h->getLastRequest());
118 $client =
new Client(
'http://127.0.0.1/');
120 $client->getEventDispatcher()->addSubscriber($h);
123 new Response(301, array(
'Location' =>
'/redirect1',
'Content-Length' => 0)),
124 new Response(307, array(
'Location' =>
'/redirect2',
'Content-Length' => 0)),
125 new Response(200, array(
'Content-Length' =>
'2'),
'HI')
128 $client->getEventDispatcher()->addSubscriber($mock);
129 $request = $client->get();
131 $this->assertEquals(3, count($h));
132 $this->assertEquals(3, count($mock->getReceivedRequests()));
134 $h = str_replace(
"\r",
'', $h);
135 $this->assertContains(
"> GET / HTTP/1.1\nHost: 127.0.0.1\nUser-Agent:", $h);
136 $this->assertContains(
"< HTTP/1.1 301 Moved Permanently\nLocation: /redirect1", $h);
137 $this->assertContains(
"< HTTP/1.1 307 Temporary Redirect\nLocation: /redirect2", $h);
138 $this->assertContains(
"< HTTP/1.1 200 OK\nContent-Length: 2\n\nHI", $h);