Skip to content

moar tests passing #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
language: php
php:
- 5.5
#- 5.4
#- 5.3
- 7.0

env:
- LIBMEMCACHED_VERSION=1.0.17
- LIBMEMCACHED_VERSION=1.0.16
Expand Down
15 changes: 8 additions & 7 deletions .travis/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ function build_php_memcached() {
sasl_flag="--enable-memcached-sasl"
fi

./configure --with-libmemcached-dir="$LIBMEMCACHED_PREFIX" $protocol_flag $sasl_flag --enable-memcached-json --enable-memcached-igbinary --enable-memcached-msgpack
make
# ./configure --with-libmemcached-dir="$LIBMEMCACHED_PREFIX" $protocol_flag $sasl_flag --enable-memcached-json --enable-memcached-igbinary --enable-memcached-msgpack
./configure --with-libmemcached-dir="$LIBMEMCACHED_PREFIX" $protocol_flag $sasl_flag
make
make install
popd
}
Expand All @@ -155,11 +156,11 @@ function run_memcached_tests() {

pushd "${PHP_MEMCACHED_BUILD_DIR}/memcached-${PHP_MEMCACHED_VERSION}"
# We have one xfail test, we run it separately
php run-tests.php -d extension=msgpack.so -d extension=igbinary.so -d extension=memcached.so -n ./tests/expire.phpt
php run-tests.php -d extension=memcached.so -n ./tests/expire.phpt
rm ./tests/expire.phpt

# Run normal tests
php run-tests.php -d extension=msgpack.so -d extension=igbinary.so -d extension=memcached.so -n ./tests/*.phpt
php run-tests.php -d extension=memcached.so -n ./tests/*.phpt
retval=$?
for i in `ls tests/*.out 2>/dev/null`; do
echo "-- START ${i}";
Expand Down Expand Up @@ -213,14 +214,14 @@ case $ACTION in
install_libmemcached

# Install igbinary extension
install_igbinary
# install_igbinary

# install msgpack
install_msgpack
# install_msgpack

# install SASL
if test "x$ENABLE_SASL" = "xyes"; then
install_sasl
install_sasl
fi
;;

Expand Down
40 changes: 21 additions & 19 deletions php_memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ typedef struct {
} php_memc_t;

static inline php_memc_t *php_memc_fetch_object(zend_object *obj) {
return (php_memc_t *)((char *)(obj) - XtOffsetOf(php_memc_t, zo));
return (php_memc_t *)((char *)obj - XtOffsetOf(php_memc_t, zo));
}
#define Z_MEMC_OBJ_P(zv) php_memc_fetch_object(Z_OBJ_P(zv));

Expand Down Expand Up @@ -356,20 +356,17 @@ char *php_memc_printable_func (zend_fcall_info *fci, zend_fcall_info_cache *fci_
static zend_bool php_memcached_on_new_callback(zval *object, zend_fcall_info *fci, zend_fcall_info_cache *fci_cache, zend_string *persistent_id)
{
zend_bool ret = 1;
zval retval;
zval params[2];
zval retval, id;

if (persistent_id) {
ZVAL_STR(&params[1], persistent_id);
ZVAL_STR(&id, persistent_id);
} else {
ZVAL_NULL(&params[1]);
ZVAL_NULL(&id);
}

/* Call the cb */
ZVAL_COPY(&params[0], object);
ZVAL_UNDEF(&retval);

fci->params = params;
fci->param_count = 2;
zend_fcall_info_argn(fci, 2, object, &id);
fci->retval = &retval;
fci->no_separation = 1;

Expand All @@ -379,10 +376,12 @@ static zend_bool php_memcached_on_new_callback(zval *object, zend_fcall_info *fc
efree (buf);
ret = 0;
}

if (Z_TYPE(retval) != IS_UNDEF)
zval_ptr_dtor(&retval);

zend_fcall_info_args_clear(fci, 1);

zval_ptr_dtor(&params[0]);
zval_ptr_dtor(&params[1]);
zval_ptr_dtor(&retval);
return ret;
}

Expand All @@ -407,7 +406,7 @@ static PHP_METHOD(Memcached, __construct)
zend_fcall_info fci = {0};
zend_fcall_info_cache fci_cache;

if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|S!f!S", &persistent_id, &fci, &fci_cache, &conn_str) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!f!S", &persistent_id, &fci, &fci_cache, &conn_str) == FAILURE) {
return;
}

Expand Down Expand Up @@ -3295,6 +3294,7 @@ zend_bool s_unserialize_value (enum memcached_serializer serializer, int val_typ

PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (!php_var_unserialize(value, (const unsigned char **)&payload_tmp, (const unsigned char *)payload_tmp + payload_len, &var_hash)) {
zval_ptr_dtor(value);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other serializers should probably be consistent with this

ZVAL_FALSE(value);
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
php_error_docref(NULL, E_WARNING, "could not unserialize value");
Expand Down Expand Up @@ -3529,6 +3529,7 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i
fci->param_count = 4;

result = zend_call_function(fci, fcc);

ZVAL_DUP(value, Z_REFVAL(z_val));
expiration = Z_REFVAL(z_expiration);
if (result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
Expand Down Expand Up @@ -3573,6 +3574,7 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i
zval_ptr_dtor(&z_key);
zval_ptr_dtor(&z_val);
zval_ptr_dtor(&z_expiration);
zval_ptr_dtor(zmemc_obj);

return status;
}
Expand All @@ -3594,9 +3596,7 @@ static int php_memc_do_result_callback(zval *zmemc_obj, zend_fcall_info *fci,
int rc = 0;
php_memc_t *i_obj = NULL;

ZVAL_COPY(&params[0], zmemc_obj);
fci->retval = &retval;
fci->params = params;
fci->param_count = 2;

payload = memcached_result_value(result);
Expand All @@ -3615,7 +3615,6 @@ static int php_memc_do_result_callback(zval *zmemc_obj, zend_fcall_info *fci,
}

array_init(&z_result);
ZVAL_COPY(&params[1], &z_result);
add_assoc_stringl_ex(&z_result, ZEND_STRL("key"), (char *)res_key, res_key_len);
add_assoc_zval_ex(&z_result, ZEND_STRL("value"), &value);
if (cas != 0) {
Expand All @@ -3625,16 +3624,19 @@ static int php_memc_do_result_callback(zval *zmemc_obj, zend_fcall_info *fci,
add_assoc_long_ex(&z_result, ZEND_STRL("flags"), MEMC_VAL_GET_USER_FLAGS(flags));
}

ZVAL_UNDEF(&retval);
zend_fcall_info_argn(fci, 2, zmemc_obj, &z_result);

if (zend_call_function(fci, fcc) == FAILURE) {
php_error_docref(NULL, E_WARNING, "could not invoke result callback");
rc = -1;
}

if (&retval) {
if (Z_TYPE(retval) != IS_UNDEF) {
zval_ptr_dtor(&retval);
}
zval_ptr_dtor(&params[0]);
zval_ptr_dtor(&params[1]);

zend_fcall_info_args_clear(fci, 1);
zval_ptr_dtor(&z_result);

return rc;
Expand Down
13 changes: 8 additions & 5 deletions tests/bad_construct.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Memcached construct with bad arguments
<?php if (!extension_loaded("memcached")) print "skip"; ?>
--FILE--
<?php
error_reporting(0);

$m = new Memcached((object)array());
echo $php_errormsg, "\n";
var_dump($m);
Expand All @@ -21,9 +21,12 @@ var_dump ($extended->setOption (Memcached::OPT_BINARY_PROTOCOL, true));
echo "OK" . PHP_EOL;

--EXPECTF--
Memcached::__construct() expects parameter %s
NULL
Warning: Memcached::__construct() expects parameter 1 to be string, object given in %s on line 3
Memcached::__construct() expects parameter 1 to be string, object given
object(Memcached)#1 (0) {
}

Warning: Memcached::setOption(): Memcached constructor was not called in %s on line %d
Warning: Memcached::setOption(): Memcached constructor was not called in %s on line 14
NULL
OK
OK

5 changes: 4 additions & 1 deletion tests/clone.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ $m = clone $m;

echo "GOT HERE";
--EXPECTF--
Fatal error: Trying to clone an uncloneable object of class Memcached in %s on line %d
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class Memcached in %s:6
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just because errors as exceptions now ... is same ...

Stack trace:
#0 {main}
thrown in %s on line 6
4 changes: 2 additions & 2 deletions tests/experimental/cas_invalid_key.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ error_reporting(0);
var_dump($m->cas(0, '', true, 10));
echo $m->getResultMessage(), "\n";

var_dump($m->cas(0, ' �� jas kjjhask d ', true, 10));
var_dump($m->cas(0, ' �� jas kjjhask d ', true, 10)); # no spaces allowed
echo $m->getResultMessage(), "\n";

--EXPECTF--
bool(false)
A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE
bool(false)
%rCLIENT ERROR|NOT FOUND%r
A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this appears to be right, strchr is ran on the key to check for spaces ...

4 changes: 2 additions & 2 deletions tests/experimental/delete_bykey.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var_dump($m->deleteByKey('keffe', ''));
echo $m->getResultMessage(), "\n";
var_dump($m->deleteByKey('', 'keffe'));
echo $m->getResultMessage(), "\n";
var_dump($m->deleteByKey('keffe', '���as�� �a�sd�f asdf'));
var_dump($m->deleteByKey('keffe', '���as�� �a�sd�f asdf')); # no spaces allowed
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it seems like I just changed these to pass, but it really looks like this is the expected result. strchr is ran on the keys everywhere to check for spaces ...

echo $m->getResultMessage(), "\n";
--EXPECTF--
string(3) "foo"
Expand All @@ -37,4 +37,4 @@ A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE
bool(false)
NOT FOUND
bool(false)
%rPROTOCOL ERROR|NOT FOUND|WRITE FAILURE|CLIENT ERROR%r
A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE
2 changes: 1 addition & 1 deletion tests/experimental/get.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE
string(4) "asdf"
SUCCESS
bool(false)
NOT FOUND
A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE
2 changes: 1 addition & 1 deletion tests/experimental/get_bykey_cas.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ string(4) "asdf"
float(%d)
SUCCESS
bool(false)
NULL
float(0)
NOT FOUND
bool(false)
NULL
Expand Down