From: Michael Wallner Date: Thu, 8 Nov 2012 13:46:20 +0000 (+0000) Subject: better PHP-5.3 compatibility X-Git-Tag: RELEASE_2_1_0_RC3~10^2^2~102 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=d5de4f9eae86ae1dab0f8a906bf9543710ae124d;p=m6w6%2Fext-http better PHP-5.3 compatibility --- diff --git a/php_http_client.c b/php_http_client.c index 8f51a03..79a0ef8 100644 --- a/php_http_client.c +++ b/php_http_client.c @@ -296,11 +296,8 @@ zend_object_value php_http_client_object_new_ex(zend_class_entry *ce, php_http_c o = ecalloc(1, sizeof(*o)); zend_object_std_init((zend_object *) o, ce TSRMLS_CC); -#if PHP_VERSION_ID < 50339 - zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); -#else object_properties_init((zend_object *) o, ce); -#endif + ov.handle = zend_objects_store_put(o, NULL, php_http_client_object_free, NULL TSRMLS_CC); ov.handlers = &php_http_client_object_handlers; diff --git a/php_http_client_datashare.c b/php_http_client_datashare.c index 5f7a90a..387df53 100644 --- a/php_http_client_datashare.c +++ b/php_http_client_datashare.c @@ -147,11 +147,7 @@ PHP_HTTP_BEGIN_ARGS(detach, 1) PHP_HTTP_ARG_OBJ(http\\Client, client, 0) PHP_HTTP_END_ARGS; -static void php_http_client_datashare_object_write_prop(zval *object, zval *member, zval *value -#if PHP_VERSION_ID >= 50400 -, const zend_literal *literal_key -#endif -TSRMLS_DC); +static void php_http_client_datashare_object_write_prop(zval *object, zval *member, zval *value PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC); static zend_class_entry *php_http_client_datashare_class_entry; @@ -205,11 +201,7 @@ zend_object_value php_http_client_datashare_object_new_ex(zend_class_entry *ce, o = ecalloc(1, sizeof(*o)); zend_object_std_init((zend_object *) o, ce TSRMLS_CC); -#if PHP_VERSION_ID < 50339 - zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); -#else object_properties_init((zend_object *) o, ce); -#endif ov.handle = zend_objects_store_put(o, NULL, php_http_client_datashare_object_free, NULL TSRMLS_CC); ov.handlers = &php_http_client_datashare_object_handlers; @@ -234,11 +226,7 @@ void php_http_client_datashare_object_free(void *object TSRMLS_DC) efree(o); } -static void php_http_client_datashare_object_write_prop(zval *object, zval *member, zval *value -#if PHP_VERSION_ID >= 50400 -, const zend_literal *literal_key -#endif -TSRMLS_DC) +static void php_http_client_datashare_object_write_prop(zval *object, zval *member, zval *value PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC) { zend_property_info *pi; @@ -262,18 +250,10 @@ TSRMLS_DC) } } - zend_get_std_object_handlers()->write_property(object, member, value -#if PHP_VERSION_ID >= 50400 - , literal_key -#endif - TSRMLS_CC); + zend_get_std_object_handlers()->write_property(object, member, value PHP_HTTP_ZEND_LITERAL_CC TSRMLS_CC); } -static zval **php_http_client_datashare_object_get_prop_ptr(zval *object, zval *member -#if PHP_VERSION_ID >= 50400 -, const zend_literal *literal_key -#endif -TSRMLS_DC) +static zval **php_http_client_datashare_object_get_prop_ptr(zval *object, zval *member PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC) { zend_property_info *pi; @@ -281,11 +261,7 @@ TSRMLS_DC) return &php_http_property_proxy_init(NULL, object, member, NULL TSRMLS_CC)->myself; } - return zend_get_std_object_handlers()->get_property_ptr_ptr(object, member -#if PHP_VERSION_ID >= 50400 - , literal_key -#endif - TSRMLS_CC); + return zend_get_std_object_handlers()->get_property_ptr_ptr(object, member PHP_HTTP_ZEND_LITERAL_CC TSRMLS_CC); } diff --git a/php_http_client_pool.c b/php_http_client_pool.c index 93e5e0a..04a7306 100644 --- a/php_http_client_pool.c +++ b/php_http_client_pool.c @@ -321,11 +321,7 @@ zend_object_value php_http_client_pool_object_new_ex(zend_class_entry *ce, php_h o = ecalloc(1, sizeof(php_http_client_pool_object_t)); zend_object_std_init((zend_object *) o, ce TSRMLS_CC); -#if PHP_VERSION_ID < 50339 - zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); -#else object_properties_init((zend_object *) o, ce); -#endif if (!(o->pool = p)) { o->pool = php_http_client_pool_init(NULL, &php_http_client_pool_user_ops, NULL, NULL TSRMLS_CC); diff --git a/php_http_cookie.c b/php_http_cookie.c index 5b78abb..6908d38 100644 --- a/php_http_cookie.c +++ b/php_http_cookie.c @@ -463,11 +463,7 @@ zend_object_value php_http_cookie_object_new_ex(zend_class_entry *ce, php_http_c o = ecalloc(sizeof(*o), 1); zend_object_std_init((zend_object *) o, ce TSRMLS_CC); -#if PHP_VERSION_ID < 50339 - zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); -#else object_properties_init((zend_object *) o, ce); -#endif if (list) { o->list = list; diff --git a/php_http_curl_client.c b/php_http_curl_client.c index 01678d8..32dbb7e 100644 --- a/php_http_curl_client.c +++ b/php_http_curl_client.c @@ -1307,11 +1307,7 @@ zend_object_value php_http_curl_client_object_new_ex(zend_class_entry *ce, php_h o = ecalloc(1, sizeof(php_http_client_object_t)); zend_object_std_init((zend_object *) o, ce TSRMLS_CC); -#if PHP_VERSION_ID < 50339 - zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); -#else object_properties_init((zend_object *) o, ce); -#endif if (!(o->client = r)) { o->client = php_http_client_init(NULL, &php_http_curl_client_ops, NULL, NULL TSRMLS_CC); diff --git a/php_http_curl_client_datashare.c b/php_http_curl_client_datashare.c index 1c9cf4d..3668512 100644 --- a/php_http_curl_client_datashare.c +++ b/php_http_curl_client_datashare.c @@ -191,11 +191,7 @@ zend_object_value php_http_curl_client_datashare_object_new_ex(zend_class_entry o = ecalloc(1, sizeof(*o)); zend_object_std_init((zend_object *) o, ce TSRMLS_CC); -#if PHP_VERSION_ID < 50339 - zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); -#else object_properties_init((zend_object *) o, ce); -#endif if (share) { o->share = share; diff --git a/php_http_curl_client_pool.c b/php_http_curl_client_pool.c index ddac5c1..6ae1da6 100644 --- a/php_http_curl_client_pool.c +++ b/php_http_curl_client_pool.c @@ -527,11 +527,7 @@ zend_object_value php_http_curl_client_pool_object_new_ex(zend_class_entry *ce, o = ecalloc(1, sizeof(php_http_client_pool_object_t)); zend_object_std_init((zend_object *) o, ce TSRMLS_CC); -#if PHP_VERSION_ID < 50339 - zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); -#else object_properties_init((zend_object *) o, ce); -#endif if (!(o->pool = p)) { o->pool = php_http_client_pool_init(NULL, &php_http_curl_client_pool_ops, NULL, NULL TSRMLS_CC); diff --git a/php_http_encoding.c b/php_http_encoding.c index c84c309..4a71c80 100644 --- a/php_http_encoding.c +++ b/php_http_encoding.c @@ -959,11 +959,7 @@ zend_object_value php_http_encoding_stream_object_new_ex(zend_class_entry *ce, p o = ecalloc(1, sizeof(*o)); zend_object_std_init((zend_object *) o, ce TSRMLS_CC); -#if PHP_VERSION_ID < 50339 - zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); -#else object_properties_init((zend_object *) o, ce); -#endif if (ptr) { *ptr = o; diff --git a/php_http_env.c b/php_http_env.c index 3ca996f..f2d4a38 100644 --- a/php_http_env.c +++ b/php_http_env.c @@ -4,7 +4,7 @@ +--------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the conditions mentioned | - | in the accomp395anying LICENSE file are met. | + | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ | Copyright (c) 2004-2011, Michael Wallner | +--------------------------------------------------------------------+ @@ -987,7 +987,7 @@ PHP_METHOD(HttpEnv, cleanPersistentHandles) static SAPI_POST_HANDLER_FUNC(php_http_json_post_handler) { if (SG(request_info).raw_post_data) { - php_json_decode_ex(arg, SG(request_info).raw_post_data, SG(request_info).raw_post_data_length, PHP_JSON_OBJECT_AS_ARRAY, PG(max_input_nesting_level) TSRMLS_CC); + php_json_decode(arg, SG(request_info).raw_post_data, SG(request_info).raw_post_data_length, 1, PG(max_input_nesting_level) TSRMLS_CC); } } diff --git a/php_http_env_response.c b/php_http_env_response.c index c3cf80b..d88fb72 100644 --- a/php_http_env_response.c +++ b/php_http_env_response.c @@ -189,6 +189,9 @@ static size_t output(void *context, char *buf, size_t len TSRMLS_DC) if (!(php_output_get_status(TSRMLS_C) & PHP_OUTPUT_IMPLICITFLUSH)) { sapi_flush(TSRMLS_C); } +#else + php_end_ob_buffer(1, 1 TSRMLS_CC); + sapi_flush(TSRMLS_C); #endif php_http_sleep(r->throttle.delay); } diff --git a/php_http_message.c b/php_http_message.c index a93d9f5..e4b4660 100644 --- a/php_http_message.c +++ b/php_http_message.c @@ -89,7 +89,7 @@ PHP_HTTP_API php_http_message_t *php_http_message_init_env(php_http_message_t *m } php_http_env_get_response_headers(&message->hdrs TSRMLS_CC); - +#if PHP_VERSION_ID >= 50400 if (php_output_get_level(TSRMLS_C)) { if (php_output_get_status(TSRMLS_C) & PHP_OUTPUT_SENT) { php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "Could not fetch response body, output has already been sent at %s:%d", php_output_get_start_filename(TSRMLS_C), php_output_get_start_lineno(TSRMLS_C)); @@ -102,6 +102,7 @@ PHP_HTTP_API php_http_message_t *php_http_message_init_env(php_http_message_t *m zval_dtor(&tval); } } +#endif break; default: @@ -671,9 +672,9 @@ PHP_HTTP_BEGIN_ARGS(isMultipart, 0) PHP_HTTP_END_ARGS; PHP_HTTP_EMPTY_ARGS(splitMultipartBody); -static zval *php_http_message_object_read_prop(zval *object, zval *member, int type, const zend_literal *literal_key TSRMLS_DC); -static void php_http_message_object_write_prop(zval *object, zval *member, zval *value, const zend_literal *literal_key TSRMLS_DC); -static zval **php_http_message_object_get_prop_ptr(zval *object, zval *member, const zend_literal *literal_key TSRMLS_DC); +static zval *php_http_message_object_read_prop(zval *object, zval *member, int type PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC); +static void php_http_message_object_write_prop(zval *object, zval *member, zval *value PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC); +static zval **php_http_message_object_get_prop_ptr(zval *object, zval *member PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC); static HashTable *php_http_message_object_get_props(zval *object TSRMLS_DC); static zend_class_entry *php_http_message_class_entry; @@ -1140,7 +1141,7 @@ void php_http_message_object_free(void *object TSRMLS_DC) } -static zval **php_http_message_object_get_prop_ptr(zval *object, zval *member, const zend_literal *literal_key TSRMLS_DC) +static zval **php_http_message_object_get_prop_ptr(zval *object, zval *member PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC) { php_http_message_object_prophandler_t *handler; zval *copy = php_http_ztyp(IS_STRING, member); @@ -1151,10 +1152,10 @@ static zval **php_http_message_object_get_prop_ptr(zval *object, zval *member, c } zval_ptr_dtor(©); - return zend_get_std_object_handlers()->get_property_ptr_ptr(object, member, literal_key TSRMLS_CC); + return zend_get_std_object_handlers()->get_property_ptr_ptr(object, member PHP_HTTP_ZEND_LITERAL_CC TSRMLS_CC); } -static zval *php_http_message_object_read_prop(zval *object, zval *member, int type, const zend_literal *literal_key TSRMLS_DC) +static zval *php_http_message_object_read_prop(zval *object, zval *member, int type PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC) { php_http_message_object_t *obj = zend_object_store_get_object(object TSRMLS_CC); php_http_message_object_prophandler_t *handler; @@ -1172,7 +1173,7 @@ static zval *php_http_message_object_read_prop(zval *object, zval *member, int t return_value = NULL; } } else { - return_value = zend_get_std_object_handlers()->read_property(object, member, type, literal_key TSRMLS_CC); + return_value = zend_get_std_object_handlers()->read_property(object, member, type PHP_HTTP_ZEND_LITERAL_CC TSRMLS_CC); } zval_ptr_dtor(©); @@ -1180,7 +1181,7 @@ static zval *php_http_message_object_read_prop(zval *object, zval *member, int t return return_value; } -static void php_http_message_object_write_prop(zval *object, zval *member, zval *value, const zend_literal *literal_key TSRMLS_DC) +static void php_http_message_object_write_prop(zval *object, zval *member, zval *value PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC) { php_http_message_object_t *obj = zend_object_store_get_object(object TSRMLS_CC); php_http_message_object_prophandler_t *handler; @@ -1189,7 +1190,7 @@ static void php_http_message_object_write_prop(zval *object, zval *member, zval if (SUCCESS == php_http_message_object_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) { handler->write(obj, value TSRMLS_CC); } else { - zend_get_std_object_handlers()->write_property(object, member, value, literal_key TSRMLS_CC); + zend_get_std_object_handlers()->write_property(object, member, value PHP_HTTP_ZEND_LITERAL_CC TSRMLS_CC); } zval_ptr_dtor(©); diff --git a/php_http_message_body.c b/php_http_message_body.c index 40a1688..cf22e70 100644 --- a/php_http_message_body.c +++ b/php_http_message_body.c @@ -617,11 +617,7 @@ zend_object_value php_http_message_body_object_new_ex(zend_class_entry *ce, php_ o = ecalloc(1, sizeof(php_http_message_body_object_t)); zend_object_std_init((zend_object *) o, php_http_message_body_class_entry TSRMLS_CC); -#if PHP_VERSION_ID < 50339 - zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); -#else object_properties_init((zend_object *) o, ce); -#endif if (ptr) { *ptr = o; diff --git a/php_http_misc.h b/php_http_misc.h index 972ba92..54e1ac5 100644 --- a/php_http_misc.h +++ b/php_http_misc.h @@ -151,6 +151,21 @@ static inline const char *php_http_locate_bin_eol(const char *bin, size_t len, i /* ZEND */ +#if PHP_VERSION_ID < 50400 +# define object_properties_init(o, ce) zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)) +# define PHP_HTTP_ZEND_LITERAL_DC +# define PHP_HTTP_ZEND_LITERAL_CC +# define PHP_HTTP_ZEND_LITERAL_CCN +# define ZVAL_COPY_VALUE(zv, arr) do { \ + (zv)->value = (arr)->value; \ + Z_TYPE_P(zv) = Z_TYPE_P(arr); \ + } while (0) +#else +# define PHP_HTTP_ZEND_LITERAL_DC , const zend_literal *literal_key +# define PHP_HTTP_ZEND_LITERAL_CC , (literal_key) +# define PHP_HTTP_ZEND_LITERAL_CCN , NULL +#endif + #define INIT_PZVAL_ARRAY(zv, ht) \ { \ INIT_PZVAL((zv)); \ diff --git a/php_http_object.c b/php_http_object.c index f85960f..c278e6b 100644 --- a/php_http_object.c +++ b/php_http_object.c @@ -98,11 +98,7 @@ zend_object_value php_http_object_new_ex(zend_class_entry *ce, void *nothing, ph o = ecalloc(1, sizeof(php_http_object_t)); zend_object_std_init((zend_object *) o, ce TSRMLS_CC); -#if PHP_VERSION_ID < 50339 - zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); -#else object_properties_init((zend_object *) o, ce); -#endif if (ptr) { *ptr = o; diff --git a/php_http_property_proxy.c b/php_http_property_proxy.c index 781c0c0..f4d3523 100644 --- a/php_http_property_proxy.c +++ b/php_http_property_proxy.c @@ -91,11 +91,7 @@ zend_object_value php_http_property_proxy_object_new_ex(zend_class_entry *ce, ph o = ecalloc(1, sizeof(*o)); zend_object_std_init((zend_object *) o, ce TSRMLS_CC); -#if PHP_VERSION_ID < 50339 - zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); -#else object_properties_init((zend_object *) o, ce); -#endif if (ptr) { *ptr = o; diff --git a/php_http_querystring.c b/php_http_querystring.c index e14504c..2c6ca28 100644 --- a/php_http_querystring.c +++ b/php_http_querystring.c @@ -468,7 +468,7 @@ PHP_METHOD(HttpQueryString, getGlobalInstance) with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { if (SUCCESS == zend_parse_parameters_none()) { with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { - zval *instance = *zend_std_get_static_property(php_http_querystring_class_entry, ZEND_STRL("instance"), 0, NULL TSRMLS_CC); + zval *instance = *zend_std_get_static_property(php_http_querystring_class_entry, ZEND_STRL("instance"), 0 PHP_HTTP_ZEND_LITERAL_CCN TSRMLS_CC); if (Z_TYPE_P(instance) != IS_OBJECT) { zval **_GET = NULL; diff --git a/phpunit.php b/phpunit.php new file mode 100644 index 0000000..8a61937 --- /dev/null +++ b/phpunit.php @@ -0,0 +1,4 @@ +run(array_merge($argv, array(__DIR__."/phpunit/"))); diff --git a/phpunit/ObjectTest.php b/phpunit/ObjectTest.php index bce3a52..968f3f8 100644 --- a/phpunit/ObjectTest.php +++ b/phpunit/ObjectTest.php @@ -19,19 +19,22 @@ class ObjectTest extends PHPUnit_Framework_TestCase { function testSuppress() { http\Object::setDefaultErrorHandling(http\Object::EH_SUPPRESS); - (new eh)->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "suppress"); + $o = new eh; + $o->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "suppress"); } function testException() { http\Object::setDefaultErrorHandling(http\Object::EH_THROW); $this->setExpectedException("http\\Exception"); - (new eh)->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "exception"); + $o = new eh; + $o->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "exception"); } function testNormalError() { http\Object::setDefaultErrorHandling(http\Object::EH_NORMAL); $this->setExpectedException("PHPUnit_Framework_Error_Warning"); - (new eh)->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "warning"); + $o = new eh; + $o->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "warning"); } function testSuppress2() { diff --git a/phpunit/RequestTest.php b/phpunit/RequestTest.php index a327f6d..136b29f 100644 --- a/phpunit/RequestTest.php +++ b/phpunit/RequestTest.php @@ -28,7 +28,8 @@ class RequestTest extends PHPUnit_Framework_TestCase protected $r; function setUp() { - $this->r = (new http\Client\Factory)->createClient(); + $f = new http\Client\Factory; + $this->r = $f->createClient(); $this->r->setOptions( array( "connecttimeout" => 30, @@ -55,19 +56,20 @@ class RequestTest extends PHPUnit_Framework_TestCase } function testObserver() { + $test = $this; $this->r->attach($o1 = new ProgressObserver1); $this->r->attach($o2 = new ProgressObserver2); $this->r->attach( $o3 = new CallbackObserver( - function ($r) { + function ($r) use ($test) { $p = (array) $r->getProgress(); - $this->assertArrayHasKey("started", $p); - $this->assertArrayHasKey("finished", $p); - $this->assertArrayHasKey("dlnow", $p); - $this->assertArrayHasKey("ulnow", $p); - $this->assertArrayHasKey("dltotal", $p); - $this->assertArrayHasKey("ultotal", $p); - $this->assertArrayHasKey("info", $p); + $test->assertArrayHasKey("started", $p); + $test->assertArrayHasKey("finished", $p); + $test->assertArrayHasKey("dlnow", $p); + $test->assertArrayHasKey("ulnow", $p); + $test->assertArrayHasKey("dltotal", $p); + $test->assertArrayHasKey("ultotal", $p); + $test->assertArrayHasKey("info", $p); } ) ); diff --git a/phpunit/UrlTest.php b/phpunit/UrlTest.php index 50fa2ff..dcf3b4f 100644 --- a/phpunit/UrlTest.php +++ b/phpunit/UrlTest.php @@ -43,6 +43,7 @@ class UrlTest extends PHPUnit_Framework_TestCase { function testArrays() { $url = new http\Url($this->url); - $this->assertEquals($url->toArray(), (new http\Url($url->toArray()))->toArray()); + $url2 = new http\Url($url->toArray()); + $this->assertEquals($url->toArray(), $url2->toArray()); } } diff --git a/reflection2php.php b/reflection2php.php index e319bd4..aa238ed 100755 --- a/reflection2php.php +++ b/reflection2php.php @@ -31,6 +31,8 @@ function c($n, $c) { if (!strlen($ext = $argv[1])) die(sprintf("Usage: %s \n", $argv[0])); +printf("getConstants() as $constant => $value) { printf("const %s = %s;\n", $constant, $value); @@ -111,7 +113,12 @@ foreach ($classes as $class) { } $ps[] = $p1; } - printf("%s) {\n\t\t}\n", implode(", ", $ps)); + printf("%s)", implode(", ", $ps)); + if ($m->isAbstract()) { + printf(";\n\n"); + } else { + printf(" {\n\t\t}\n\n"); + } } } diff --git a/tests/etag001.phpt b/tests/etag001.phpt index 77659d3..4a86681 100644 --- a/tests/etag001.phpt +++ b/tests/etag001.phpt @@ -1,7 +1,11 @@ --TEST-- etags with hash --SKIPIF-- - +=") or die("skip PHP>=5.4 required"); +?> --FILE-- "nonexistant")))->{"create$type"}()); + $f = new http\Client\Factory(array("driver" => "nonexistant")); + var_dump($f->{"create$type"}()); } catch (Exception $e) { echo $e->getMessage(), "\n"; } diff --git a/tests/message004.phpt b/tests/message004.phpt index de2e4e4..914a8da 100644 --- a/tests/message004.phpt +++ b/tests/message004.phpt @@ -8,12 +8,16 @@ include "skip.inc"; use http\Message as HttpMessage; +function newHttpMessage($s) { + return new http\Message($s); +} + $s = "GET /first HTTP/1.1\nHTTP/1.1 200 Ok-first\nGET /second HTTP/1.1\nHTTP/1.1 200 Ok-second\nGET /third HTTP/1.1\nHTTP/1.1 200 Ok-third\n"; -echo (new HttpMessage($s))->toString(true); +echo newHttpMessage($s)->toString(true); echo "===\n"; -echo (new HttpMessage($s))->reverse()->toString(true); +echo newHttpMessage($s)->reverse()->toString(true); -$m = new HttpMessage($s); +$m = newHttpMessage($s); $r = $m->reverse(); unset($m); var_dump($r->count()); diff --git a/tests/persistenthandles001.phpt b/tests/persistenthandles001.phpt index 01f5069..18bce8a 100644 --- a/tests/persistenthandles001.phpt +++ b/tests/persistenthandles001.phpt @@ -4,12 +4,12 @@ persistent handles --FILE-- "foo"))) - ->createClient()->setRequest(new http\Client\Request("GET", "http://dev.iworks.at")) +$f = new http\Client\Factory(array("persistentHandleId" => "foo")); +$r = $f->createClient()->setRequest(new http\Client\Request("GET", "http://dev.iworks.at")) ->setOptions(array("connecttimeout"=> 90, "timeout" =>300)) - ->send(null); -$r = (new http\Client\Factory(array("persistentHandleId" => "bar"))) - ->createClient()->setRequest(new http\Client\Request("GET", "http://dev.iworks.at")) + ->send(null); +$f = new http\Client\Factory(array("persistentHandleId" => "bar")); +$r = $f->createClient()->setRequest(new http\Client\Request("GET", "http://dev.iworks.at")) ->setOptions(array("connecttimeout"=> 90, "timeout" =>300)); var_dump(http\Env::statPersistentHandles()); diff --git a/tests/phpunit.phpt b/tests/phpunit.phpt index 6320f61..9c106f0 100644 --- a/tests/phpunit.phpt +++ b/tests/phpunit.phpt @@ -2,12 +2,13 @@ unit tests --SKIPIF-- --FILE-- run([null, __DIR__."/../phpunit"]); +$c = new PHPUnit_TextUI_Command; +$c->run(array("--process-isolation", __DIR__."/../phpunit/")); ?> --EXPECTF-- PHPUnit %s by Sebastian Bergmann. diff --git a/tests/response003.phpt b/tests/response003.phpt index f83df3b..8331e0f 100644 --- a/tests/response003.phpt +++ b/tests/response003.phpt @@ -12,7 +12,7 @@ a=b $r = new http\Env\Response; $r->setContentType("text/plain"); $r->setContentDisposition( - ["attachment" => ["filename" => basename(__FILE__)]] + array("attachment" => array("filename" => basename(__FILE__))) ); $r->setBody(new http\Message\Body(fopen(__FILE__, "rb"))); $r->send(); diff --git a/tests/serialize001.phpt b/tests/serialize001.phpt index 2e06afe..b37b230 100644 --- a/tests/serialize001.phpt +++ b/tests/serialize001.phpt @@ -23,7 +23,7 @@ foreach ($ext->getClasses() as $class) { $serialized = serialize($instance); $unserialized = unserialize($serialized); - foreach (["toString", "toArray"] as $m) { + foreach (array("toString", "toArray") as $m) { if ($class->hasMethod($m)) { #printf("%s#%s\n", $class->getName(), $m); $unserialized->$m(); @@ -31,7 +31,9 @@ foreach ($ext->getClasses() as $class) { } if ($class->hasMethod("attach") && !$class->implementsInterface("\\SplSubject")) { #printf("%s#%s\n", $class->getName(), "attach"); - $unserialized->attach((new http\Curl\Client)->setRequest(new http\Client\Request("GET", "http://localhost"))); + $c = new http\Curl\Client; + $c->setRequest(new http\Client\Request("GET", "http://localhost")); + $unserialized->attach($c); } } }