80%+ test coverage
[m6w6/ext-http] / phpunit / DataShareTest.php
1 <?php
2
3 class DataShareTest 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 $s = $f->createDataShare();
9
10 $this->assertFalse($s->dns, "dns");
11 $this->assertFalse($s->cookie, "cookie");
12 $this->assertFalse($s->ssl, "ssl");
13
14 $s->dns = true;
15 $s->cookie = true;
16 $s->ssl = true;
17
18 $this->assertTrue($s->dns, "dns");
19 $this->assertTrue($s->cookie, "cookie");
20 $this->assertTrue($s->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 $s = $f->createDataShare();
28 $s->dns = $s->ssl = $s->cookie = true;
29 $c = $f->createClient();
30 $s->attach($c);
31 $c->setRequest(new http\Client\Request("GET", "https://twitter.com/"));
32 $s->attach($c);
33 $cc = clone $c;
34 $s->attach($cc);
35
36 $this->assertEquals(3, count($s));
37 }
38 }
39
40 function testCurl() {
41 $client = new http\Curl\Client;
42 $client->setRequest(new http\Client\Request("GET", "https://twitter.com/"));
43 $share = new http\Curl\Client\DataShare;
44 $share->ssl = $share->dns = $share->cookie = true;
45 $share->attach($client);
46 $share->attach($client2 = clone $client);
47 $share->attach($client3 = clone $client);
48
49 $this->assertEquals(3, count($share));
50 $client->send();
51 $client2->send();
52 $client3->send();
53
54 $share->detach($client);
55 $share->reset();
56 }
57 }
58