converted phpunit ClientRequestTest to PHPTs
[m6w6/ext-http] / phpunit / MessageTest.php
index 6dd5b707bbf665e75baddbb33d00bfbaf5d728fe..b572f57273adfb0192dc3536ba65c88ae74737cd 100644 (file)
@@ -46,6 +46,13 @@ class MessageTest extends PHPUnit_Framework_TestCase
                $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());
@@ -134,7 +141,7 @@ class MessageTest extends PHPUnit_Framework_TestCase
                        array(
                                array(
                                        "cookies" => array("foo" => "bar"),
-                                       "expires" => date_create("2012-12-31 23:59:59")->format(
+                                       "expires" => date_create("2012-12-31 22:59:59 GMT")->format(
                                                DateTime::COOKIE
                                        ),
                                        "path" => "/somewhere"
@@ -195,6 +202,25 @@ class MessageTest extends PHPUnit_Framework_TestCase
                );
        }
        
+       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 {
@@ -212,7 +238,7 @@ class MessageTest extends PHPUnit_Framework_TestCase
                
                $d = new http\Encoding\Stream\Deflate;
                $s = "";
-               $m->toCallback(function ($m, $data) use ($d) {
+               $m->toCallback(function ($m, $data) use ($d, &$s) {
                        $s.=$d->update($data);
                });
                $s.=$d->finish();
@@ -240,7 +266,7 @@ class MessageTest extends PHPUnit_Framework_TestCase
                $m->getBody()->addPart($p);
                $this->assertStringMatchesFormat(
                        "HTTP/1.1 200\r\n".
-                       "Content-Length: 97\r\n".
+                       "Content-Length: %d\r\n".
                        "Content-Type: multipart/form-data; boundary=\"%x.%x\"\r\n".
                        "\r\n".
                        "--%x.%x\r\n".