From 1bcceb6d155dfed7e352f9559974527787d1ae97 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 8 Nov 2013 12:58:59 +0000 Subject: [PATCH] standard return values; fix tests --- php_http_encoding.c | 6 +----- php_http_message_body.c | 40 +++++++++++++++++++------------------ phpunit/MessageBodyTest.php | 31 ++++++++++++++-------------- 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/php_http_encoding.c b/php_http_encoding.c index 54dc19c..27f1de7 100644 --- a/php_http_encoding.c +++ b/php_http_encoding.c @@ -1021,7 +1021,6 @@ static PHP_METHOD(HttpEncodingStream, update) } } } - RETURN_FALSE; } ZEND_BEGIN_ARG_INFO_EX(ai_HttpEncodingStream_flush, 0, 0, 0) @@ -1044,10 +1043,9 @@ static PHP_METHOD(HttpEncodingStream, flush) } } } - RETURN_FALSE; } -ZEND_BEGIN_ARG_INFO_EX(ai_HttpEncodingStream_done, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEncodingStream_done, 0, 0, 0) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpEncodingStream, done) { @@ -1058,7 +1056,6 @@ static PHP_METHOD(HttpEncodingStream, done) RETURN_BOOL(php_http_encoding_stream_done(obj->stream)); } } - RETURN_FALSE; } ZEND_BEGIN_ARG_INFO_EX(ai_HttpEncodingStream_finish, 0, 0, 0) @@ -1085,7 +1082,6 @@ static PHP_METHOD(HttpEncodingStream, finish) } } } - RETURN_FALSE; } static zend_function_entry php_http_encoding_stream_methods[] = { diff --git a/php_http_message_body.c b/php_http_message_body.c index 03ca5c3..1b5ecc2 100644 --- a/php_http_message_body.c +++ b/php_http_message_body.c @@ -663,6 +663,8 @@ PHP_METHOD(HttpMessageBody, unserialize) ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_toStream, 0, 0, 1) ZEND_ARG_INFO(0, stream) + ZEND_ARG_INFO(0, offset) + ZEND_ARG_INFO(0, maxlen) ZEND_END_ARG_INFO(); PHP_METHOD(HttpMessageBody, toStream) { @@ -677,13 +679,14 @@ PHP_METHOD(HttpMessageBody, toStream) php_stream_from_zval(stream, &zstream); php_http_message_body_to_stream(obj->body, stream, offset, forlen); - RETURN_TRUE; + RETURN_ZVAL(getThis(), 1, 0); } - RETURN_FALSE; } ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_toCallback, 0, 0, 1) ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, offset) + ZEND_ARG_INFO(0, maxlen) ZEND_END_ARG_INFO(); PHP_METHOD(HttpMessageBody, toCallback) { @@ -703,9 +706,8 @@ PHP_METHOD(HttpMessageBody, toCallback) zend_fcall_info_args_clear(&fcd.fci, 1); zval_ptr_dtor(&fcd.fcz); - RETURN_TRUE; + RETURN_ZVAL(getThis(), 1, 0); } - RETURN_FALSE; } ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_getResource, 0, 0, 0) @@ -735,9 +737,11 @@ PHP_METHOD(HttpMessageBody, append) PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj); - RETURN_LONG(php_http_message_body_append(obj->body, str, len)); + if (len != php_http_message_body_append(obj->body, str, len)) { + php_http_error(HE_WARNING, PHP_HTTP_E_MESSAGE_BODY, "Could not append to body"); + } + RETURN_ZVAL(getThis(), 1, 0); } - RETURN_FALSE; } ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_addForm, 0, 0, 0) @@ -753,9 +757,9 @@ PHP_METHOD(HttpMessageBody, addForm) PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj); - RETURN_BOOL(SUCCESS == php_http_message_body_add_form(obj->body, fields, files)); + php_http_message_body_add_form(obj->body, fields, files); + RETURN_ZVAL(getThis(), 1, 0); } - RETURN_FALSE; } ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_addPart, 0, 0, 1) @@ -772,9 +776,8 @@ PHP_METHOD(HttpMessageBody, addPart) PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj); php_http_message_body_add_part(obj->body, mobj->message); - RETURN_TRUE; + RETURN_ZVAL(getThis(), 1, 0); } - RETURN_FALSE; } ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_etag, 0, 0, 0) @@ -789,13 +792,14 @@ PHP_METHOD(HttpMessageBody, etag) if ((etag = php_http_message_body_etag(obj->body))) { RETURN_STRING(etag, 0); + } else { + RETURN_FALSE; } } - RETURN_FALSE; } ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_stat, 0, 0, 0) - ZEND_ARG_INFO(0, what) + ZEND_ARG_INFO(0, field) ZEND_END_ARG_INFO(); PHP_METHOD(HttpMessageBody, stat) { @@ -832,16 +836,14 @@ PHP_METHOD(HttpMessageBody, stat) break; } } else { - array_init(return_value); - add_assoc_long_ex(return_value, ZEND_STRS("size"), sb->sb.st_size); - add_assoc_long_ex(return_value, ZEND_STRS("atime"), sb->sb.st_atime); - add_assoc_long_ex(return_value, ZEND_STRS("mtime"), sb->sb.st_mtime); - add_assoc_long_ex(return_value, ZEND_STRS("ctime"), sb->sb.st_ctime); - return; + object_init(return_value); + add_property_long_ex(return_value, ZEND_STRS("size"), sb->sb.st_size); + add_property_long_ex(return_value, ZEND_STRS("atime"), sb->sb.st_atime); + add_property_long_ex(return_value, ZEND_STRS("mtime"), sb->sb.st_mtime); + add_property_long_ex(return_value, ZEND_STRS("ctime"), sb->sb.st_ctime); } } } - RETURN_FALSE; } static zend_function_entry php_http_message_body_methods[] = { diff --git a/phpunit/MessageBodyTest.php b/phpunit/MessageBodyTest.php index 1764ef6..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 testAddForm() { - $this->assertTrue( - $this->temp->addForm( - array( - "foo" => "bar", - "more" => array( - "bah", "baz", "fuz" - ), + $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", ) ) ); -- 2.30.2