removed awkward custom error handling and http\Object base class
[m6w6/ext-http] / phpunit / MessageBodyTest.php
index 4ef4efe43814f7f2a9c0ed0018c1d5247b2b17ce..3aaf3eb838b0f487d8e72f4ac74175c5bfcbc5c7 100644 (file)
@@ -14,7 +14,7 @@ class MessageBodyTest extends PHPUnit_Framework_TestCase {
         $this->assertEquals(fileatime(__FILE__), $this->file->stat("atime"));
         $this->assertEquals(filectime(__FILE__), $this->file->stat("ctime"));
         $this->assertEquals(
-            array(
+            (object) array(
                 "size" => 0,
                 "mtime" => 0,
                 "atime" => 0,
@@ -24,26 +24,27 @@ class MessageBodyTest extends PHPUnit_Framework_TestCase {
         );
     }
 
+    function testAppendError() {
+       $this->setExpectedException("http\Exception\RuntimeException");
+        $this->file->append("nope");
+    }
     function testAppend() {
-        $this->assertEquals(0, $this->file->append("nope"));
-        $this->assertEquals(3, $this->temp->append("yes"));
+        $this->temp->append("yes");
     }
 
     function testAddForm() {
-        $this->assertTrue( 
-            $this->temp->addForm(
-                array(
-                    "foo" => "bar",
-                    "more" => array(
-                        "bah", "baz", "fuz"
-                    ),
+        $this->temp->addForm(
+            array(
+                "foo" => "bar",
+                "more" => array(
+                    "bah", "baz", "fuz"
                 ),
+            ),
+            array(
                 array(
-                    array(
-                        "file" => __FILE__,
-                        "name" => "upload",
-                        "type" => "text/plain",
-                    )
+                    "file" => __FILE__,
+                    "name" => "upload",
+                    "type" => "text/plain",
                 )
             )
         );
@@ -78,6 +79,20 @@ class MessageBodyTest extends PHPUnit_Framework_TestCase {
         );
     }
 
+    function testAddPart() {
+        $this->temp->addPart(new http\Message("This: is a header\n\nand this is the data\n"));
+        $this->assertStringMatchesFormat(
+            "--%x.%x\r\n".
+            "This: is a header\r\n".
+            "Content-Length: 21\r\n".
+            "\r\n".
+            "and this is the data\n\r\n".
+            "--%x.%x--\r\n".
+            "",
+            str_replace("\r", "", $this->temp)
+        );
+    }
+
     function testEtag() {
         $s = stat(__FILE__);
         $this->assertEquals(
@@ -110,4 +125,11 @@ class MessageBodyTest extends PHPUnit_Framework_TestCase {
     function testClone() {
         $this->assertEquals((string) $this->file, (string) clone $this->file);
     }
+    
+    function testGetResource() {
+       $stream = $this->file->getResource();
+       $this->assertTrue(is_resource($stream));
+       $stat = fstat($stream);
+       $this->assertEquals(filesize(__FILE__), $stat["size"]);
+    }
 }