f4a0453c6163c1d968b7ec5c5650774a879a08a5
[m6w6/ext-http] / phpunit / DataShareTest.php
1 <?php
2
3 class UserClient extends http\Client\AbstractClient {
4 function send($request = null) {
5 }
6 }
7
8
9 class DataShareTest extends PHPUnit_Framework_TestCase
10 {
11 function testStandard() {
12 foreach (http\Client\Factory::getAvailableDrivers() as $driver) {
13 $f = new http\Client\Factory(compact("driver"));
14 $s = $f->createDataShare();
15
16 $this->assertFalse($s->dns, "dns");
17 $this->assertFalse($s->cookie, "cookie");
18 $this->assertFalse($s->ssl, "ssl");
19
20 $s->dns = true;
21 $s->cookie = true;
22 $s->ssl = true;
23
24 $this->assertTrue($s->dns, "dns");
25 $this->assertTrue($s->cookie, "cookie");
26 $this->assertTrue($s->ssl, "ssl");
27 }
28 }
29
30 function testAttach() {
31 foreach (http\Client\Factory::getAvailableDrivers() as $driver) {
32 $f = new http\Client\Factory(compact("driver"));
33 $s = $f->createDataShare();
34 $s->dns = $s->ssl = $s->cookie = true;
35 $c = $f->createClient();
36 $s->attach($c);
37 $c->setRequest(new http\Client\Request("GET", "https://twitter.com/"));
38 $s->attach($c);
39 $cc = clone $c;
40 $s->attach($cc);
41
42 $this->assertEquals(3, count($s));
43 }
44 }
45
46 function testCurl() {
47 $client = new http\Curl\Client;
48 $client->setRequest(new http\Client\Request("GET", "https://twitter.com/"));
49 $share = new http\Curl\Client\DataShare;
50 $share->ssl = $share->dns = $share->cookie = true;
51 $share->attach($client);
52 $share->attach($client2 = clone $client);
53 $share->attach($client3 = clone $client);
54
55 $this->assertEquals(3, count($share));
56 $client->send();
57 $client2->send();
58 $client3->send();
59
60 $share->detach($client);
61 $share->reset();
62 }
63
64 function testCurlIncompatible() {
65 $client = new UserClient;
66 $client->setRequest(new http\Client\Request("GET", "https://twitter.com"));
67
68 $share = new http\Curl\Client\DataShare;
69 $this->setExpectedException("PHPUnit_Framework_Error_Warning");
70 $share->attach($client);
71 $this->setExpectedException("PHPUnit_Framework_Error_Warning");
72 $share->detach($client);
73 }
74 }
75