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"));
32 function testAddForm() {
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: form-data; 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
81 function testAddPart() {
82 $this->temp
->addPart(new http\
Message("This: is a header\n\nand this is the data\n"));
83 $this->assertStringMatchesFormat(
85 "This: is a header\r\n".
86 "Content-Length: 21\r\n".
88 "and this is the data\n\r\n".
91 str_replace("\r", "", $this->temp
)
100 $s["ino"],$s["mtime"],$s["size"]
104 $this->assertEquals(crc32(""), $this->temp
->etag());
107 function testToStream() {
108 $this->file
->toStream($f = fopen("php://temp", "w"));
109 fseek($f, 0, SEEK_SET
);
111 file_get_contents(__FILE__
),
112 fread($f, filesize(__FILE__
))
116 function testToCallback() {
118 $this->file
->toCallback(
119 function($body, $string) use (&$s) { $s.=$string; }
121 $this->assertEquals($s, (string) $this->file
);
124 function testClone() {
125 $this->assertEquals((string) $this->file
, (string) clone $this->file
);
128 function testGetResource() {
129 $stream = $this->file
->getResource();
130 $this->assertTrue(is_resource($stream));
131 $stat = fstat($stream);
132 $this->assertEquals(filesize(__FILE__
), $stat["size"]);