test reafactoring; release beta5
authorMichael Wallner <mike@php.net>
Mon, 12 Aug 2013 19:49:55 +0000 (19:49 +0000)
committerMichael Wallner <mike@php.net>
Mon, 12 Aug 2013 19:49:55 +0000 (19:49 +0000)
67 files changed:
package.xml
php_http.h
phpunit/ClientTest.php [deleted file]
phpunit/HeaderTest.php [deleted file]
phpunit/MessageTest.php [deleted file]
phpunit/ObjectTest.php [deleted file]
tests/client011.phpt [new file with mode: 0644]
tests/client012.phpt [new file with mode: 0644]
tests/client013.phpt [new file with mode: 0644]
tests/clientrequest004.phpt
tests/envrequestheader001.phpt
tests/envresponse001.phpt [new file with mode: 0644]
tests/envresponse002.phpt [new file with mode: 0644]
tests/envresponse003.phpt [new file with mode: 0644]
tests/envresponse004.phpt [new file with mode: 0644]
tests/envresponse005.phpt [new file with mode: 0644]
tests/envresponse006.phpt [new file with mode: 0644]
tests/envresponse007.phpt [new file with mode: 0644]
tests/envresponse008.phpt [new file with mode: 0644]
tests/envresponse009.phpt [new file with mode: 0644]
tests/envresponse010.phpt [new file with mode: 0644]
tests/envresponse011.phpt [new file with mode: 0644]
tests/envresponse012.phpt [new file with mode: 0644]
tests/envresponse013.phpt [new file with mode: 0644]
tests/envresponse014.phpt [new file with mode: 0644]
tests/header001.phpt [new file with mode: 0644]
tests/header002.phpt [new file with mode: 0644]
tests/header003.phpt [new file with mode: 0644]
tests/header004.phpt [new file with mode: 0644]
tests/header005.phpt [new file with mode: 0644]
tests/header006.phpt [new file with mode: 0644]
tests/header007.phpt [new file with mode: 0644]
tests/header008.phpt [new file with mode: 0644]
tests/header009.phpt [new file with mode: 0644]
tests/message002.phpt
tests/message007.phpt [new file with mode: 0644]
tests/message008.phpt [new file with mode: 0644]
tests/message009.phpt [new file with mode: 0644]
tests/message010.phpt [new file with mode: 0644]
tests/message011.phpt [new file with mode: 0644]
tests/message012.phpt [new file with mode: 0644]
tests/message013.phpt [new file with mode: 0644]
tests/message014.phpt [new file with mode: 0644]
tests/message015.phpt [new file with mode: 0644]
tests/object001.phpt [new file with mode: 0644]
tests/object002.phpt [new file with mode: 0644]
tests/object003.phpt [new file with mode: 0644]
tests/object004.phpt [new file with mode: 0644]
tests/object005.phpt [new file with mode: 0644]
tests/object006.phpt [new file with mode: 0644]
tests/object007.phpt [new file with mode: 0644]
tests/object008.phpt [new file with mode: 0644]
tests/object009.phpt [new file with mode: 0644]
tests/response001.phpt [deleted file]
tests/response002.phpt [deleted file]
tests/response003.phpt [deleted file]
tests/response004.phpt [deleted file]
tests/response005.phpt [deleted file]
tests/response006.phpt [deleted file]
tests/response007.phpt [deleted file]
tests/response008.phpt [deleted file]
tests/response009.phpt [deleted file]
tests/response010.phpt [deleted file]
tests/response011.phpt [deleted file]
tests/response012.phpt [deleted file]
tests/response013.phpt [deleted file]
tests/response014.phpt [deleted file]

index 158a29c..a0b1a68 100644 (file)
@@ -28,9 +28,9 @@ support. Parallel requests are available for PHP 5 and greater.
   <email>mike@php.net</email>
   <active>yes</active>
  </lead>
- <date>2012-12-31</date>
+ <date>2013-08-12</date>
  <version>
-  <release>2.0.0dev</release>
+  <release>2.0.0beta5</release>
   <api>2.0.0</api>
  </version>
  <stability>
@@ -140,6 +140,9 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be
      <file role="test" name="client008.phpt"/>
      <file role="test" name="client009.phpt"/>
      <file role="test" name="client010.phpt"/>
+     <file role="test" name="client011.phpt"/>
+     <file role="test" name="client012.phpt"/>
+     <file role="test" name="client013.phpt"/>
      <file role="test" name="clientrequest001.phpt"/>
      <file role="test" name="clientrequest002.phpt"/>
      <file role="test" name="clientrequest003.phpt"/>
@@ -157,6 +160,20 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be
      <file role="test" name="envrequestjson001.phpt"/>
      <file role="test" name="envrequestjson002.phpt"/>
      <file role="test" name="envrequestquery.phpt"/>
+     <file role="test" name="envresponse001.phpt"/>
+     <file role="test" name="envresponse002.phpt"/>
+     <file role="test" name="envresponse003.phpt"/>
+     <file role="test" name="envresponse004.phpt"/>
+     <file role="test" name="envresponse005.phpt"/>
+     <file role="test" name="envresponse006.phpt"/>
+     <file role="test" name="envresponse007.phpt"/>
+     <file role="test" name="envresponse008.phpt"/>
+     <file role="test" name="envresponse009.phpt"/>
+     <file role="test" name="envresponse010.phpt"/>
+     <file role="test" name="envresponse011.phpt"/>
+     <file role="test" name="envresponse012.phpt"/>
+     <file role="test" name="envresponse013.phpt"/>
+     <file role="test" name="envresponse014.phpt"/>
      <file role="test" name="envresponsebody001.phpt"/>
      <file role="test" name="envresponsebody002.phpt"/>
      <file role="test" name="envresponsecodes.phpt"/>
@@ -165,6 +182,15 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be
      <file role="test" name="etag001.phpt"/>
      <file role="test" name="filterchunked.phpt"/>
      <file role="test" name="filterzlib.phpt"/>
+     <file role="test" name="header001.phpt"/>
+     <file role="test" name="header002.phpt"/>
+     <file role="test" name="header003.phpt"/>
+     <file role="test" name="header004.phpt"/>
+     <file role="test" name="header005.phpt"/>
+     <file role="test" name="header006.phpt"/>
+     <file role="test" name="header007.phpt"/>
+     <file role="test" name="header008.phpt"/>
+     <file role="test" name="header009.phpt"/>
      <file role="test" name="info_001.phpt"/>
      <file role="test" name="info.phpt"/>
      <file role="test" name="message001.phpt"/>
@@ -173,38 +199,38 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be
      <file role="test" name="message004.phpt"/>
      <file role="test" name="message005.phpt"/>
      <file role="test" name="message006.phpt"/>
+     <file role="test" name="message007.phpt"/>
+     <file role="test" name="message008.phpt"/>
+     <file role="test" name="message009.phpt"/>
+     <file role="test" name="message010.phpt"/>
+     <file role="test" name="message011.phpt"/>
+     <file role="test" name="message012.phpt"/>
+     <file role="test" name="message013.phpt"/>
+     <file role="test" name="message014.phpt"/>
+     <file role="test" name="message015.phpt"/>
      <file role="test" name="negotiate001.phpt"/>
+     <file role="test" name="object001.phpt"/>
+     <file role="test" name="object002.phpt"/>
+     <file role="test" name="object003.phpt"/>
+     <file role="test" name="object004.phpt"/>
+     <file role="test" name="object005.phpt"/>
+     <file role="test" name="object006.phpt"/>
+     <file role="test" name="object007.phpt"/>
+     <file role="test" name="object008.phpt"/>
+     <file role="test" name="object009.phpt"/>
      <file role="test" name="params001.phpt"/>
      <file role="test" name="params002.phpt"/>
      <file role="test" name="phpunit.phpt"/>
      <file role="test" name="propertyproxy001.phpt"/>
      <file role="test" name="querystring_001.phpt"/>
-     <file role="test" name="response001.phpt"/>
-     <file role="test" name="response002.phpt"/>
-     <file role="test" name="response003.phpt"/>
-     <file role="test" name="response004.phpt"/>
-     <file role="test" name="response005.phpt"/>
-     <file role="test" name="response006.phpt"/>
-     <file role="test" name="response007.phpt"/>
-     <file role="test" name="response008.phpt"/>
-     <file role="test" name="response009.phpt"/>
-     <file role="test" name="response010.phpt"/>
-     <file role="test" name="response011.phpt"/>
-     <file role="test" name="response012.phpt"/>
-     <file role="test" name="response013.phpt"/>
-     <file role="test" name="response014.phpt"/>
      <file role="test" name="serialize001.phpt"/>
      <file role="test" name="url001.phpt"/>
      <file role="test" name="version001.phpt"/>
    </dir>
    <dir name="phpunit">
-    <file role="test" name="ClientTest.php"/>
     <file role="test" name="CookieTest.php"/>
     <file role="test" name="EncodingTest.php"/>
-    <file role="test" name="HeaderTest.php"/>
-    <file role="test" name="MessageTest.php"/>
     <file role="test" name="MessageBodyTest.php"/>
-    <file role="test" name="ObjectTest.php"/>
     <file role="test" name="ParamsTest.php"/>
     <file role="test" name="QueryStringTest.php"/>
     <file role="test" name="UrlTest.php"/>
index bb9c2d0..68f4293 100644 (file)
@@ -13,7 +13,7 @@
 #ifndef PHP_EXT_HTTP_H
 #define PHP_EXT_HTTP_H
 
-#define PHP_HTTP_EXT_VERSION "2.0.0dev"
+#define PHP_HTTP_EXT_VERSION "2.0.0beta5"
 
 zend_module_entry http_module_entry;
 #define phpext_http_ptr &http_module_entry
diff --git a/phpunit/ClientTest.php b/phpunit/ClientTest.php
deleted file mode 100644 (file)
index 21493f3..0000000
+++ /dev/null
@@ -1,182 +0,0 @@
-<?php
-
-class ProgressObserver1 implements SplObserver {
-    function update(SplSubject $c, $r = null) {
-        if ($c->getProgressInfo($r)) $c->pi .= "-";
-    }
-}
-class ProgressObserver2 implements SplObserver {
-    function update(SplSubject $c, $r = null) {
-        if ($c->getProgressInfo($r)) $c->pi .= ".";
-    }
-}
-class CallbackObserver implements SplObserver {
-    public $callback;
-    function __construct($callback) {
-        $this->callback = $callback;
-    }
-    function update(SplSubject $c, $r = null) {
-        call_user_func($this->callback, $c, $r);
-    } 
-}
-
-class RequestTest extends PHPUnit_Framework_TestCase
-{
-    /**
-     * @var http\Client
-     */
-    protected $r;
-
-    function setUp() {
-        $this->r = new http\Client;
-        $this->r->pi = "";
-        $this->r->setOptions(
-            array(
-                "connecttimeout"    => 30,
-                "timeout"           => 300,
-            )
-        );
-        $this->r->setOptions(
-               array(
-                       "timeout" => 600
-               )
-        );
-        $this->assertEquals(
-               array(
-                       "connecttimeout" => 30,
-                       "timeout" => 600,
-               ),
-               $this->r->getOptions()
-        );
-    }
-
-    function testObserver() {
-               $test = $this;
-        $this->r->attach($o1 = new ProgressObserver1);
-        $this->r->attach($o2 = new ProgressObserver2);
-        $this->r->attach(
-            $o3 = new CallbackObserver(
-                function ($c, $r) use ($test) {
-                    $p = (array) $c->getProgressInfo($r);
-                    $test->assertArrayHasKey("started", $p);
-                    $test->assertArrayHasKey("finished", $p);
-                    $test->assertArrayHasKey("dlnow", $p);
-                    $test->assertArrayHasKey("ulnow", $p);
-                    $test->assertArrayHasKey("dltotal", $p);
-                    $test->assertArrayHasKey("ultotal", $p);
-                    $test->assertArrayHasKey("info", $p);
-                }
-            )
-        );
-        $this->r->enqueue(new http\Client\Request("GET", "http://dev.iworks.at/ext-http/"))->send();
-        $this->assertRegexp("/(\.-)+/", $this->r->pi);
-        $this->assertCount(3, $this->r->getObservers());
-        $this->r->detach($o1);
-        $this->assertCount(2, $this->r->getObservers());
-        $this->r->detach($o2);
-        $this->assertCount(1, $this->r->getObservers());
-        $this->r->detach($o3);
-        $this->assertCount(0, $this->r->getObservers());
-    }
-
-    function testSsl() {
-       $this->r->setSslOptions(array("verify_peer" => true));
-       $this->r->addSslOptions(array("verify_host" => 2));
-       $this->assertEquals(
-               array(
-                       "verify_peer" => true,
-                       "verify_host" => 2,
-               ),
-               $this->r->getSslOptions()
-       );
-       $this->r->enqueue($req = new http\Client\Request("GET", "https://twitter.com/"));
-       $this->r->send();
-       $ti = $this->r->getTransferInfo($req);
-       $this->assertArrayHasKey("ssl_engines", $ti);
-       $this->assertGreaterThan(0, count($ti["ssl_engines"])); 
-    }
-
-    function testHistory() {
-        $body = new http\Message\Body;
-        $body->append("foobar");
-
-        $request = new http\Client\Request;
-        $request->setBody($body);
-        $request->setRequestMethod("POST");
-        $request->setRequestUrl("http://dev.iworks.at/ext-http/.print_request.php");
-
-        $this->r->recordHistory = true;
-        $this->r->enqueue($request)->send();
-
-        $this->assertStringMatchesFormat(<<<HTTP
-POST /ext-http/.print_request.php HTTP/1.1
-User-Agent: %s
-Host: dev.iworks.at
-Accept: */*
-Content-Length: 6
-Content-Type: application/x-www-form-urlencoded
-X-Original-Content-Length: 6
-
-foobar
-HTTP/1.1 200 OK
-Date: %s
-Server: %s
-Vary: %s
-Content-Length: 19
-Content-Type: text/html
-X-Original-Content-Length: 19
-
-string(6) "foobar"
-
-HTTP
-        , str_replace("\r", "", $this->r->getHistory()->toString(true))
-        );
-
-
-        $this->r->requeue($request)->send();
-
-        $this->assertStringMatchesFormat(<<<HTTP
-POST /ext-http/.print_request.php HTTP/1.1
-User-Agent: %s
-Host: dev.iworks.at
-Accept: */*
-Content-Length: 6
-Content-Type: application/x-www-form-urlencoded
-X-Original-Content-Length: 6
-
-foobar
-HTTP/1.1 200 OK
-Date: %s
-Server: %s
-Vary: %s
-Content-Length: 19
-Content-Type: text/html
-X-Original-Content-Length: 19
-
-string(6) "foobar"
-
-POST /ext-http/.print_request.php HTTP/1.1
-User-Agent: %s
-Host: dev.iworks.at
-Accept: */*
-Content-Length: 6
-Content-Type: application/x-www-form-urlencoded
-X-Original-Content-Length: 6
-
-foobar
-HTTP/1.1 200 OK
-Date: %s
-Server: %s
-Vary: %s
-Content-Length: 19
-Content-Type: text/html
-X-Original-Content-Length: 19
-
-string(6) "foobar"
-
-HTTP
-        , str_replace("\r", "", $this->r->getHistory()->toString(true))
-        );
-    }
-}
-
diff --git a/phpunit/HeaderTest.php b/phpunit/HeaderTest.php
deleted file mode 100644 (file)
index 184f21a..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-<?php
-
-class HeaderTest extends PHPUnit_Framework_TestCase {
-    function setUp() {
-        
-    }
-    function testString() {
-       $h = new http\Header("foo", "bar");
-        $this->assertEquals("Foo: bar", (string) $h);
-    }
-
-    function testSerialize() {
-               $h = new http\Header("foo", "bar");
-               $this->assertEquals("Foo: bar", (string) unserialize(serialize($h)));
-    }
-
-       function testNumeric() {
-               $h = new http\Header(123, 456);
-        $this->assertEquals("123: 456", (string) $h);
-               $this->assertEquals("123: 456", (string) unserialize(serialize($h)));
-       }
-       
-    function testMatch() {
-        $ae = new http\Header("Accept-encoding", "gzip, deflate");
-        $this->assertTrue($ae->match("gzip", http\Header::MATCH_WORD));
-        $this->assertTrue($ae->match("gzip", http\Header::MATCH_WORD|http\Header::MATCH_CASE));
-        $this->assertFalse($ae->match("gzip", http\Header::MATCH_STRICT));
-        $this->assertTrue($ae->match("deflate", http\Header::MATCH_WORD));
-        $this->assertTrue($ae->match("deflate", http\Header::MATCH_WORD|http\Header::MATCH_CASE));
-        $this->assertFalse($ae->match("deflate", http\Header::MATCH_STRICT));
-
-        $this->assertFalse($ae->match("zip", http\Header::MATCH_WORD));
-        $this->assertFalse($ae->match("gzip", http\Header::MATCH_FULL));
-    }
-    
-    function testNegotiate() {
-       $a = new http\Header("Accept", "text/html, text/plain;q=0.5, */*;q=0");
-       $this->assertEquals("text/html", $a->negotiate(array("text/plain","text/html")));
-       $this->assertEquals("text/html", $a->negotiate(array("text/plain","text/html"), $rs));
-       $this->assertEquals(array("text/html"=>0.99, "text/plain"=>0.5), $rs);
-       $this->assertEquals("text/plain", $a->negotiate(array("foo/bar", "text/plain"), $rs));
-       $this->assertEquals(array("text/plain"=>0.5), $rs);
-       $this->assertEquals("foo/bar", $a->negotiate(array("foo/bar"), $rs));
-       $this->assertEquals(array(), $rs);
-    }
-    
-    function testParse() {
-       $header = "Foo: bar\nBar: foo\n";
-       $this->assertEquals(array("Foo"=>"bar","Bar"=>"foo"), http\Header::parse($header)); 
-       $headers = http\Header::parse($header, "http\\Header");
-       $this->assertCount(2, $headers);
-       $this->assertContainsOnlyInstancesOf("http\\Header", $headers); 
-    }
-    
-    function testParseError() {
-       $header = "wass\nup";
-       $this->setExpectedException("PHPUnit_Framework_Error_Warning", "Could not parse headers");
-       $this->assertFalse(http\Header::parse($header));
-    }
-       
-       function testParams() {
-               $header = new http\Header("Cache-control", "public, must-revalidate, max-age=0");
-               $this->assertEquals(
-                       array(
-                               "public" => array("value" => true, "arguments" => array()),
-                               "must-revalidate" => array("value" => true, "arguments" => array()),
-                               "max-age" => array("value" => 0, "arguments" => array()),
-                       ),
-                       $header->getParams()->params
-               );
-       }
-       
-       function testParamsWithArgs() {
-               $header = new http\Header("Custom", '"foo" is "bar". "bar" is "bis" where "bis" is "where".');
-               $this->assertEquals(
-                       array(
-                               "foo" => array("value" => "bar", "arguments" => array()),
-                               "bar" => array("value" => "bis", "arguments" => array("bis" => "where"))
-                       ),
-                       $header->getParams(".", "where", "is")->params
-               );
-       }
-}
diff --git a/phpunit/MessageTest.php b/phpunit/MessageTest.php
deleted file mode 100644 (file)
index b572f57..0000000
+++ /dev/null
@@ -1,283 +0,0 @@
-<?php
-
-class strval {
-       private $str;
-       function __construct($str) {
-               $this->str = $str;
-       }
-       function __toString() {
-               return (string) $this->str;
-       }
-}
-
-class message extends http\Message {
-       function __call($m, $args) {
-               if (preg_match("/^test(get|set)(.*)\$/i", $m, $match)) {
-                       list(, $getset, $prop) = $match;
-                       $prop = strtolower($prop[0]).substr($prop,1);
-                       switch(strtolower($getset)) {
-                       case "get":
-                               return $this->$prop;
-                       case "set":
-                               $this->$prop = current($args);
-                               break;
-                       }
-               }
-       }
-}
-
-class MessageTest extends PHPUnit_Framework_TestCase
-{
-       function testProperties() {
-               $test = new message;
-               $this->assertEquals(0, $test->testGetType());
-               $this->assertEquals(null, $test->testGetBody());
-               $this->assertEquals("", $test->testGetRequestMethod());
-               $this->assertEquals("", $test->testGetRequestUrl());
-               $this->assertEquals("", $test->testGetResponseStatus());
-               $this->assertEquals(0, $test->testGetResponseCode());
-               $this->assertEquals("1.1", $test->testGetHttpVersion());
-               $this->assertEquals(array(), $test->testGetHeaders());
-               $this->assertEquals(null, $test->testGetParentMessage());
-               $test->testSetType(http\Message::TYPE_REQUEST);
-               $this->assertEquals(http\Message::TYPE_REQUEST, $test->testGetType());
-               $this->assertEquals(http\Message::TYPE_REQUEST, $test->getType());
-               $body = new http\Message\Body;
-               $test->testSetBody($body);
-               $this->assertEquals($body, $test->testGetBody());
-               $this->assertEquals($body, $test->getBody());
-               $file = fopen(__FILE__,"r");
-               $test->testSetBody($file);
-               $this->assertEquals($file, $test->testGetBody()->getResource());
-               $this->assertEquals($file, $test->getBody()->getResource());
-               $test->testSetBody("data");
-               $this->assertEquals("data", (string) $test->testGetBody());
-               $this->assertEquals("data", (string) $test->getBody());
-               $test->testSetRequestMethod("HEAD");
-               $this->assertEquals("HEAD", $test->testGetRequestMethod());
-               $this->assertEquals("HEAD", $test->getRequestMethod());
-               $test->testSetRequestUrl("/");
-               $this->assertEquals("/", $test->testGetRequestUrl());
-               $this->assertEquals("/", $test->getRequestUrl());
-               $this->assertEquals("HEAD / HTTP/1.1", $test->getInfo());
-               $test->testSetType(http\Message::TYPE_RESPONSE);
-               $test->setResponseStatus("Created");
-               $this->assertEquals("Created", $test->testGetResponseStatus());
-               $this->assertEquals("Created", $test->getResponseStatus());
-               $test->setResponseCode(201);
-               $this->assertEquals(201, $test->testGetResponseCode());
-               $this->assertEquals(201, $test->getResponseCode());
-               $test->testSetResponseStatus("Ok");
-               $this->assertEquals("Ok", $test->testGetResponseStatus());
-               $this->assertEquals("Ok", $test->getResponseStatus());
-               $test->testSetResponseCode(200);
-               $this->assertEquals(200, $test->testGetResponseCode());
-               $this->assertEquals(200, $test->getResponseCode());
-               $test->testSetHttpVersion("1.0");
-               $this->assertEquals("1.0", $test->testGetHttpVersion());
-               $this->assertEquals("1.0", $test->getHttpVersion());
-               $this->assertEquals("HTTP/1.0 200 OK", $test->getInfo());
-               $test->setHttpVersion("1.1");
-               $this->assertEquals("1.1", $test->testGetHttpVersion());
-               $this->assertEquals("1.1", $test->getHttpVersion());
-               $this->assertEquals("HTTP/1.1 200 OK", $test->getInfo());
-               $test->setInfo("HTTP/1.1 201 Created");
-               $this->assertEquals("Created", $test->testGetResponseStatus());
-               $this->assertEquals("Created", $test->getResponseStatus());
-               $this->assertEquals(201, $test->testGetResponseCode());
-               $this->assertEquals(201, $test->getResponseCode());
-               $this->assertEquals("1.1", $test->testGetHttpVersion());
-               $this->assertEquals("1.1", $test->getHttpVersion());
-               $test->testSetHeaders(array("Foo" => "bar"));
-               $this->assertEquals(array("Foo" => "bar"), $test->testGetHeaders());
-               $this->assertEquals(array("Foo" => "bar"), $test->getHeaders());
-               $this->assertEquals("bar", $test->getHeader("foo"));
-               $this->assertEquals(null, $test->getHeader("bar"));
-               $parent = new message;
-               $test->testSetParentMessage($parent);
-               $this->assertEquals($parent, $test->testGetParentMessage());
-               $this->assertEquals($parent, $test->getParentMessage());
-       }
-       
-       function testAddBody() {
-               $m = new http\Message;
-               $body = new http\Message\Body;
-               $body->append("foo");
-               $m->addBody($body);
-               $body = new http\Message\Body;
-               $body->append("bar");
-               $m->addBody($body);
-               $this->assertEquals("foobar", (string) $m->getBody());
-       }
-       
-       function testAddHeaders() {
-               $m = new http\Message;
-               $m->addHeaders(array("foo"=>"bar","bar"=>"foo"));
-               $this->assertEquals(array("Foo"=>"bar","Bar"=>"foo"), $m->getHeaders());
-               $m->addHeaders(array("key"=>"val","more"=>"Stuff"));
-               $this->assertEquals(array("Foo"=>"bar","Bar"=>"foo","Key"=>"val","More"=>"Stuff"), $m->getHeaders());
-       }
-       
-       function testArrayHeaders() {
-               $m = new http\Message("GET / HTTP/1.1");
-               $m->addHeader("Accept", "text/html");
-               $m->addHeader("Accept", "text/xml;q=0");
-               $m->addHeader("Accept", "text/plain;q=0.5");
-               $this->assertEquals(
-                       "GET / HTTP/1.1\r\n".
-                       "Accept: text/html, text/xml;q=0, text/plain;q=0.5\r\n",
-                       $m->toString()
-               );
-       }
-       
-       function testHeaderValueTypes() {
-               $m = new http\Message("HTTP/1.1 200 Ok");
-               $m->addHeader("Bool", true);
-               $m->addHeader("Int", 123);
-               $m->addHeader("Float", 1.23);
-               $m->addHeader("Array", array(1,2,3));
-               $m->addHeader("Object", new strval("test"));
-               $m->addHeader("Set-Cookie", 
-                       array(
-                               array(
-                                       "cookies" => array("foo" => "bar"),
-                                       "expires" => date_create("2012-12-31 22:59:59 GMT")->format(
-                                               DateTime::COOKIE
-                                       ),
-                                       "path" => "/somewhere"
-                               )
-                       )
-               );
-               $m->addHeader("Set-Cookie", "val=0");
-               
-               $this->assertEquals(
-                       "HTTP/1.1 200 Ok\r\n".
-                       "Bool: true\r\n".
-                       "Int: 123\r\n".
-                       "Float: 1.23\r\n".
-                       "Array: 1, 2, 3\r\n".
-                       "Object: test\r\n".
-                       "Set-Cookie: foo=bar; path=/somewhere; expires=Mon, 31 Dec 2012 22:59:59 GMT; \r\n".
-                       "Set-Cookie: val=0\r\n",
-                       $m->toString()
-               );
-       }
-       
-       function testDetach() {
-               $m = new http\Message(
-                       "HTTP/1.1 200 Ok\r\n".
-                       "HTTP/1.1 201 Created\n".
-                       "HTTP/1.1 302 Found\r\n"
-               );
-               
-               $this->assertCount(3, $m);
-               $d = $m->detach();
-               $this->assertCount(3, $m);
-               $this->assertCount(1, $d);
-               
-               $this->assertEquals("HTTP/1.1 302 Found\r\n\r\n", $d->toString(true));
-       }
-       
-       function testPrepend() {
-               for ($i=0; $i<9; ++$i) {
-                       $a[] = new http\Message("HTTP/1.1 ".($i+200));
-               }
-               
-               foreach ($a as $m) {
-                       if (isset($p)) $m->prepend($p);
-                       $p = $m;
-               }
-               
-               $this->assertEquals(
-                       "HTTP/1.1 200\r\n\r\n".
-                       "HTTP/1.1 201\r\n\r\n".
-                       "HTTP/1.1 202\r\n\r\n".
-                       "HTTP/1.1 203\r\n\r\n".
-                       "HTTP/1.1 204\r\n\r\n".
-                       "HTTP/1.1 205\r\n\r\n".
-                       "HTTP/1.1 206\r\n\r\n".
-                       "HTTP/1.1 207\r\n\r\n".
-                       "HTTP/1.1 208\r\n\r\n",
-                       $m->toString(true)
-               );
-       }
-       
-       function testEmptyUrlWarning() {
-               $m = new http\Message;
-               $this->setExpectedException("PHPUnit_Framework_Error_Notice");
-               $m->setRequestUrl("/foo");
-               $m->setType(http\Message::TYPE_REQUEST);
-               $this->setExpectedException("PHPUnit_Framework_Error_Warning");
-               $m->setRequestUrl("");
-       }
-       
-       function testEmptyParentMessage() {
-               $m = new http\Message;
-               try {
-                       $m->getParentMessage();
-                       $this->assertFalse("this code should not be reached");
-               } catch (http\Exception $e) {
-                       $this->assertEquals("HttpMessage does not have a parent message", $e->getMessage());
-               }
-       }
-       
-       function testPrependError() {
-               $m = new http\Message("HTTP/1.1 200\r\nHTTP/1.1 201");
-               try {
-                       $m->prepend($m->getParentMessage());
-                       $this->assertFalse("this code should not be reached");
-               } catch (http\Exception $e) {
-                       $this->assertEquals("Cannot prepend a message located within the same message chain", $e->getMessage());
-               }
-       }
-       
-       function testToCallback() {
-               $m = new http\Message("HTTP/1.1 200 Ok");
-               $m->addHeader("Content-Type", "text/plain");
-               $m->getBody()->append("this\nis\nthe\ntext");
-               
-               $d = new http\Encoding\Stream\Deflate;
-               $s = "";
-               $m->toCallback(function ($m, $data) use ($d, &$s) {
-                       $s.=$d->update($data);
-               });
-               $s.=$d->finish();
-               $this->assertEquals($m->toString(), http\Encoding\Stream\Inflate::decode($s));
-       }
-       
-       function testToStream() {
-               $m = new http\Message("HTTP/1.1 200 Ok");
-               $m->addHeader("Content-Type", "text/plain");
-               $m->getBody()->append("this\nis\nthe\ntext");
-               
-               $f = tmpfile();
-               $m->toStream($f);
-               rewind($f);
-               $this->assertEquals((string) $m, stream_get_contents($f));
-               fclose($f);
-       }
-       
-       function testBoundary() {
-               $p = new http\Message;
-               $p->addHeader("Content-Type", "text/plain");
-               $p->getBody()->append("data");
-               
-               $m = new http\Message("HTTP/1.1 200");
-               $m->getBody()->addPart($p);
-               $this->assertStringMatchesFormat(
-                       "HTTP/1.1 200\r\n".
-                       "Content-Length: %d\r\n".
-                       "Content-Type: multipart/form-data; boundary=\"%x.%x\"\r\n".
-                       "\r\n".
-                       "--%x.%x\r\n".
-                       "Content-Type: text/plain\r\n".
-                       "Content-Length: 4\r\n".
-                       "\r\n".
-                       "data\r\n".
-                       "--%x.%x--\r\n".
-                       "", 
-                       str_replace("\r", "", $m->toString()) // phpunit replaces \r\n with \n
-               );
-       }
-}
-
diff --git a/phpunit/ObjectTest.php b/phpunit/ObjectTest.php
deleted file mode 100644 (file)
index 968f3f8..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-<?php
-
-class eh extends http\Object {
-}
-
-class ObjectTest extends PHPUnit_Framework_TestCase {
-    function testDefaultErrorHandling() {
-        $this->assertEquals(http\Object::EH_NORMAL, http\Object::getDefaultErrorHandling());
-        http\Object::setDefaultErrorHandling(http\Object::EH_SUPPRESS);
-        $this->assertEquals(http\Object::EH_SUPPRESS, http\Object::getDefaultErrorHandling());
-    }
-
-    function testErrorHandling() {
-        $eh = new eh;
-        $this->assertEquals(eh::EH_NORMAL, $eh->getErrorHandling());
-        $eh->setErrorHandling(eh::EH_SUPPRESS);
-        $this->assertEquals(eh::EH_SUPPRESS, $eh->getErrorHandling());
-    }
-
-    function testSuppress() {
-        http\Object::setDefaultErrorHandling(http\Object::EH_SUPPRESS);
-        $o = new eh;
-               $o->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "suppress");
-    }
-
-    function testException() {
-        http\Object::setDefaultErrorHandling(http\Object::EH_THROW);
-        $this->setExpectedException("http\\Exception");
-        $o = new eh;
-               $o->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "exception");
-    }
-
-    function testNormalError() {
-        http\Object::setDefaultErrorHandling(http\Object::EH_NORMAL);
-        $this->setExpectedException("PHPUnit_Framework_Error_Warning");
-        $o = new eh;
-               $o->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "warning");
-    }
-
-    function testSuppress2() {
-        $eh = new eh;
-        $eh->setErrorHandling(http\Object::EH_SUPPRESS);
-        $eh->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "suppress");
-    }
-
-    function testException2() {
-        $eh = new eh;
-        $eh->setErrorHandling(http\Object::EH_THROW);
-        $this->setExpectedException("http\\Exception");
-        $eh->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "exception");
-    }
-
-    function testNormalError2() {
-        $eh = new eh;
-        $eh->setErrorHandling(http\Object::EH_NORMAL);
-        $this->setExpectedException("PHPUnit_Framework_Error_Warning");
-        $eh->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "warning");
-    }
-
-    function testUnknownDefaultErrorHandling() {
-        $this->setExpectedException("PHPUnit_Framework_Error_Warning");
-        http\Object::setDefaultErrorHandling(12345);
-    }
-
-    function testUnknownErrorHandling() {
-        $eh = new eh;
-        $this->setExpectedException("PHPUnit_Framework_Error_Warning");
-        $eh->setErrorHandling(12345);
-    }
-}
-
diff --git a/tests/client011.phpt b/tests/client011.phpt
new file mode 100644 (file)
index 0000000..188b178
--- /dev/null
@@ -0,0 +1,90 @@
+--TEST--
+client history
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php 
+
+echo "Test\n";
+
+$body = new http\Message\Body;
+$body->append("foobar");
+
+$request = new http\Client\Request;
+$request->setBody($body);
+$request->setRequestMethod("POST");
+$request->setRequestUrl("http://dev.iworks.at/ext-http/.print_request.php");
+
+$client = new http\Client;
+$client->recordHistory = true;
+
+$client->enqueue($request)->send();
+echo $client->getHistory()->toString(true);
+
+$client->requeue($request)->send();
+echo $client->getHistory()->toString(true);
+
+?>
+Done
+--EXPECTF--
+Test
+POST /ext-http/.print_request.php HTTP/1.1
+User-Agent: %s
+Host: dev.iworks.at
+Accept: */*
+Content-Length: 6
+Content-Type: application/x-www-form-urlencoded
+X-Original-Content-Length: 6
+
+foobar
+HTTP/1.1 200 OK
+Date: %s
+Server: %s
+Vary: %s
+Content-Length: 19
+Content-Type: text/html
+X-Original-Content-Length: 19
+
+string(6) "foobar"
+
+POST /ext-http/.print_request.php HTTP/1.1
+User-Agent: %s
+Host: dev.iworks.at
+Accept: */*
+Content-Length: 6
+Content-Type: application/x-www-form-urlencoded
+X-Original-Content-Length: 6
+
+foobar
+HTTP/1.1 200 OK
+Date: %s
+Server: %s
+Vary: %s
+Content-Length: 19
+Content-Type: text/html
+X-Original-Content-Length: 19
+
+string(6) "foobar"
+
+POST /ext-http/.print_request.php HTTP/1.1
+User-Agent: %s
+Host: dev.iworks.at
+Accept: */*
+Content-Length: 6
+Content-Type: application/x-www-form-urlencoded
+X-Original-Content-Length: 6
+
+foobar
+HTTP/1.1 200 OK
+Date: %s
+Server: %s
+Vary: %s
+Content-Length: 19
+Content-Type: text/html
+X-Original-Content-Length: 19
+
+string(6) "foobar"
+
+Done
diff --git a/tests/client012.phpt b/tests/client012.phpt
new file mode 100644 (file)
index 0000000..f9ae690
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+client ssl
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php 
+
+echo "Test\n";
+
+$client = new http\Client;
+
+$client->setSslOptions(array("verify_peer" => true));
+$client->addSslOptions(array("verify_host" => 2));
+var_dump(
+       array(
+               "verify_peer" => true,
+               "verify_host" => 2,
+       ) === $client->getSslOptions()
+);
+
+$client->enqueue($req = new http\Client\Request("GET", "https://twitter.com/"));
+$client->send();
+
+$ti = $client->getTransferInfo($req);
+var_dump(array_key_exists("ssl_engines", $ti));
+var_dump(0 < count($ti["ssl_engines"]));
+?>
+Done
+--EXPECTF--
+Test
+bool(true)
+bool(true)
+bool(true)
+Done
diff --git a/tests/client013.phpt b/tests/client013.phpt
new file mode 100644 (file)
index 0000000..0de0547
--- /dev/null
@@ -0,0 +1,66 @@
+--TEST--
+client observers
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php 
+
+echo "Test\n";
+
+class Client extends http\Client {
+       public $pi;
+}
+class ProgressObserver1 implements SplObserver {
+       function update(SplSubject $c, $r = null) {
+               if ($c->getProgressInfo($r)) $c->pi .= "-";
+       }
+}
+class ProgressObserver2 implements SplObserver {
+       function update(SplSubject $c, $r = null) {
+               if ($c->getProgressInfo($r)) $c->pi .= ".";
+       }
+}
+class CallbackObserver implements SplObserver {
+       public $callback;
+       function __construct($callback) {
+               $this->callback = $callback;
+       }
+       function update(SplSubject $c, $r = null) {
+               call_user_func($this->callback, $c, $r);
+       }
+}
+
+$client = new Client;
+$client->attach($o1 = new ProgressObserver1);
+$client->attach($o2 = new ProgressObserver2);
+$client->attach(
+               $o3 = new CallbackObserver(
+                               function ($c, $r) {
+                                       $p = (array) $c->getProgressInfo($r);
+                                       var_dump(array_key_exists("started", $p));
+                                       var_dump(array_key_exists("finished", $p));
+                                       var_dump(array_key_exists("dlnow", $p));
+                                       var_dump(array_key_exists("ulnow", $p));
+                                       var_dump(array_key_exists("dltotal", $p));
+                                       var_dump(array_key_exists("ultotal", $p));
+                                       var_dump(array_key_exists("info", $p));
+                               }
+               )
+);
+
+$client->enqueue(new http\Client\Request("GET", "http://dev.iworks.at/ext-http/"))->send();
+var_dump(1 === preg_match("/(\.-)+/", $client->pi));
+var_dump(3 === count($client->getObservers()));
+$client->detach($o1);
+var_dump(2 === count($client->getObservers()));
+$client->detach($o2);
+var_dump(1 === count($client->getObservers()));
+$client->detach($o3);
+var_dump(0 === count($client->getObservers()));
+
+?>
+Done
+--EXPECTREGEX--
+Test\n(bool\(true\)\n)+Done
index abff8d9..f00ee2e 100644 (file)
@@ -12,6 +12,9 @@ echo "Test\n";
 $r = new http\Client\Request("GET", "http://localhost");
 var_dump($r === $r->setOptions($o = array("redirect"=>5, "timeout"=>5)));
 var_dump($o === $r->getOptions());
+var_dump($r === $r->setOptions(array("timeout"=>50)));
+$o["timeout"] = 50;
+var_dump($o === $r->getOptions());
 var_dump($r === $r->setSslOptions($o = array("verify_peer"=>false)));
 var_dump($o === $r->getSslOptions());
 
@@ -23,4 +26,6 @@ bool(true)
 bool(true)
 bool(true)
 bool(true)
+bool(true)
+bool(true)
 Done
index 2a6a940..b259ea5 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-request header
+env request header
 --SKIPIF--
 <? include "skipif.inc";
 --POST--
diff --git a/tests/envresponse001.phpt b/tests/envresponse001.phpt
new file mode 100644 (file)
index 0000000..9d55a5b
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+env response message
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--POST--
+a=b
+--ENV--
+HTTP_ACCEPT_ENCODING=gzip
+--FILE--
+<?php
+
+$r = new http\env\Response;
+$r->setHeader("foo","bar");
+$r->setContentEncoding(http\env\Response::CONTENT_ENCODING_GZIP);
+$r->setBody(new http\message\Body(fopen(__FILE__,"r")));
+$r->send();
+
+--EXPECTHEADERS--
+Foo: bar
+Content-Encoding: gzip
+Vary: Accept-Encoding
+--EXPECTREGEX--
+^\x1f\x8b\x08.+
diff --git a/tests/envresponse002.phpt b/tests/envresponse002.phpt
new file mode 100644 (file)
index 0000000..e11f7bb
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+env response cache negative
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--GET--
+a=b
+--ENV--
+HTTP_IF_MODIFIED_SINCE=Fri, 13 Feb 2009 23:31:30 GMT
+HTTP_IF_NONE_MATCH=0000-00-0000
+--FILE--
+<?php
+$r = new http\Env\Response;
+$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
+$r->setEtag("abc");
+$r->setLastModified(1234567891);
+$r->send();
+?>
+--EXPECTHEADERS--
+ETag: "abc"
+Last-Modified: Fri, 13 Feb 2009 23:31:31 GMT
+--EXPECT--
+<?php
+$r = new http\Env\Response;
+$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
+$r->setEtag("abc");
+$r->setLastModified(1234567891);
+$r->send();
+?>
diff --git a/tests/envresponse003.phpt b/tests/envresponse003.phpt
new file mode 100644 (file)
index 0000000..3bbf760
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+env response ranges
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--ENV--
+HTTP_RANGE=bytes=2-4
+--GET--
+a=b
+--FILE--
+<?php
+
+$r = new http\Env\Response;
+$r->setContentType("text/plain");
+$r->setContentDisposition(
+    array("attachment" => array(array("filename" => basename(__FILE__))))
+);
+$r->setBody(new http\Message\Body(fopen(__FILE__, "rb")));
+$r->send();
+
+?>
+--EXPECTHEADERS--
+Content-Type: text/plain
+--EXPECTF--
+php
diff --git a/tests/envresponse004.phpt b/tests/envresponse004.phpt
new file mode 100644 (file)
index 0000000..f84c860
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+env reponse callback
+--SKIPIF--
+<?php
+include "skipif.inc";
+if (version_compare(PHP_VERSION, "5.4.0", "<")) die("SKIP 5.3 ob is broken");
+?>
+--GET--
+dummy=1
+--FILE--
+<?php
+
+$r = new http\Env\Response;
+$r->setCacheControl("public,must-revalidate,max-age=0");
+$r->setThrottleRate(1, 0.1);
+ob_start($r);
+
+echo "foo";
+echo "bar";
+
+ob_end_flush();
+$r->send();
+--EXPECTHEADERS--
+Accept-Ranges: bytes
+Cache-Control: public,must-revalidate,max-age=0
+ETag: "9ef61f95"
+--EXPECTF--
+foobar
diff --git a/tests/envresponse005.phpt b/tests/envresponse005.phpt
new file mode 100644 (file)
index 0000000..6d55168
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+env response cache positive
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--GET--
+a=b
+--ENV--
+HTTP_IF_MODIFIED_SINCE=Fri, 13 Feb 2009 23:31:32 GMT
+--FILE--
+<?php
+$r = new http\Env\Response;
+$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
+$r->setEtag("abc");
+$r->setLastModified(1234567891);
+$r->isCachedByEtag("If-None-Match") and die("Huh? etag? really?\n");
+$r->isCachedByLastModified("If-Modified-Since") or die("yep, I should be cached");
+$r->send();
+?>
+--EXPECTHEADERS--
+HTTP/1.1 304 Not Modified
+ETag: "abc"
+Last-Modified: Fri, 13 Feb 2009 23:31:31 GMT
+--EXPECT--
diff --git a/tests/envresponse006.phpt b/tests/envresponse006.phpt
new file mode 100644 (file)
index 0000000..76141c1
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+env response stream
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$f = tmpfile();
+
+$r = new http\Env\Response;
+$r->addHeader("foo", array("bar","baz"));
+$r->getBody()->append("foo");
+
+$r->send($f);
+
+rewind($f);
+var_dump(stream_get_contents($f));
+?>
+Done
+--EXPECT--
+Test
+string(77) "HTTP/1.1 200 OK
+Accept-Ranges: bytes
+Foo: bar, baz
+ETag: "8c736521"
+
+foo"
+Done
diff --git a/tests/envresponse007.phpt b/tests/envresponse007.phpt
new file mode 100644 (file)
index 0000000..5495fe2
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+env response env request
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--GET--
+dummy=1
+--FILE--
+<?php
+echo "Test\n";
+
+$tmp = tmpfile();
+
+// modify HTTP env
+$req = new http\Env\Request;
+$req->setHeader("Range", "bytes=2-4");
+
+$res = new http\Env\Response;
+$res->setEnvRequest($req);
+$res->setContentType("text/plain");
+$res->getBody()->append("012345679");
+$res->send($tmp);
+
+rewind($tmp);
+var_dump(stream_get_contents($tmp));
+
+?>
+Done
+--EXPECTF--
+Test
+string(%d) "HTTP/1.1 206 Partial Content%c
+Accept-Ranges: bytes%c
+X-Powered-By: %s%c
+Content-Type: text/plain%c
+Content-Range: bytes 2-4/9%c
+%c
+234"
+Done
diff --git a/tests/envresponse008.phpt b/tests/envresponse008.phpt
new file mode 100644 (file)
index 0000000..379ab57
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+env response stream message
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--ENV--
+HTTP_ACCEPT_ENCODING=gzip
+--FILE--
+<?php
+
+$f = tmpfile();
+
+$r = new http\env\Response;
+$r->setHeader("foo","bar");
+$r->setContentEncoding(http\env\Response::CONTENT_ENCODING_GZIP);
+$r->setBody(new http\message\Body(fopen(__FILE__,"r")));
+$r->send($f);
+
+rewind($f);
+var_dump(stream_get_contents($f));
+
+--EXPECTREGEX--
+string\(\d+\) "HTTP\/1\.1 200 OK
+Accept-Ranges: bytes
+Foo: bar
+Content-Encoding: gzip
+Vary: Accept-Encoding
+ETag: "\w+-\w+-\w+"
+Last-Modified: \w+, \d+ \w+ \d{4} \d\d:\d\d:\d\d GMT
+
+\x1f\x8b\x08.+
diff --git a/tests/envresponse009.phpt b/tests/envresponse009.phpt
new file mode 100644 (file)
index 0000000..2a337e4
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+env response stream cache negative
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--GET--
+a=b
+--ENV--
+HTTP_IF_MODIFIED_SINCE=Fri, 13 Feb 2009 23:31:30 GMT
+HTTP_IF_NONE_MATCH=0000-00-0000
+--FILE--
+<?php
+$f = tmpfile();
+$r = new http\Env\Response;
+$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
+$r->setEtag("abc");
+$r->setLastModified(1234567891);
+$r->send($f);
+rewind($f);
+var_dump(stream_get_contents($f));
+?>
+--EXPECTF--
+string(%d) "HTTP/1.1 200 OK%c
+Accept-Ranges: bytes%c
+X-Powered-By: %s%c
+ETag: "abc"%c
+Last-Modified: %s%c
+%c
+<?php
+$f = tmpfile();
+$r = new http\Env\Response;
+$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
+$r->setEtag("abc");
+$r->setLastModified(1234567891);
+$r->send($f);
+rewind($f);
+var_dump(stream_get_contents($f));
+?>
+"
+
diff --git a/tests/envresponse010.phpt b/tests/envresponse010.phpt
new file mode 100644 (file)
index 0000000..d365497
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+env response stream ranges
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--ENV--
+HTTP_RANGE=bytes=2-4
+--GET--
+a=b
+--FILE--
+<?php
+$f = tmpfile();
+$r = new http\Env\Response;
+$r->setContentType("text/plain");
+$r->setContentDisposition(
+    array("attachment" => array(array("filename" => basename(__FILE__))))
+);
+$r->setBody(new http\Message\Body(fopen(__FILE__, "rb")));
+$r->send($f);
+rewind($f);
+var_dump(stream_get_contents($f));
+?>
+--EXPECTF--
+string(%i) "HTTP/1.1 206 Partial Content%c
+Accept-Ranges: bytes%c
+X-Powered-By: PHP/%s%c
+Content-Type: text/plain%c
+Content-Range: bytes 2-4/311%c
+%c
+php"
diff --git a/tests/envresponse011.phpt b/tests/envresponse011.phpt
new file mode 100644 (file)
index 0000000..45e2f6e
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+env response cache positive with env message
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--GET--
+dummy=1
+--FILE--
+<?php
+$e = new http\Env\Request;
+$e->setHeader("If-Modified-Since", "Fri, 13 Feb 2009 23:31:32 GMT");
+$r = new http\Env\Response;
+$r->setEnvRequest($e);
+$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
+$r->setEtag("abc");
+$r->setLastModified(1234567891);
+$r->isCachedByEtag("If-None-Match") and die("Huh? etag? really?\n");
+$r->isCachedByLastModified("If-Modified-Since") or die("yep, I should be cached");
+$r->send();
+?>
+--EXPECTHEADERS--
+HTTP/1.1 304 Not Modified
+ETag: "abc"
+Last-Modified: Fri, 13 Feb 2009 23:31:31 GMT
+--EXPECT--
diff --git a/tests/envresponse012.phpt b/tests/envresponse012.phpt
new file mode 100644 (file)
index 0000000..58e0a3b
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+env response content disposition
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--GET--
+dummy=1
+--FILE--
+<?php
+
+$r = new http\Env\Response;
+$r->setContentDisposition(array("attachment"=>array("filename"=>basename(__FILE__))));
+$r->setBody(new http\Message\Body(fopen(__FILE__,"r")));
+$r->send();
+
+?>
+--EXPECTHEADERS--
+Content-Disposition: attachment;filename=envresponse012.php
+--EXPECT--
+<?php
+
+$r = new http\Env\Response;
+$r->setContentDisposition(array("attachment"=>array("filename"=>basename(__FILE__))));
+$r->setBody(new http\Message\Body(fopen(__FILE__,"r")));
+$r->send();
+
+?>
+
diff --git a/tests/envresponse013.phpt b/tests/envresponse013.phpt
new file mode 100644 (file)
index 0000000..d21f604
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+env response deflate
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--GET--
+dummy=1
+--FILE--
+<?php
+
+$req = new http\Env\Request;
+$req->setHeader("Accept-Encoding", "deflate");
+
+$res = new http\Env\Response;
+$res->setCacheControl("public, max-age=3600");
+$res->setContentEncoding(http\Env\Response::CONTENT_ENCODING_GZIP);
+$res->getBody()->append("foobar");
+
+$res->setEnvRequest($req);
+$res->send();
+?>
+--EXPECTHEADERS--
+Content-Encoding: deflate
+Vary: Accept-Encoding
+Cache-Control: public, max-age=3600
+--EXPECTREGEX--
+^\x78\x9c.+
+
diff --git a/tests/envresponse014.phpt b/tests/envresponse014.phpt
new file mode 100644 (file)
index 0000000..ef85e2c
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+env response invalid ranges
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+$f = tmpfile();
+$req = new http\Env\Request;
+$req->setHeader("Range", "bytes=321-123,123-0");
+$res = new http\Env\Response;
+$res->getBody()->append("foobar");
+$res->setEnvRequest($req);
+$res->send($f);
+rewind($f);
+var_dump(stream_get_contents($f));
+--EXPECTF--
+string(96) "HTTP/1.1 416 Requested Range Not Satisfiable
+Accept-Ranges: bytes
+Content-Range: bytes */6
+
+"
+
diff --git a/tests/header001.phpt b/tests/header001.phpt
new file mode 100644 (file)
index 0000000..5e3d938
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+header string
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$h = new http\Header("foo", "bar");
+var_dump("Foo: bar" === (string) $h);
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+Done
diff --git a/tests/header002.phpt b/tests/header002.phpt
new file mode 100644 (file)
index 0000000..36b25c7
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+header numeric
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$h = new http\Header(123, 456);
+var_dump("123: 456" === (string) $h);
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+Done
diff --git a/tests/header003.phpt b/tests/header003.phpt
new file mode 100644 (file)
index 0000000..d02e7e7
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+header serialize
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$h = new http\Header("foo", "bar");
+var_dump("Foo: bar" === (string) unserialize(serialize($h)));
+$h = new http\Header(123, 456);
+var_dump("123: 456" === (string) unserialize(serialize($h)));
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+bool(true)
+Done
diff --git a/tests/header004.phpt b/tests/header004.phpt
new file mode 100644 (file)
index 0000000..1517f1f
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+header match
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$ae = new http\Header("Accept-encoding", "gzip, deflate");
+var_dump($ae->match("gzip", http\Header::MATCH_WORD));
+var_dump($ae->match("gzip", http\Header::MATCH_WORD|http\Header::MATCH_CASE));
+var_dump($ae->match("gzip", http\Header::MATCH_STRICT));
+var_dump($ae->match("deflate", http\Header::MATCH_WORD));
+var_dump($ae->match("deflate", http\Header::MATCH_WORD|http\Header::MATCH_CASE));
+var_dump($ae->match("deflate", http\Header::MATCH_STRICT));
+var_dump($ae->match("zip", http\Header::MATCH_WORD));
+var_dump($ae->match("gzip", http\Header::MATCH_FULL));
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+bool(true)
+bool(false)
+bool(true)
+bool(true)
+bool(false)
+bool(false)
+bool(false)
+Done
diff --git a/tests/header005.phpt b/tests/header005.phpt
new file mode 100644 (file)
index 0000000..07c27cb
--- /dev/null
@@ -0,0 +1,32 @@
+--TEST--
+header negotiation
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$a = new http\Header("Accept", "text/html, text/plain;q=0.5, */*;q=0");
+var_dump("text/html" === $a->negotiate(array("text/plain","text/html")));
+var_dump("text/html" === $a->negotiate(array("text/plain","text/html"), $rs));
+var_dump(array("text/html"=>0.99, "text/plain"=>0.5) === $rs);
+var_dump("text/plain" === $a->negotiate(array("foo/bar", "text/plain"), $rs));
+var_dump(array("text/plain"=>0.5) === $rs);
+var_dump("foo/bar" === $a->negotiate(array("foo/bar"), $rs));
+var_dump(array() === $rs);
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Done
diff --git a/tests/header006.phpt b/tests/header006.phpt
new file mode 100644 (file)
index 0000000..92a6215
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+header parsing
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$header = "Foo: bar\nBar: foo\n";
+var_dump(array("Foo"=>"bar","Bar"=>"foo") === http\Header::parse($header));
+$headers = http\Header::parse($header, "http\\Header");
+var_dump(2 === count($headers));
+var_dump(2 === array_reduce($headers, function($count, $header) {
+       return $count + ($header instanceof http\Header);
+}, 0));
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+bool(true)
+bool(true)
+Done
diff --git a/tests/header007.phpt b/tests/header007.phpt
new file mode 100644 (file)
index 0000000..7f6f9eb
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+header parse error
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$header = "wass\nup";
+/* this generates two warnings because of the LF ;) */
+http\Header::parse($header);
+
+?>
+Done
+--EXPECTF--
+Test
+
+Warning: http\Header::parse(): Could not parse headers in %s on line %d
+
+Warning: http\Header::parse(): Could not parse headers in %s on line %d
+Done
diff --git a/tests/header008.phpt b/tests/header008.phpt
new file mode 100644 (file)
index 0000000..089e2ea
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+header params
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$header = new http\Header("Cache-control", "public, must-revalidate, max-age=0");
+var_dump(
+       array(
+               "public" => array("value" => true, "arguments" => array()),
+               "must-revalidate" => array("value" => true, "arguments" => array()),
+               "max-age" => array("value" => "0", "arguments" => array()),
+       ) === $header->getParams()->params
+);
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+Done
diff --git a/tests/header009.phpt b/tests/header009.phpt
new file mode 100644 (file)
index 0000000..d3ca1de
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+header params w/ args
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$header = new http\Header("Custom", '"foo" is "bar". "bar" is "bis" where "bis" is "where".');
+var_dump(
+               array(
+                               "foo" => array("value" => "bar", "arguments" => array()),
+                               "bar" => array("value" => "bis", "arguments" => array("bis" => "where"))
+               ) === $header->getParams(".", "where", "is")->params
+);
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+Done
index 810c1e8..f515af5 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-env request Message
+env request message
 --SKIPIF--
 <?php include "skipif.inc"; ?>
 --POST_RAW--
diff --git a/tests/message007.phpt b/tests/message007.phpt
new file mode 100644 (file)
index 0000000..478f411
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+message to stream
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$m = new http\Message("HTTP/1.1 200 Ok");
+$m->addHeader("Content-Type", "text/plain");
+$m->getBody()->append("this\nis\nthe\ntext");
+
+$f = tmpfile();
+$m->toStream($f);
+rewind($f);
+var_dump((string) $m === stream_get_contents($f));
+fclose($f);
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+Done
diff --git a/tests/message008.phpt b/tests/message008.phpt
new file mode 100644 (file)
index 0000000..3f5154d
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+message to callback
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$m = new http\Message("HTTP/1.1 200 Ok");
+$m->addHeader("Content-Type", "text/plain");
+$m->getBody()->append("this\nis\nthe\ntext");
+
+$d = new http\Encoding\Stream\Deflate;
+$s = "";
+$m->toCallback(function ($m, $data) use ($d, &$s) {
+       $s.=$d->update($data);
+});
+$s.=$d->finish();
+var_dump($m->toString() === http\Encoding\Stream\Inflate::decode($s));
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+Done
diff --git a/tests/message009.phpt b/tests/message009.phpt
new file mode 100644 (file)
index 0000000..34a923f
--- /dev/null
@@ -0,0 +1,149 @@
+--TEST--
+message properties
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+class message extends http\Message {
+       function __call($m, $args) {
+               if (preg_match("/^test(get|set)(.*)\$/i", $m, $match)) {
+                       list(, $getset, $prop) = $match;
+                       $prop = strtolower($prop[0]).substr($prop,1);
+                       switch(strtolower($getset)) {
+                               case "get":
+                                       return $this->$prop;
+                               case "set":
+                                       $this->$prop = current($args);
+                                       break;
+                       }
+               }
+       }
+}
+
+$test = new message;
+var_dump(0 === $test->testGetType());
+var_dump(null === $test->testGetBody());
+var_dump(null === $test->testGetRequestMethod());
+var_dump(null === $test->testGetRequestUrl());
+var_dump(null === $test->testGetResponseStatus());
+var_dump(null === $test->testGetResponseCode());
+var_dump("1.1" === $test->testGetHttpVersion());
+var_dump(array() === $test->testGetHeaders());
+var_dump(null === $test->testGetParentMessage());
+$test->testSetType(http\Message::TYPE_REQUEST);
+var_dump(http\Message::TYPE_REQUEST === $test->testGetType());
+var_dump(http\Message::TYPE_REQUEST === $test->getType());
+$body = new http\Message\Body;
+$test->testSetBody($body);
+var_dump($body === $test->testGetBody());
+var_dump($body === $test->getBody());
+$file = fopen(__FILE__,"r");
+$test->testSetBody($file);
+var_dump($file === $test->testGetBody()->getResource());
+var_dump($file === $test->getBody()->getResource());
+$test->testSetBody("data");
+var_dump("data" === (string) $test->testGetBody());
+var_dump("data" === (string) $test->getBody());
+$test->testSetRequestMethod("HEAD");
+var_dump("HEAD" === $test->testGetRequestMethod());
+var_dump("HEAD" === $test->getRequestMethod());
+$test->testSetRequestUrl("/");
+var_dump("/" === $test->testGetRequestUrl());
+var_dump("/" === $test->getRequestUrl());
+var_dump("HEAD / HTTP/1.1" === $test->getInfo());
+$test->testSetType(http\Message::TYPE_RESPONSE);
+$test->setResponseStatus("Created");
+var_dump("Created" === $test->testGetResponseStatus());
+var_dump("Created" === $test->getResponseStatus());
+$test->setResponseCode(201);
+var_dump(201 === $test->testGetResponseCode());
+var_dump(201 === $test->getResponseCode());
+$test->testSetResponseStatus("Ok");
+var_dump("Ok" === $test->testGetResponseStatus());
+var_dump("Ok" === $test->getResponseStatus());
+$test->testSetResponseCode(200);
+var_dump(200 === $test->testGetResponseCode());
+var_dump(200 === $test->getResponseCode());
+$test->testSetHttpVersion("1.0");
+var_dump("1.0" === $test->testGetHttpVersion());
+var_dump("1.0" === $test->getHttpVersion());
+var_dump("HTTP/1.0 200 OK" === $test->getInfo());
+$test->setHttpVersion("1.1");
+var_dump("1.1" === $test->testGetHttpVersion());
+var_dump("1.1" === $test->getHttpVersion());
+var_dump("HTTP/1.1 200 OK" === $test->getInfo());
+$test->setInfo("HTTP/1.1 201 Created");
+var_dump("Created" === $test->testGetResponseStatus());
+var_dump("Created" === $test->getResponseStatus());
+var_dump(201 === $test->testGetResponseCode());
+var_dump(201 === $test->getResponseCode());
+var_dump("1.1" === $test->testGetHttpVersion());
+var_dump("1.1" === $test->getHttpVersion());
+$test->testSetHeaders(array("Foo" => "bar"));
+var_dump(array("Foo" => "bar") === $test->testGetHeaders());
+var_dump(array("Foo" => "bar") === $test->getHeaders());
+var_dump("bar" === $test->getHeader("foo"));
+var_dump(false === $test->getHeader("bar"));
+$parent = new message;
+$test->testSetParentMessage($parent);
+var_dump($parent === $test->testGetParentMessage());
+var_dump($parent === $test->getParentMessage());
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Done
diff --git a/tests/message010.phpt b/tests/message010.phpt
new file mode 100644 (file)
index 0000000..5a51510
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+message body
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$m = new http\Message;
+$body = new http\Message\Body;
+$body->append("foo");
+$m->addBody($body);
+$body = new http\Message\Body;
+$body->append("bar");
+$m->addBody($body);
+var_dump("foobar" === (string) $m->getBody());
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+Done
diff --git a/tests/message011.phpt b/tests/message011.phpt
new file mode 100644 (file)
index 0000000..53aa992
--- /dev/null
@@ -0,0 +1,77 @@
+--TEST--
+message headers
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+
+echo "Test\n";
+
+class strval {
+       private $str;
+       function __construct($str) {
+               $this->str = $str;
+       }
+       function __toString() {
+               return (string) $this->str;
+       }
+}
+
+$m = new http\Message;
+$m->addHeaders(array("foo"=>"bar","bar"=>"foo"));
+var_dump(array("Foo"=>"bar", "Bar"=>"foo") === $m->getHeaders());
+$m->addHeaders(array("key"=>"val","more"=>"Stuff"));
+var_dump(array("Foo"=>"bar", "Bar"=>"foo","Key"=>"val","More"=>"Stuff") === $m->getHeaders());
+$m = new http\Message("GET / HTTP/1.1");
+$m->addHeader("Accept", "text/html");
+$m->addHeader("Accept", "text/xml;q=0");
+$m->addHeader("Accept", "text/plain;q=0.5");
+var_dump(
+               "GET / HTTP/1.1\r\n".
+               "Accept: text/html, text/xml;q=0, text/plain;q=0.5\r\n" ===
+               $m->toString()
+);
+$m = new http\Message("HTTP/1.1 200 Ok");
+$m->addHeader("Bool", true);
+$m->addHeader("Int", 123);
+$m->addHeader("Float", 1.23);
+$m->addHeader("Array", array(1,2,3));
+$m->addHeader("Object", new strval("test"));
+$m->addHeader("Set-Cookie",
+               array(
+                               array(
+                                               "cookies" => array("foo" => "bar"),
+                                               "expires" => date_create("2012-12-31 22:59:59 GMT")->format(
+                                                               DateTime::COOKIE
+                                               ),
+                                               "path" => "/somewhere"
+                               )
+               )
+);
+$m->addHeader("Set-Cookie", "val=0");
+
+var_dump(
+               "HTTP/1.1 200 Ok\r\n".
+               "Bool: true\r\n".
+               "Int: 123\r\n".
+               "Float: 1.23\r\n".
+               "Array: 1, 2, 3\r\n".
+               "Object: test\r\n".
+               "Set-Cookie: foo=bar; path=/somewhere; expires=Mon, 31 Dec 2012 22:59:59 GMT; \r\n".
+               "Set-Cookie: val=0\r\n" ===
+               $m->toString()
+);
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Done
diff --git a/tests/message012.phpt b/tests/message012.phpt
new file mode 100644 (file)
index 0000000..5f46c48
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+message part
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$p = new http\Message;
+$p->addHeader("Content-Type", "text/plain");
+$p->getBody()->append("data");
+       
+$m = new http\Message("HTTP/1.1 200");
+$m->getBody()->addPart($p);
+echo $m;
+
+?>
+Done
+--EXPECTF--
+Test
+HTTP/1.1 200
+Content-Length: %d
+Content-Type: multipart/form-data; boundary="%x.%x"
+
+--%x.%x
+Content-Type: text/plain
+Content-Length: 4
+
+data
+--%x.%x--
+Done
diff --git a/tests/message013.phpt b/tests/message013.phpt
new file mode 100644 (file)
index 0000000..8a192a5
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+message detach
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$m = new http\Message(
+       "HTTP/1.1 200 Ok\r\n".
+       "HTTP/1.1 201 Created\n".
+       "HTTP/1.1 302 Found\r\n"
+);
+
+var_dump(3 === count($m));
+$d = $m->detach();
+var_dump(3 === count($m));
+var_dump(1 === count($d));
+
+var_dump("HTTP/1.1 302 Found\r\n\r\n" === $d->toString(true));
+
+?>
+Done
+--EXPECTF--
+Test
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Done
diff --git a/tests/message014.phpt b/tests/message014.phpt
new file mode 100644 (file)
index 0000000..485c47f
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+message prepend
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+for ($i=0; $i<9; ++$i) {
+       $a[] = new http\Message("HTTP/1.1 ".($i+200));
+}
+
+foreach ($a as $m) {
+       if (isset($p)) $m->prepend($p);
+       $p = $m;
+}
+
+var_dump(
+       "HTTP/1.1 200\r\n\r\n".
+       "HTTP/1.1 201\r\n\r\n".
+       "HTTP/1.1 202\r\n\r\n".
+       "HTTP/1.1 203\r\n\r\n".
+       "HTTP/1.1 204\r\n\r\n".
+       "HTTP/1.1 205\r\n\r\n".
+       "HTTP/1.1 206\r\n\r\n".
+       "HTTP/1.1 207\r\n\r\n".
+       "HTTP/1.1 208\r\n\r\n" ===
+       $m->toString(true)
+);
+
+?>
+Done
+--EXPECTF--
+Test
+bool(true)
+Done
diff --git a/tests/message015.phpt b/tests/message015.phpt
new file mode 100644 (file)
index 0000000..f11efc8
--- /dev/null
@@ -0,0 +1,43 @@
+--TEST--
+message errors
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$m = new http\Message;
+$m->setRequestUrl("/foo");
+$m->setType(http\Message::TYPE_REQUEST);
+$m->setRequestUrl("");
+
+$m = new http\Message;
+try {
+       $m->getParentMessage();
+       die("unreached");
+} catch (http\Exception $e) {
+       var_dump($e->getMessage());
+}
+
+$m = new http\Message("HTTP/1.1 200\r\nHTTP/1.1 201");
+try {
+       $m->prepend($m->getParentMessage());
+       die("unreached");
+} catch (http\Exception $e) {
+       var_dump($e->getMessage());
+}
+
+?>
+Done
+--EXPECTF--
+Test
+
+Notice: http\Message::setRequestUrl(): HttpMessage is not of type REQUEST in %s on line %d
+
+Warning: http\Message::setRequestUrl(): Cannot set HttpMessage::requestUrl to an empty string in %s on line %d
+string(42) "HttpMessage does not have a parent message"
+string(62) "Cannot prepend a message located within the same message chain"
+Done
diff --git a/tests/object001.phpt b/tests/object001.phpt
new file mode 100644 (file)
index 0000000..fe3d012
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+object default error handling
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php 
+
+echo "Test\n";
+
+var_dump(null === http\Object::getDefaultErrorHandling());
+http\Object::setDefaultErrorHandling(http\Object::EH_SUPPRESS);
+var_dump(http\Object::EH_SUPPRESS === http\Object::getDefaultErrorHandling());
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+bool(true)
+Done
diff --git a/tests/object002.phpt b/tests/object002.phpt
new file mode 100644 (file)
index 0000000..b3e3743
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+object instance error handling
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php 
+
+echo "Test\n";
+
+class eh extends http\Object {}
+
+$eh = new eh;
+var_dump(null === $eh->getErrorHandling());
+$eh->setErrorHandling(eh::EH_SUPPRESS);
+var_dump(eh::EH_SUPPRESS === $eh->getErrorHandling());
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+bool(true)
+Done
diff --git a/tests/object003.phpt b/tests/object003.phpt
new file mode 100644 (file)
index 0000000..842bb0d
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+object error suppression
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php 
+
+echo "Test\n";
+
+class eh extends http\Object {}
+
+http\Object::setDefaultErrorHandling(http\Object::EH_SUPPRESS);
+$o = new eh;
+$o->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "suppress");
+
+?>
+Done
+--EXPECT--
+Test
+Done
diff --git a/tests/object004.phpt b/tests/object004.phpt
new file mode 100644 (file)
index 0000000..93a062d
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+object error exception
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php 
+
+echo "Test\n";
+
+class eh extends http\Object {}
+
+http\Object::setDefaultErrorHandling(http\Object::EH_THROW);
+$o = new eh;
+$o->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "exception");
+
+?>
+Done
+--EXPECTF--
+Test
+
+Fatal error: Uncaught exception 'http\Exception' with message 'exception' in %s:%d
+Stack trace:
+#0 %s(%d): http\Object->triggerError(512, 0, 'exception')
+#1 {main}
+  thrown in %s on line %d
diff --git a/tests/object005.phpt b/tests/object005.phpt
new file mode 100644 (file)
index 0000000..0330d32
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+object normal error
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php 
+
+echo "Test\n";
+
+class eh extends http\Object {}
+
+http\Object::setDefaultErrorHandling(http\Object::EH_NORMAL);
+$o = new eh;
+$o->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "warning");
+
+?>
+Done
+--EXPECTF--
+Test
+
+Warning: http\Object::triggerError(): warning in %s on line %d
+Done
diff --git a/tests/object006.phpt b/tests/object006.phpt
new file mode 100644 (file)
index 0000000..a11529d
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+object error suppression2
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php 
+
+echo "Test\n";
+
+class eh extends http\Object {}
+
+$eh = new eh;
+$eh->setErrorHandling(http\Object::EH_SUPPRESS);
+$eh->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "suppress");
+
+?>
+Done
+--EXPECTF--
+Test
+Done
diff --git a/tests/object007.phpt b/tests/object007.phpt
new file mode 100644 (file)
index 0000000..475b4b8
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+object error exception2
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php 
+
+echo "Test\n";
+
+class eh extends http\Object {}
+
+$eh = new eh;
+$eh->setErrorHandling(http\Object::EH_THROW);
+$eh->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "exception");
+
+?>
+Done
+--EXPECTF--
+Test
+
+Fatal error: Uncaught exception 'http\Exception' with message 'exception' in %s:%d
+Stack trace:
+#0 /home/mike/src/pecl_http-DEV_2.svn/tests/object007.php(9): http\Object->triggerError(512, 0, 'exception')
+#1 {main}
+  thrown in %s on line %d
diff --git a/tests/object008.phpt b/tests/object008.phpt
new file mode 100644 (file)
index 0000000..6dff7d5
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+object normal error2
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php 
+
+echo "Test\n";
+
+class eh extends http\Object {}
+
+$eh = new eh;
+$eh->setErrorHandling(http\Object::EH_NORMAL);
+$eh->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "warning");
+
+?>
+Done
+--EXPECTF--
+Test
+
+Warning: http\Object::triggerError(): warning in %s on line %d
+Done
diff --git a/tests/object009.phpt b/tests/object009.phpt
new file mode 100644 (file)
index 0000000..4d6e574
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+object unknown error handling
+--SKIPIF--
+<?php 
+include "skipif.inc";
+?>
+--FILE--
+<?php 
+
+echo "Test\n";
+
+http\Object::setDefaultErrorHandling(12345);
+
+class eh extends http\Object {}
+
+$eh = new eh;
+$eh->setErrorHandling(12345);
+
+?>
+Done
+--EXPECTF--
+Test
+
+Warning: http\Object::setDefaultErrorHandling(): unknown error handling code (12345) in %s on line %d
+
+Warning: http\Object::setErrorHandling(): unknown error handling code (12345) in %s on line %d
+Done
diff --git a/tests/response001.phpt b/tests/response001.phpt
deleted file mode 100644 (file)
index 2aa2bd0..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
---TEST--
-env response Message
---SKIPIF--
-<?php include "skipif.inc"; ?>
---POST--
-a=b
---ENV--
-HTTP_ACCEPT_ENCODING=gzip
---FILE--
-<?php
-
-$r = new http\env\Response;
-$r->setHeader("foo","bar");
-$r->setContentEncoding(http\env\Response::CONTENT_ENCODING_GZIP);
-$r->setBody(new http\message\Body(fopen(__FILE__,"r")));
-$r->send();
-
---EXPECTHEADERS--
-Foo: bar
-Content-Encoding: gzip
-Vary: Accept-Encoding
---EXPECTREGEX--
-^\x1f\x8b\x08.+
diff --git a/tests/response002.phpt b/tests/response002.phpt
deleted file mode 100644 (file)
index 9a2d3da..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
---TEST--
-http response cache negative
---SKIPIF--
-<?php include "skipif.inc"; ?>
---GET--
-a=b
---ENV--
-HTTP_IF_MODIFIED_SINCE=Fri, 13 Feb 2009 23:31:30 GMT
-HTTP_IF_NONE_MATCH=0000-00-0000
---FILE--
-<?php
-$r = new http\Env\Response;
-$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
-$r->setEtag("abc");
-$r->setLastModified(1234567891);
-$r->send();
-?>
---EXPECTHEADERS--
-ETag: "abc"
-Last-Modified: Fri, 13 Feb 2009 23:31:31 GMT
---EXPECT--
-<?php
-$r = new http\Env\Response;
-$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
-$r->setEtag("abc");
-$r->setLastModified(1234567891);
-$r->send();
-?>
diff --git a/tests/response003.phpt b/tests/response003.phpt
deleted file mode 100644 (file)
index d2f91c1..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
---TEST--
-response ranges
---SKIPIF--
-<?php include "skipif.inc"; ?>
---ENV--
-HTTP_RANGE=bytes=2-4
---GET--
-a=b
---FILE--
-<?php
-
-$r = new http\Env\Response;
-$r->setContentType("text/plain");
-$r->setContentDisposition(
-    array("attachment" => array(array("filename" => basename(__FILE__))))
-);
-$r->setBody(new http\Message\Body(fopen(__FILE__, "rb")));
-$r->send();
-
-?>
---EXPECTHEADERS--
-Content-Type: text/plain
---EXPECTF--
-php
diff --git a/tests/response004.phpt b/tests/response004.phpt
deleted file mode 100644 (file)
index bda3be0..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
---TEST--
-reponse callback
---SKIPIF--
-<?php
-include "skipif.inc";
-if (version_compare(PHP_VERSION, "5.4.0", "<")) die("SKIP 5.3 ob is broken");
-?>
---GET--
-dummy=1
---FILE--
-<?php
-
-$r = new http\Env\Response;
-$r->setCacheControl("public,must-revalidate,max-age=0");
-$r->setThrottleRate(1, 0.1);
-ob_start($r);
-
-echo "foo";
-echo "bar";
-
-ob_end_flush();
-$r->send();
---EXPECTHEADERS--
-Accept-Ranges: bytes
-Cache-Control: public,must-revalidate,max-age=0
-ETag: "9ef61f95"
---EXPECTF--
-foobar
diff --git a/tests/response005.phpt b/tests/response005.phpt
deleted file mode 100644 (file)
index f4f747d..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
---TEST--
-http response cache positive
---SKIPIF--
-<?php include "skipif.inc"; ?>
---GET--
-a=b
---ENV--
-HTTP_IF_MODIFIED_SINCE=Fri, 13 Feb 2009 23:31:32 GMT
---FILE--
-<?php
-$r = new http\Env\Response;
-$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
-$r->setEtag("abc");
-$r->setLastModified(1234567891);
-$r->isCachedByEtag("If-None-Match") and die("Huh? etag? really?\n");
-$r->isCachedByLastModified("If-Modified-Since") or die("yep, I should be cached");
-$r->send();
-?>
---EXPECTHEADERS--
-HTTP/1.1 304 Not Modified
-ETag: "abc"
-Last-Modified: Fri, 13 Feb 2009 23:31:31 GMT
---EXPECT--
diff --git a/tests/response006.phpt b/tests/response006.phpt
deleted file mode 100644 (file)
index c555be6..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
---TEST--
-http response stream
---SKIPIF--
-<?php
-include "skipif.inc";
-?>
---FILE--
-<?php
-echo "Test\n";
-
-$f = tmpfile();
-
-$r = new http\Env\Response;
-$r->addHeader("foo", array("bar","baz"));
-$r->getBody()->append("foo");
-
-$r->send($f);
-
-rewind($f);
-var_dump(stream_get_contents($f));
-?>
-Done
---EXPECT--
-Test
-string(77) "HTTP/1.1 200 OK
-Accept-Ranges: bytes
-Foo: bar, baz
-ETag: "8c736521"
-
-foo"
-Done
diff --git a/tests/response007.phpt b/tests/response007.phpt
deleted file mode 100644 (file)
index 64fbd65..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
---TEST--
-response env request
---SKIPIF--
-<?php
-include "skipif.inc";
-?>
---GET--
-dummy=1
---FILE--
-<?php
-echo "Test\n";
-
-$tmp = tmpfile();
-
-// modify HTTP env
-$req = new http\Env\Request;
-$req->setHeader("Range", "bytes=2-4");
-
-$res = new http\Env\Response;
-$res->setEnvRequest($req);
-$res->setContentType("text/plain");
-$res->getBody()->append("012345679");
-$res->send($tmp);
-
-rewind($tmp);
-var_dump(stream_get_contents($tmp));
-
-?>
-Done
---EXPECTF--
-Test
-string(%d) "HTTP/1.1 206 Partial Content%c
-Accept-Ranges: bytes%c
-X-Powered-By: %s%c
-Content-Type: text/plain%c
-Content-Range: bytes 2-4/9%c
-%c
-234"
-Done
diff --git a/tests/response008.phpt b/tests/response008.phpt
deleted file mode 100644 (file)
index 379ab57..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
---TEST--
-env response stream message
---SKIPIF--
-<?php include "skipif.inc"; ?>
---ENV--
-HTTP_ACCEPT_ENCODING=gzip
---FILE--
-<?php
-
-$f = tmpfile();
-
-$r = new http\env\Response;
-$r->setHeader("foo","bar");
-$r->setContentEncoding(http\env\Response::CONTENT_ENCODING_GZIP);
-$r->setBody(new http\message\Body(fopen(__FILE__,"r")));
-$r->send($f);
-
-rewind($f);
-var_dump(stream_get_contents($f));
-
---EXPECTREGEX--
-string\(\d+\) "HTTP\/1\.1 200 OK
-Accept-Ranges: bytes
-Foo: bar
-Content-Encoding: gzip
-Vary: Accept-Encoding
-ETag: "\w+-\w+-\w+"
-Last-Modified: \w+, \d+ \w+ \d{4} \d\d:\d\d:\d\d GMT
-
-\x1f\x8b\x08.+
diff --git a/tests/response009.phpt b/tests/response009.phpt
deleted file mode 100644 (file)
index 9a0e23d..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
---TEST--
-http response stream cache negative
---SKIPIF--
-<?php include "skipif.inc"; ?>
---GET--
-a=b
---ENV--
-HTTP_IF_MODIFIED_SINCE=Fri, 13 Feb 2009 23:31:30 GMT
-HTTP_IF_NONE_MATCH=0000-00-0000
---FILE--
-<?php
-$f = tmpfile();
-$r = new http\Env\Response;
-$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
-$r->setEtag("abc");
-$r->setLastModified(1234567891);
-$r->send($f);
-rewind($f);
-var_dump(stream_get_contents($f));
-?>
---EXPECTF--
-string(%d) "HTTP/1.1 200 OK%c
-Accept-Ranges: bytes%c
-X-Powered-By: %s%c
-ETag: "abc"%c
-Last-Modified: %s%c
-%c
-<?php
-$f = tmpfile();
-$r = new http\Env\Response;
-$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
-$r->setEtag("abc");
-$r->setLastModified(1234567891);
-$r->send($f);
-rewind($f);
-var_dump(stream_get_contents($f));
-?>
-"
-
diff --git a/tests/response010.phpt b/tests/response010.phpt
deleted file mode 100644 (file)
index 8a3c1ae..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
---TEST--
-response stream ranges
---SKIPIF--
-<?php include "skipif.inc"; ?>
---ENV--
-HTTP_RANGE=bytes=2-4
---GET--
-a=b
---FILE--
-<?php
-$f = tmpfile();
-$r = new http\Env\Response;
-$r->setContentType("text/plain");
-$r->setContentDisposition(
-    array("attachment" => array(array("filename" => basename(__FILE__))))
-);
-$r->setBody(new http\Message\Body(fopen(__FILE__, "rb")));
-$r->send($f);
-rewind($f);
-var_dump(stream_get_contents($f));
-?>
---EXPECTF--
-string(%i) "HTTP/1.1 206 Partial Content%c
-Accept-Ranges: bytes%c
-X-Powered-By: PHP/%s%c
-Content-Type: text/plain%c
-Content-Range: bytes 2-4/311%c
-%c
-php"
diff --git a/tests/response011.phpt b/tests/response011.phpt
deleted file mode 100644 (file)
index 701da22..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
---TEST--
-http response cache positive with env message
---SKIPIF--
-<?php include "skipif.inc"; ?>
---GET--
-dummy=1
---FILE--
-<?php
-$e = new http\Env\Request;
-$e->setHeader("If-Modified-Since", "Fri, 13 Feb 2009 23:31:32 GMT");
-$r = new http\Env\Response;
-$r->setEnvRequest($e);
-$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
-$r->setEtag("abc");
-$r->setLastModified(1234567891);
-$r->isCachedByEtag("If-None-Match") and die("Huh? etag? really?\n");
-$r->isCachedByLastModified("If-Modified-Since") or die("yep, I should be cached");
-$r->send();
-?>
---EXPECTHEADERS--
-HTTP/1.1 304 Not Modified
-ETag: "abc"
-Last-Modified: Fri, 13 Feb 2009 23:31:31 GMT
---EXPECT--
diff --git a/tests/response012.phpt b/tests/response012.phpt
deleted file mode 100644 (file)
index 5e9ed57..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
---TEST--
-response content disposition
---SKIPIF--
-<?php
-include "skipif.inc";
-?>
---GET--
-dummy=1
---FILE--
-<?php
-
-$r = new http\Env\Response;
-$r->setContentDisposition(array("attachment"=>array("filename"=>basename(__FILE__))));
-$r->setBody(new http\Message\Body(fopen(__FILE__,"r")));
-$r->send();
-
-?>
---EXPECTHEADERS--
-Content-Disposition: attachment;filename=response012.php
---EXPECT--
-<?php
-
-$r = new http\Env\Response;
-$r->setContentDisposition(array("attachment"=>array("filename"=>basename(__FILE__))));
-$r->setBody(new http\Message\Body(fopen(__FILE__,"r")));
-$r->send();
-
-?>
-
diff --git a/tests/response013.phpt b/tests/response013.phpt
deleted file mode 100644 (file)
index 75b4163..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
---TEST--
-response deflate
---SKIPIF--
-<?php
-include "skipif.inc";
-?>
---GET--
-dummy=1
---FILE--
-<?php
-
-$req = new http\Env\Request;
-$req->setHeader("Accept-Encoding", "deflate");
-
-$res = new http\Env\Response;
-$res->setCacheControl("public, max-age=3600");
-$res->setContentEncoding(http\Env\Response::CONTENT_ENCODING_GZIP);
-$res->getBody()->append("foobar");
-
-$res->setEnvRequest($req);
-$res->send();
-?>
---EXPECTHEADERS--
-Content-Encoding: deflate
-Vary: Accept-Encoding
-Cache-Control: public, max-age=3600
---EXPECTREGEX--
-^\x78\x9c.+
-
diff --git a/tests/response014.phpt b/tests/response014.phpt
deleted file mode 100644 (file)
index 5478a61..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
---TEST--
-response invalid ranges
---SKIPIF--
-<?php
-include "skipif.inc";
-?>
---FILE--
-<?php
-$f = tmpfile();
-$req = new http\Env\Request;
-$req->setHeader("Range", "bytes=321-123,123-0");
-$res = new http\Env\Response;
-$res->getBody()->append("foobar");
-$res->setEnvRequest($req);
-$res->send($f);
-rewind($f);
-var_dump(stream_get_contents($f));
---EXPECTF--
-string(96) "HTTP/1.1 416 Requested Range Not Satisfiable
-Accept-Ranges: bytes
-Content-Range: bytes */6
-
-"
-