coverity fix
[m6w6/ext-http] / tests / message009.phpt
1 --TEST--
2 message properties
3 --SKIPIF--
4 <?php
5 include "skipif.inc";
6 ?>
7 --FILE--
8 <?php
9
10 echo "Test\n";
11
12 class message extends http\Message {
13 function __call($m, $args) {
14 if (preg_match("/^test(get|set)(.*)\$/i", $m, $match)) {
15 list(, $getset, $prop) = $match;
16 $prop = strtolower($prop[0]).substr($prop,1);
17 switch(strtolower($getset)) {
18 case "get":
19 return $this->$prop;
20 case "set":
21 $this->$prop = current($args);
22 break;
23 }
24 }
25 }
26 }
27
28 $test = new message;
29 var_dump(0 === $test->testGetType());
30 var_dump(null === $test->testGetBody());
31 var_dump(null === $test->testGetRequestMethod());
32 var_dump(null === $test->testGetRequestUrl());
33 var_dump(null === $test->testGetResponseStatus());
34 var_dump(null === $test->testGetResponseCode());
35 var_dump("1.1" === $test->testGetHttpVersion());
36 var_dump(array() === $test->testGetHeaders());
37 var_dump(null === $test->testGetParentMessage());
38 $test->testSetType(http\Message::TYPE_REQUEST);
39 var_dump(http\Message::TYPE_REQUEST === $test->testGetType());
40 var_dump(http\Message::TYPE_REQUEST === $test->getType());
41 $body = new http\Message\Body;
42 $test->testSetBody($body);
43 var_dump($body === $test->testGetBody());
44 var_dump($body === $test->getBody());
45 $file = fopen(__FILE__,"r");
46 $test->testSetBody($file);
47 var_dump($file === $test->testGetBody()->getResource());
48 var_dump($file === $test->getBody()->getResource());
49 $test->testSetBody("data");
50 var_dump("data" === (string) $test->testGetBody());
51 var_dump("data" === (string) $test->getBody());
52 $test->testSetRequestMethod("HEAD");
53 var_dump("HEAD" === $test->testGetRequestMethod());
54 var_dump("HEAD" === $test->getRequestMethod());
55 $test->testSetRequestUrl("/");
56 var_dump("/" === $test->testGetRequestUrl());
57 var_dump("/" === $test->getRequestUrl());
58 var_dump("HEAD / HTTP/1.1" === $test->getInfo());
59 $test->testSetType(http\Message::TYPE_RESPONSE);
60 $test->setResponseStatus("Created");
61 var_dump("Created" === $test->testGetResponseStatus());
62 var_dump("Created" === $test->getResponseStatus());
63 $test->setResponseCode(201);
64 var_dump(201 === $test->testGetResponseCode());
65 var_dump(201 === $test->getResponseCode());
66 $test->testSetResponseStatus("Ok");
67 var_dump("Ok" === $test->testGetResponseStatus());
68 var_dump("Ok" === $test->getResponseStatus());
69 $test->testSetResponseCode(200);
70 var_dump(200 === $test->testGetResponseCode());
71 var_dump(200 === $test->getResponseCode());
72 $test->testSetHttpVersion("1.0");
73 var_dump("1.0" === $test->testGetHttpVersion());
74 var_dump("1.0" === $test->getHttpVersion());
75 var_dump("HTTP/1.0 200 OK" === $test->getInfo());
76 $test->setHttpVersion("1.1");
77 var_dump("1.1" === $test->testGetHttpVersion());
78 var_dump("1.1" === $test->getHttpVersion());
79 var_dump("HTTP/1.1 200 OK" === $test->getInfo());
80 $test->setInfo("HTTP/1.1 201 Created");
81 var_dump("Created" === $test->testGetResponseStatus());
82 var_dump("Created" === $test->getResponseStatus());
83 var_dump(201 === $test->testGetResponseCode());
84 var_dump(201 === $test->getResponseCode());
85 var_dump("1.1" === $test->testGetHttpVersion());
86 var_dump("1.1" === $test->getHttpVersion());
87 $test->testSetHeaders(array("Foo" => "bar"));
88 var_dump(array("Foo" => "bar") === $test->testGetHeaders());
89 var_dump(array("Foo" => "bar") === $test->getHeaders());
90 var_dump("bar" === $test->getHeader("foo"));
91 var_dump(false === $test->getHeader("bar"));
92 $parent = new message;
93 $test->testSetParentMessage($parent);
94 var_dump($parent === $test->testGetParentMessage());
95 var_dump($parent === $test->getParentMessage());
96
97 ?>
98 Done
99 --EXPECT--
100 Test
101 bool(true)
102 bool(true)
103 bool(true)
104 bool(true)
105 bool(true)
106 bool(true)
107 bool(true)
108 bool(true)
109 bool(true)
110 bool(true)
111 bool(true)
112 bool(true)
113 bool(true)
114 bool(true)
115 bool(true)
116 bool(true)
117 bool(true)
118 bool(true)
119 bool(true)
120 bool(true)
121 bool(true)
122 bool(true)
123 bool(true)
124 bool(true)
125 bool(true)
126 bool(true)
127 bool(true)
128 bool(true)
129 bool(true)
130 bool(true)
131 bool(true)
132 bool(true)
133 bool(true)
134 bool(true)
135 bool(true)
136 bool(true)
137 bool(true)
138 bool(true)
139 bool(true)
140 bool(true)
141 bool(true)
142 bool(true)
143 bool(true)
144 bool(true)
145 bool(true)
146 bool(true)
147 bool(true)
148 bool(true)
149 Done