3 class MessageBodyTest
extends PHPUnit_Framework_TestCase
{
4 protected $file, $temp;
7 $this->file
= new http\Message\
Body(fopen(__FILE__
, "r"));
8 $this->temp
= new http\Message\
Body();
12 $this->assertEquals(filesize(__FILE__
), $this->file
->stat("size"));
13 $this->assertEquals(filemtime(__FILE__
), $this->file
->stat("mtime"));
14 $this->assertEquals(fileatime(__FILE__
), $this->file
->stat("atime"));
15 $this->assertEquals(filectime(__FILE__
), $this->file
->stat("ctime"));
27 function testAppend() {
28 $this->assertEquals(0, $this->file
->append("nope"));
29 $this->assertEquals(3, $this->temp
->append("yes"));
45 "type" => "text/plain",
51 $file = str_replace("%", "%c", file_get_contents(__FILE__
));
52 $this->assertStringMatchesFormat(
54 "Content-Disposition: form-data; name=\"foo\"\r\n".
58 "Content-Disposition: form-data; name=\"more[0]\"\r\n".
62 "Content-Disposition: form-data; name=\"more[1]\"\r\n".
66 "Content-Disposition: form-data; name=\"more[2]\"\r\n".
70 "Content-Disposition: attachment; name=\"upload\"; filename=\"MessageBodyTest.php\"\r\n".
71 "Content-Transfer-Encoding: binary\r\n".
72 "Content-Type: text/plain\r\n".
77 str_replace("\r", "", $this->temp
) // phpunit replaces \r\n with \n
86 $s["ino"],$s["mtime"],$s["size"]
90 $this->assertEquals(crc32(""), $this->temp
->etag());
93 function testToStream() {
94 $this->file
->toStream($f = fopen("php://temp", "w"));
95 fseek($f, 0, SEEK_SET
);
97 file_get_contents(__FILE__
),
98 fread($f, filesize(__FILE__
))
102 function testToCallback() {
104 $this->file
->toCallback(
105 function($body, $string) use (&$s) { $s.=$string; }
107 $this->assertEquals($s, (string) $this->file
);