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 testAppendError() {
28 $this->setExpectedException("http\Exception\RuntimeException");
29 $this->file
->append("nope");
31 function testAppend() {
32 $this->temp
->append("yes");
35 function testAddForm() {
47 "type" => "text/plain",
52 $file = str_replace("%", "%c", file_get_contents(__FILE__
));
53 $this->assertStringMatchesFormat(
55 "Content-Disposition: form-data; name=\"foo\"\r\n".
59 "Content-Disposition: form-data; name=\"more[0]\"\r\n".
63 "Content-Disposition: form-data; name=\"more[1]\"\r\n".
67 "Content-Disposition: form-data; name=\"more[2]\"\r\n".
71 "Content-Disposition: form-data; name=\"upload\"; filename=\"MessageBodyTest.php\"\r\n".
72 "Content-Transfer-Encoding: binary\r\n".
73 "Content-Type: text/plain\r\n".
78 str_replace("\r", "", $this->temp
) // phpunit replaces \r\n with \n
82 function testAddPart() {
83 $this->temp
->addPart(new http\
Message("This: is a header\n\nand this is the data\n"));
84 $this->assertStringMatchesFormat(
86 "This: is a header\r\n".
87 "Content-Length: 21\r\n".
89 "and this is the data\n\r\n".
92 str_replace("\r", "", $this->temp
)
101 $s["ino"],$s["mtime"],$s["size"]
105 $this->assertEquals(crc32(""), $this->temp
->etag());
108 function testToStream() {
109 $this->file
->toStream($f = fopen("php://temp", "w"));
110 fseek($f, 0, SEEK_SET
);
112 file_get_contents(__FILE__
),
113 fread($f, filesize(__FILE__
))
117 function testToCallback() {
119 $this->file
->toCallback(
120 function($body, $string) use (&$s) { $s.=$string; }
122 $this->assertEquals($s, (string) $this->file
);
125 function testClone() {
126 $this->assertEquals((string) $this->file
, (string) clone $this->file
);
129 function testGetResource() {
130 $stream = $this->file
->getResource();
131 $this->assertTrue(is_resource($stream));
132 $stat = fstat($stream);
133 $this->assertEquals(filesize(__FILE__
), $stat["size"]);