From 40688e36ecfc7b22a1221079a8d40edd122ee550 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Mon, 12 Aug 2013 19:49:55 +0000 Subject: [PATCH] test reafactoring; release beta5 --- package.xml | 66 ++-- php_http.h | 2 +- phpunit/ClientTest.php | 182 ----------- phpunit/HeaderTest.php | 83 ----- phpunit/MessageTest.php | 283 ------------------ phpunit/ObjectTest.php | 71 ----- tests/client011.phpt | 90 ++++++ tests/client012.phpt | 36 +++ tests/client013.phpt | 66 ++++ tests/clientrequest004.phpt | 5 + tests/envrequestheader001.phpt | 2 +- .../{response001.phpt => envresponse001.phpt} | 2 +- .../{response002.phpt => envresponse002.phpt} | 2 +- .../{response003.phpt => envresponse003.phpt} | 2 +- .../{response004.phpt => envresponse004.phpt} | 2 +- .../{response005.phpt => envresponse005.phpt} | 2 +- .../{response006.phpt => envresponse006.phpt} | 2 +- .../{response007.phpt => envresponse007.phpt} | 2 +- .../{response008.phpt => envresponse008.phpt} | 0 .../{response009.phpt => envresponse009.phpt} | 2 +- .../{response010.phpt => envresponse010.phpt} | 2 +- .../{response011.phpt => envresponse011.phpt} | 2 +- .../{response012.phpt => envresponse012.phpt} | 4 +- .../{response013.phpt => envresponse013.phpt} | 2 +- .../{response014.phpt => envresponse014.phpt} | 2 +- tests/header001.phpt | 20 ++ tests/header002.phpt | 20 ++ tests/header003.phpt | 23 ++ tests/header004.phpt | 34 +++ tests/header005.phpt | 32 ++ tests/header006.phpt | 27 ++ tests/header007.phpt | 24 ++ tests/header008.phpt | 26 ++ tests/header009.phpt | 25 ++ tests/message002.phpt | 2 +- tests/message007.phpt | 27 ++ tests/message008.phpt | 29 ++ tests/message009.phpt | 149 +++++++++ tests/message010.phpt | 26 ++ tests/message011.phpt | 77 +++++ tests/message012.phpt | 34 +++ tests/message013.phpt | 33 ++ tests/message014.phpt | 39 +++ tests/message015.phpt | 43 +++ tests/object001.phpt | 22 ++ tests/object002.phpt | 25 ++ tests/object003.phpt | 22 ++ tests/object004.phpt | 27 ++ tests/object005.phpt | 24 ++ tests/object006.phpt | 22 ++ tests/object007.phpt | 27 ++ tests/object008.phpt | 24 ++ tests/object009.phpt | 27 ++ 53 files changed, 1168 insertions(+), 656 deletions(-) delete mode 100644 phpunit/ClientTest.php delete mode 100644 phpunit/HeaderTest.php delete mode 100644 phpunit/MessageTest.php delete mode 100644 phpunit/ObjectTest.php create mode 100644 tests/client011.phpt create mode 100644 tests/client012.phpt create mode 100644 tests/client013.phpt rename tests/{response001.phpt => envresponse001.phpt} (95%) rename tests/{response002.phpt => envresponse002.phpt} (95%) rename tests/{response003.phpt => envresponse003.phpt} (95%) rename tests/{response004.phpt => envresponse004.phpt} (95%) rename tests/{response005.phpt => envresponse005.phpt} (95%) rename tests/{response006.phpt => envresponse006.phpt} (94%) rename tests/{response007.phpt => envresponse007.phpt} (95%) rename tests/{response008.phpt => envresponse008.phpt} (100%) rename tests/{response009.phpt => envresponse009.phpt} (95%) rename tests/{response010.phpt => envresponse010.phpt} (95%) rename tests/{response011.phpt => envresponse011.phpt} (93%) rename tests/{response012.phpt => envresponse012.phpt} (84%) rename tests/{response013.phpt => envresponse013.phpt} (96%) rename tests/{response014.phpt => envresponse014.phpt} (93%) create mode 100644 tests/header001.phpt create mode 100644 tests/header002.phpt create mode 100644 tests/header003.phpt create mode 100644 tests/header004.phpt create mode 100644 tests/header005.phpt create mode 100644 tests/header006.phpt create mode 100644 tests/header007.phpt create mode 100644 tests/header008.phpt create mode 100644 tests/header009.phpt create mode 100644 tests/message007.phpt create mode 100644 tests/message008.phpt create mode 100644 tests/message009.phpt create mode 100644 tests/message010.phpt create mode 100644 tests/message011.phpt create mode 100644 tests/message012.phpt create mode 100644 tests/message013.phpt create mode 100644 tests/message014.phpt create mode 100644 tests/message015.phpt create mode 100644 tests/object001.phpt create mode 100644 tests/object002.phpt create mode 100644 tests/object003.phpt create mode 100644 tests/object004.phpt create mode 100644 tests/object005.phpt create mode 100644 tests/object006.phpt create mode 100644 tests/object007.phpt create mode 100644 tests/object008.phpt create mode 100644 tests/object009.phpt diff --git a/package.xml b/package.xml index 158a29c..a0b1a68 100644 --- a/package.xml +++ b/package.xml @@ -28,9 +28,9 @@ support. Parallel requests are available for PHP 5 and greater. mike@php.net yes - 2012-12-31 + 2013-08-12 - 2.0.0dev + 2.0.0beta5 2.0.0 @@ -140,6 +140,9 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be + + + @@ -157,6 +160,20 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be + + + + + + + + + + + + + + @@ -165,6 +182,15 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be + + + + + + + + + @@ -173,38 +199,38 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - diff --git a/php_http.h b/php_http.h index bb9c2d0..68f4293 100644 --- a/php_http.h +++ b/php_http.h @@ -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 index 21493f3..0000000 --- a/phpunit/ClientTest.php +++ /dev/null @@ -1,182 +0,0 @@ -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(<<r->getHistory()->toString(true)) - ); - - - $this->r->requeue($request)->send(); - - $this->assertStringMatchesFormat(<<r->getHistory()->toString(true)) - ); - } -} - diff --git a/phpunit/HeaderTest.php b/phpunit/HeaderTest.php deleted file mode 100644 index 184f21a..0000000 --- a/phpunit/HeaderTest.php +++ /dev/null @@ -1,83 +0,0 @@ -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 index b572f57..0000000 --- a/phpunit/MessageTest.php +++ /dev/null @@ -1,283 +0,0 @@ -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 index 968f3f8..0000000 --- a/phpunit/ObjectTest.php +++ /dev/null @@ -1,71 +0,0 @@ -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 index 0000000..188b178 --- /dev/null +++ b/tests/client011.phpt @@ -0,0 +1,90 @@ +--TEST-- +client history +--SKIPIF-- + +--FILE-- +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 index 0000000..f9ae690 --- /dev/null +++ b/tests/client012.phpt @@ -0,0 +1,36 @@ +--TEST-- +client ssl +--SKIPIF-- + +--FILE-- +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 index 0000000..0de0547 --- /dev/null +++ b/tests/client013.phpt @@ -0,0 +1,66 @@ +--TEST-- +client observers +--SKIPIF-- + +--FILE-- +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 diff --git a/tests/clientrequest004.phpt b/tests/clientrequest004.phpt index abff8d9..f00ee2e 100644 --- a/tests/clientrequest004.phpt +++ b/tests/clientrequest004.phpt @@ -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 diff --git a/tests/envrequestheader001.phpt b/tests/envrequestheader001.phpt index 2a6a940..b259ea5 100644 --- a/tests/envrequestheader001.phpt +++ b/tests/envrequestheader001.phpt @@ -1,5 +1,5 @@ --TEST-- -request header +env request header --SKIPIF-- --POST-- diff --git a/tests/response002.phpt b/tests/envresponse002.phpt similarity index 95% rename from tests/response002.phpt rename to tests/envresponse002.phpt index 9a2d3da..e11f7bb 100644 --- a/tests/response002.phpt +++ b/tests/envresponse002.phpt @@ -1,5 +1,5 @@ --TEST-- -http response cache negative +env response cache negative --SKIPIF-- --GET-- diff --git a/tests/response003.phpt b/tests/envresponse003.phpt similarity index 95% rename from tests/response003.phpt rename to tests/envresponse003.phpt index d2f91c1..3bbf760 100644 --- a/tests/response003.phpt +++ b/tests/envresponse003.phpt @@ -1,5 +1,5 @@ --TEST-- -response ranges +env response ranges --SKIPIF-- --ENV-- diff --git a/tests/response004.phpt b/tests/envresponse004.phpt similarity index 95% rename from tests/response004.phpt rename to tests/envresponse004.phpt index bda3be0..f84c860 100644 --- a/tests/response004.phpt +++ b/tests/envresponse004.phpt @@ -1,5 +1,5 @@ --TEST-- -reponse callback +env reponse callback --SKIPIF-- --GET-- diff --git a/tests/response006.phpt b/tests/envresponse006.phpt similarity index 94% rename from tests/response006.phpt rename to tests/envresponse006.phpt index c555be6..76141c1 100644 --- a/tests/response006.phpt +++ b/tests/envresponse006.phpt @@ -1,5 +1,5 @@ --TEST-- -http response stream +env response stream --SKIPIF-- --GET-- diff --git a/tests/response010.phpt b/tests/envresponse010.phpt similarity index 95% rename from tests/response010.phpt rename to tests/envresponse010.phpt index 8a3c1ae..d365497 100644 --- a/tests/response010.phpt +++ b/tests/envresponse010.phpt @@ -1,5 +1,5 @@ --TEST-- -response stream ranges +env response stream ranges --SKIPIF-- --ENV-- diff --git a/tests/response011.phpt b/tests/envresponse011.phpt similarity index 93% rename from tests/response011.phpt rename to tests/envresponse011.phpt index 701da22..45e2f6e 100644 --- a/tests/response011.phpt +++ b/tests/envresponse011.phpt @@ -1,5 +1,5 @@ --TEST-- -http response cache positive with env message +env response cache positive with env message --SKIPIF-- --GET-- diff --git a/tests/response012.phpt b/tests/envresponse012.phpt similarity index 84% rename from tests/response012.phpt rename to tests/envresponse012.phpt index 5e9ed57..58e0a3b 100644 --- a/tests/response012.phpt +++ b/tests/envresponse012.phpt @@ -1,5 +1,5 @@ --TEST-- -response content disposition +env response content disposition --SKIPIF-- send(); ?> --EXPECTHEADERS-- -Content-Disposition: attachment;filename=response012.php +Content-Disposition: attachment;filename=envresponse012.php --EXPECT-- +--FILE-- + +Done +--EXPECT-- +Test +bool(true) +Done diff --git a/tests/header002.phpt b/tests/header002.phpt new file mode 100644 index 0000000..36b25c7 --- /dev/null +++ b/tests/header002.phpt @@ -0,0 +1,20 @@ +--TEST-- +header numeric +--SKIPIF-- + +--FILE-- + +Done +--EXPECT-- +Test +bool(true) +Done diff --git a/tests/header003.phpt b/tests/header003.phpt new file mode 100644 index 0000000..d02e7e7 --- /dev/null +++ b/tests/header003.phpt @@ -0,0 +1,23 @@ +--TEST-- +header serialize +--SKIPIF-- + +--FILE-- + +Done +--EXPECT-- +Test +bool(true) +bool(true) +Done diff --git a/tests/header004.phpt b/tests/header004.phpt new file mode 100644 index 0000000..1517f1f --- /dev/null +++ b/tests/header004.phpt @@ -0,0 +1,34 @@ +--TEST-- +header match +--SKIPIF-- + +--FILE-- +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 index 0000000..07c27cb --- /dev/null +++ b/tests/header005.phpt @@ -0,0 +1,32 @@ +--TEST-- +header negotiation +--SKIPIF-- + +--FILE-- +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 index 0000000..92a6215 --- /dev/null +++ b/tests/header006.phpt @@ -0,0 +1,27 @@ +--TEST-- +header parsing +--SKIPIF-- + +--FILE-- +"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 index 0000000..7f6f9eb --- /dev/null +++ b/tests/header007.phpt @@ -0,0 +1,24 @@ +--TEST-- +header parse error +--SKIPIF-- + +--FILE-- + +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 index 0000000..089e2ea --- /dev/null +++ b/tests/header008.phpt @@ -0,0 +1,26 @@ +--TEST-- +header params +--SKIPIF-- + +--FILE-- + 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 index 0000000..d3ca1de --- /dev/null +++ b/tests/header009.phpt @@ -0,0 +1,25 @@ +--TEST-- +header params w/ args +--SKIPIF-- + +--FILE-- + array("value" => "bar", "arguments" => array()), + "bar" => array("value" => "bis", "arguments" => array("bis" => "where")) + ) === $header->getParams(".", "where", "is")->params +); + +?> +Done +--EXPECT-- +Test +bool(true) +Done diff --git a/tests/message002.phpt b/tests/message002.phpt index 810c1e8..f515af5 100644 --- a/tests/message002.phpt +++ b/tests/message002.phpt @@ -1,5 +1,5 @@ --TEST-- -env request Message +env request message --SKIPIF-- --POST_RAW-- diff --git a/tests/message007.phpt b/tests/message007.phpt new file mode 100644 index 0000000..478f411 --- /dev/null +++ b/tests/message007.phpt @@ -0,0 +1,27 @@ +--TEST-- +message to stream +--SKIPIF-- + +--FILE-- +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 index 0000000..3f5154d --- /dev/null +++ b/tests/message008.phpt @@ -0,0 +1,29 @@ +--TEST-- +message to callback +--SKIPIF-- + +--FILE-- +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 index 0000000..34a923f --- /dev/null +++ b/tests/message009.phpt @@ -0,0 +1,149 @@ +--TEST-- +message properties +--SKIPIF-- + +--FILE-- +$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 index 0000000..5a51510 --- /dev/null +++ b/tests/message010.phpt @@ -0,0 +1,26 @@ +--TEST-- +message body +--SKIPIF-- + +--FILE-- +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 index 0000000..53aa992 --- /dev/null +++ b/tests/message011.phpt @@ -0,0 +1,77 @@ +--TEST-- +message headers +--SKIPIF-- + +--INI-- +date.timezone=UTC +--FILE-- +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 index 0000000..5f46c48 --- /dev/null +++ b/tests/message012.phpt @@ -0,0 +1,34 @@ +--TEST-- +message part +--SKIPIF-- + +--FILE-- +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 index 0000000..8a192a5 --- /dev/null +++ b/tests/message013.phpt @@ -0,0 +1,33 @@ +--TEST-- +message detach +--SKIPIF-- + +--FILE-- +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 index 0000000..485c47f --- /dev/null +++ b/tests/message014.phpt @@ -0,0 +1,39 @@ +--TEST-- +message prepend +--SKIPIF-- + +--FILE-- +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 index 0000000..f11efc8 --- /dev/null +++ b/tests/message015.phpt @@ -0,0 +1,43 @@ +--TEST-- +message errors +--SKIPIF-- + +--FILE-- +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 index 0000000..fe3d012 --- /dev/null +++ b/tests/object001.phpt @@ -0,0 +1,22 @@ +--TEST-- +object default error handling +--SKIPIF-- + +--FILE-- + +Done +--EXPECT-- +Test +bool(true) +bool(true) +Done diff --git a/tests/object002.phpt b/tests/object002.phpt new file mode 100644 index 0000000..b3e3743 --- /dev/null +++ b/tests/object002.phpt @@ -0,0 +1,25 @@ +--TEST-- +object instance error handling +--SKIPIF-- + +--FILE-- +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 index 0000000..842bb0d --- /dev/null +++ b/tests/object003.phpt @@ -0,0 +1,22 @@ +--TEST-- +object error suppression +--SKIPIF-- + +--FILE-- +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 index 0000000..93a062d --- /dev/null +++ b/tests/object004.phpt @@ -0,0 +1,27 @@ +--TEST-- +object error exception +--SKIPIF-- + +--FILE-- +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 index 0000000..0330d32 --- /dev/null +++ b/tests/object005.phpt @@ -0,0 +1,24 @@ +--TEST-- +object normal error +--SKIPIF-- + +--FILE-- +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 index 0000000..a11529d --- /dev/null +++ b/tests/object006.phpt @@ -0,0 +1,22 @@ +--TEST-- +object error suppression2 +--SKIPIF-- + +--FILE-- +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 index 0000000..475b4b8 --- /dev/null +++ b/tests/object007.phpt @@ -0,0 +1,27 @@ +--TEST-- +object error exception2 +--SKIPIF-- + +--FILE-- +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 index 0000000..6dff7d5 --- /dev/null +++ b/tests/object008.phpt @@ -0,0 +1,24 @@ +--TEST-- +object normal error2 +--SKIPIF-- + +--FILE-- +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 index 0000000..4d6e574 --- /dev/null +++ b/tests/object009.phpt @@ -0,0 +1,27 @@ +--TEST-- +object unknown error handling +--SKIPIF-- + +--FILE-- +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 -- 2.30.2