standard return values; fix tests
authorMichael Wallner <mike@php.net>
Fri, 8 Nov 2013 12:58:59 +0000 (12:58 +0000)
committerMichael Wallner <mike@php.net>
Fri, 8 Nov 2013 12:58:59 +0000 (12:58 +0000)
php_http_encoding.c
php_http_message_body.c
phpunit/MessageBodyTest.php

index 54dc19ce3300f23dfd999108a805dad977e4e5c9..27f1de7e2513e3007ad121b67ee75d23dc86a51a 100644 (file)
@@ -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[] = {
index 03ca5c3e11f3eb2d31e3b353b3041fe2eb5cc252..1b5ecc2397f4ef57054bed67f79f08b8f83ebf92 100644 (file)
@@ -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[] = {
index 1764ef6027b89128915420ce2667676fbb27ab3c..253fb55ccc199ca204a850680507a96d7df1c387 100644 (file)
@@ -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",
                 )
             )
         );