Permalink
Browse files

Fixed a bug with config options and test for it

  • Loading branch information...
1 parent 6def3bb commit d9d5ce86f6f3848a5b113fa0b21cdde3c8fae8d2 @mkoppanen mkoppanen committed Nov 23, 2013
Showing with 7 additions and 8 deletions.
  1. +1 −1 php_memcached.c
  2. +6 −7 tests/setoptions.phpt
View
2 php_memcached.c
@@ -2540,7 +2540,7 @@ static int php_memc_set_option(php_memc_t *i_obj, long option, zval *value TSRML
flag = (memcached_behavior) option;
convert_to_long(value);
- if (Z_LVAL_P(value) >= 0 && Z_LVAL_P(value) < MEMCACHED_BEHAVIOR_MAX) {
+ if (flag >= 0 && flag < MEMCACHED_BEHAVIOR_MAX) {
rc = memcached_behavior_set(m_obj->memc, flag, (uint64_t) Z_LVAL_P(value));
}
else {
View
13 tests/setoptions.phpt
@@ -3,7 +3,7 @@ Set options using setOptions
--SKIPIF--
<?php if (!extension_loaded("memcached")) print "skip"; ?>
--FILE--
-<?php
+<?php
$m = new Memcached();
/* existing options */
@@ -12,6 +12,7 @@ var_dump($m->setOptions(array(
Memcached::OPT_SERIALIZER => Memcached::SERIALIZER_PHP,
Memcached::OPT_COMPRESSION => 0,
Memcached::OPT_LIBKETAMA_COMPATIBLE => 1,
+ Memcached::OPT_CONNECT_TIMEOUT => 5000,
)));
var_dump($m->getOption(Memcached::OPT_PREFIX_KEY) == 'a_prefix');
@@ -20,18 +21,14 @@ var_dump($m->getOption(Memcached::OPT_COMPRESSION) == 0);
var_dump($m->getOption(Memcached::OPT_LIBKETAMA_COMPATIBLE) == 1);
echo "test invalid options\n";
-error_reporting(0);
var_dump($m->setOptions(array(
"asdf" => 123
)));
-echo $php_errormsg, "\n";
-$php_errormsg = '';
var_dump($m->setOptions(array(
-1 => 123
)));
-echo $php_errormsg, "\n";
--EXPECTF--
bool(true)
@@ -40,7 +37,9 @@ bool(true)
bool(true)
bool(true)
test invalid options
+
+Warning: Memcached::setOptions(): invalid configuration option in %s on line %d
bool(false)
-%s::setOptions(): invalid configuration option
+
+Warning: Memcached::setOptions(): error setting memcached option: %s in %s on line %d
bool(false)
-%s::setOptions(): error setting memcached option: %s

0 comments on commit d9d5ce8

Please sign in to comment.