extesion deps
[m6w6/ext-http] / phpunit / PoolTest.php
1 <?php
2
3 class PoolTest extends PHPUnit_Framework_TestCase
4 {
5 /*function testStandard() {
6 foreach (http\Client\Factory::getAvailableDrivers() as $driver) {
7 $f = new http\Client\Factory(compact("driver"));
8 $p = $f->createPool();
9
10 $this->assertFalse($p->dns, "dns");
11 $this->assertFalse($p->cookie, "cookie");
12 $this->assertFalse($p->ssl, "ssl");
13
14 $p->dns = true;
15 $p->cookie = true;
16 $p->ssl = true;
17
18 $this->assertTrue($p->dns, "dns");
19 $this->assertTrue($p->cookie, "cookie");
20 $this->assertTrue($p->ssl, "ssl");
21 }
22 }*/
23
24 function testAttach() {
25 foreach (http\Client\Factory::getAvailableDrivers() as $driver) {
26 $f = new http\Client\Factory(compact("driver"));
27
28 $p = $f->createPool();
29 $c = $f->createClient();
30
31 $c->setRequest(new http\Client\Request("GET", "https://twitter.com/"));
32 $p->attach($c);
33
34 try {
35 $p->attach($c);
36 } catch (http\Exception $e) {
37 $this->assertEquals("Could not attach request to pool: Invalid easy handle", $e->getMessage());
38 }
39
40 $cc = clone $c;
41 $p->attach($cc);
42
43 $this->assertEquals(2, count($p));
44 }
45 }
46
47 function testCurl() {
48 $client = new http\Curl\Client;
49 $client->setRequest(new http\Client\Request("GET", "https://twitter.com/"));
50 $pool = new http\Curl\Client\Pool;
51 $pool->attach($client);
52 $pool->attach($client2 = clone $client);
53 $pool->attach($client3 = clone $client);
54
55 $this->assertEquals(3, count($pool));
56 $pool->send();
57
58 $pool->detach($client);
59 $this->assertEquals(2, count($pool));
60
61 $pool->reset();
62 $this->assertEquals(0, count($pool));
63 }
64
65 function testCurlEvents() {
66 $client = new http\Curl\Client;
67 $pool = new http\Curl\Client\Pool;
68
69 $client->setRequest(new http\Client\Request("GET", "https://twitter.com/"));
70
71 $pool->attach($client);
72 $pool->attach(clone $client);
73 $pool->attach(clone $client);
74
75 $pool->enableEvents();
76 $pool->send();
77 }
78 }
79