extesion deps
[m6w6/ext-http] / tests / factory.phpt
1 --TEST--
2 factory
3 --SKIPIF--
4 <?php
5 include "skipif.inc";
6 in_array("curl", http\Client\Factory::getAvailableDrivers()) or die ("skip CURL support missing");
7 ?>
8 --FILE--
9 <?php
10 echo "Test\n";
11
12 class MyClient extends http\Curl\Client {}
13 class MyPool extends http\Curl\Client\Pool {}
14 class MyShare extends http\Curl\Client\DataShare {}
15
16 class MyFactory extends http\Client\Factory {
17 protected $driver = "curl";
18 protected $persistentHandleId = "My";
19 protected $clientClass = "MyClient";
20 protected $clientPoolClass = "MyPool";
21 protected $clientDataShareClass = "MyShare";
22
23 protected $dummy = "foo";
24 }
25
26 $f = new MyFactory(array("driver" => "curl"));
27 $r = $f->createClient();
28 $p = $f->createPool();
29 $s = $f->createDataShare();
30
31 $r->setRequest(new http\Client\Request("GET", "http://localhost/"));
32 $x = $f->createPool($r);
33 $y = $f->createDatashare($r);
34
35 var_dump(
36 array_map("get_class", array($f,$r,$p,$s,$x,$y)),
37 $f->getDriver()
38 );
39
40 foreach (array("Client", "Pool", "DataShare") as $type) {
41 try {
42 $f = new http\Client\Factory(array("driver" => "nonexistant"));
43 var_dump($f->{"create$type"}());
44 } catch (Exception $e) {
45 echo $e->getMessage(), "\n";
46 }
47 }
48
49 echo "Done\n";
50 ?>
51 --EXPECTF--
52 Test
53 array(6) {
54 [0]=>
55 string(9) "MyFactory"
56 [1]=>
57 string(8) "MyClient"
58 [2]=>
59 string(6) "MyPool"
60 [3]=>
61 string(7) "MyShare"
62 [4]=>
63 string(6) "MyPool"
64 [5]=>
65 string(7) "MyShare"
66 }
67 string(4) "curl"
68 clients are not supported by this driver
69 pools are not supported by this driver
70 datashares are not supported by this driver
71 Done