From fdcb99c1e9f3e0f959e1cf490cf8cda1803fe03d Mon Sep 17 00:00:00 2001 From: php-curl-class Date: Wed, 21 Aug 2013 16:17:06 -0700 Subject: [PATCH] Add PUT file handle test --- tests/helper.inc.php | 7 +++++++ tests/run.php | 17 +++++++++++++++++ tests/server.php | 7 +++++++ 3 files changed, 31 insertions(+) diff --git a/tests/helper.inc.php b/tests/helper.inc.php index 5075c67..62129e7 100644 --- a/tests/helper.inc.php +++ b/tests/helper.inc.php @@ -24,6 +24,13 @@ function create_png() { return $raw_image; } +function create_tmp_file($data) { + $tmp_file = tmpfile(); + fwrite($tmp_file, $data); + rewind($tmp_file); + return $tmp_file; +} + function get_png() { $tmp_filename = tempnam('/tmp', 'php-curl-class.'); file_put_contents($tmp_filename, create_png()); diff --git a/tests/run.php b/tests/run.php index 35b7ea4..98f9874 100644 --- a/tests/run.php +++ b/tests/run.php @@ -72,6 +72,23 @@ class CurlTest extends PHPUnit_Framework_TestCase { )) === 'put'); } + public function testPutFileHandle() { + $png = create_png(); + $tmp_file = create_tmp_file($png); + + $test = new Test(); + $test->curl->setopt(CURLOPT_PUT, TRUE); + $test->curl->setopt(CURLOPT_INFILE, $tmp_file); + $test->curl->setopt(CURLOPT_INFILESIZE, strlen($png)); + $test->curl->put(Test::TEST_URL, array( + 'test' => 'put_file_handle', + )); + + fclose($tmp_file); + + $this->assertTrue($test->curl->response === 'image/png'); + } + public function testDelete() { $test = new Test(); $this->assertTrue($test->server('DELETE', array( diff --git a/tests/server.php b/tests/server.php index 33b78ee..49d156f 100644 --- a/tests/server.php +++ b/tests/server.php @@ -23,6 +23,13 @@ else if ($test === 'post_file_path_upload') { echo mime_content_type($_FILES[$key]['tmp_name']); exit; } +else if ($test === 'put_file_handle') { + $tmp_filename = tempnam('/tmp', 'php-curl-class.'); + file_put_contents($tmp_filename, file_get_contents('php://input')); + echo mime_content_type($tmp_filename); + unlink($tmp_filename); + exit; +} header('Content-Type: text/plain');