Skip to content

Commit e9ec2b0

Browse files
Teddy grenmanAndrei Zmievski
authored andcommitted
New tests
Signed-off-by: Andrei Zmievski <[email protected]>
1 parent 19001d0 commit e9ec2b0

File tree

4 files changed

+172
-0
lines changed

4 files changed

+172
-0
lines changed

tests/deleted.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Memcached store & fetch type correctness
3+
--SKIPIF--
4+
<?php if (!extension_loaded("memcached")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$m = new Memcached();
8+
$m->addServer('127.0.0.1', 11211, 1);
9+
10+
$m->set('eisaleeoo', "foo");
11+
$m->delete('eisaleeoo');
12+
$v = $m->get('eisaleeoo');
13+
14+
if (!is_null($v)) {
15+
echo "Vanted a null value from get. Got:\n";
16+
var_dump($v);
17+
}
18+
?>
19+
--EXPECT--

tests/expire.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Memcached store & fetch expired key
3+
--SKIPIF--
4+
<?php if (!extension_loaded("memcached")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$m = new Memcached();
8+
$m->addServer('127.0.0.1', 11211, 1);
9+
10+
$set = $m->set('will_expire', "foo", 2);
11+
$v = $m->get('will_expire');
12+
if (!$set || $v != 'foo') {
13+
echo "Error setting will_expire to \"foo\" with 2s expiry.\n";
14+
}
15+
sleep(3);
16+
$v = $m->get('will_expire');
17+
18+
if (!is_null($v)) {
19+
echo "Wanted a null value from get of expired value. Got:\n";
20+
var_dump($v);
21+
}
22+
?>
23+
--EXPECT--

tests/types.phpt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
--TEST--
2+
Memcached store & fetch type and value correctness
3+
--SKIPIF--
4+
<?php if (!extension_loaded("memcached")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$m = new Memcached();
8+
$m->addServer('127.0.0.1', 11211, 1);
9+
10+
class testclass {
11+
}
12+
13+
$data = array(
14+
array('boolean_true', true),
15+
array('boolean_false', false),
16+
17+
array('string', "just a string"),
18+
array('string_empty', ""),
19+
20+
array('integer_positive_integer', 10),
21+
array('integer_negative_integer', -10),
22+
array('integer_zero_integer', 0),
23+
24+
array('float_positive1', 3.912131),
25+
array('float_positive2', 1.2131E+52),
26+
array('float_negative', -42.123312),
27+
array('float_zero', 0.0),
28+
29+
array('null', null),
30+
31+
array('array_empty', array()),
32+
array('array', array(1,2,3,"foo")),
33+
34+
array('object_array_empty', (object)array()),
35+
array('object_array', (object)array(1,2,3)),
36+
array('object_dummy', new testclass()),
37+
);
38+
39+
foreach ($data as $types) {
40+
$m->set($types[0], $types[1]);
41+
$actual = $m->get($types[0]);
42+
$cas = null;
43+
$actual_cas = $m->get($types[0], $cas);
44+
if ($types[1] !== $actual || $types[1] !== $actual_cas) {
45+
if (isset($cas) && is_object($types[1])
46+
&& $types[1] == $actual
47+
&& $types[1] == $actual_cas
48+
&& get_class($types[1]) == get_class($actual)
49+
&& get_class($types[1]) == get_class($actual_cas)) {
50+
continue;
51+
}
52+
echo "=== $types[0] ===\n";
53+
echo "Expected: ";
54+
var_dump($types[1]);
55+
echo "Actual: ";
56+
var_dump($actual);
57+
echo "Actual CAS: ";
58+
var_dump($actual_cas);
59+
echo "Cas: ", $cas, "\n";
60+
}
61+
62+
}
63+
64+
?>
65+
--EXPECT--

tests/types_multi.phpt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
--TEST--
2+
Memcached multi store & multi fetch type and value correctness
3+
--SKIPIF--
4+
<?php if (!extension_loaded("memcached")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$m = new Memcached();
8+
$m->addServer('127.0.0.1', 11211, 1);
9+
10+
class testclass {
11+
}
12+
13+
$data = array(
14+
'boolean_true' => true,
15+
'boolean_false' => false,
16+
17+
'string' => "just a string",
18+
'string_empty' => "",
19+
20+
'integer_positive_integer' => 10,
21+
'integer_negative_integer' => -10,
22+
'integer_zero_integer' => 0,
23+
24+
'float_positive1' => 3.912131,
25+
'float_positive2' => 1.2131E+52,
26+
'float_negative' => -42.123312,
27+
'float_zero' => 0.0,
28+
29+
'null' => null,
30+
31+
'array_empty' => array(),
32+
'array' => array(1,2,3,"foo"),
33+
34+
'object_array_empty' => (object)array(),
35+
'object_array' => (object)array(1,2,3),
36+
'object_dummy' => new testclass(),
37+
);
38+
39+
$m->setMulti($data);
40+
$actual = $m->getMulti(array_keys($data));
41+
$cas = array();
42+
$actual_cas = $m->getMulti(array_keys($data), $cas);
43+
44+
foreach ($data as $key => $value) {
45+
if ($value !== $actual[$key] || $value !== $actual_cas[$key] || !isset($cas[$key])) {
46+
if (isset($cas[$key]) && is_object($value)
47+
&& $value == $actual[$key]
48+
&& $value == $actual_cas[$key]
49+
&& get_class($value) == get_class($actual[$key])
50+
&& get_class($value) == get_class($actual_cas[$key])) {
51+
continue;
52+
}
53+
echo "=== $key ===\n";
54+
echo "Expected: ";
55+
var_dump($value);
56+
echo "Actual: ";
57+
var_dump($actual[$key]);
58+
echo "Actual CAS: ";
59+
var_dump($actual_cas[$key]);
60+
echo "Cas: ", $cas[$key], "\n";
61+
}
62+
}
63+
64+
?>
65+
--EXPECT--

0 commit comments

Comments
 (0)