X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=phpunit%2FMessageBodyTest.php;h=253fb55ccc199ca204a850680507a96d7df1c387;hb=1bcceb6d155dfed7e352f9559974527787d1ae97;hp=bc07401fa2526b9b3f0e731f96ccfbe5abf0959e;hpb=2e9ac0202f2c5f1cb94e0afd4b66c1c35c316284;p=m6w6%2Fext-http diff --git a/phpunit/MessageBodyTest.php b/phpunit/MessageBodyTest.php index bc07401..253fb55 100644 --- a/phpunit/MessageBodyTest.php +++ b/phpunit/MessageBodyTest.php @@ -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("PHPUnit_Framework_Error"); + $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 testAdd() { - $this->assertTrue( - $this->temp->add( - array( - "foo" => "bar", - "more" => array( - "bah", "baz", "fuz" - ), + function testAddForm() { + $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", ) ) ); @@ -67,7 +68,7 @@ class MessageBodyTest extends PHPUnit_Framework_TestCase { "\r\n". "fuz\r\n". "--%x.%x\r\n". - "Content-Disposition: attachment; name=\"upload\"; filename=\"MessageBodyTest.php\"\r\n". + "Content-Disposition: form-data; name=\"upload\"; filename=\"MessageBodyTest.php\"\r\n". "Content-Transfer-Encoding: binary\r\n". "Content-Type: text/plain\r\n". "\r\n". @@ -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( @@ -87,7 +102,7 @@ class MessageBodyTest extends PHPUnit_Framework_TestCase { ), $this->file->etag() ); - $this->assertEquals(md5(""), $this->temp->etag()); + $this->assertEquals(crc32(""), $this->temp->etag()); } function testToStream() { @@ -106,4 +121,15 @@ class MessageBodyTest extends PHPUnit_Framework_TestCase { ); $this->assertEquals($s, (string) $this->file); } + + 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"]); + } }