Skip to content

Commit 55c8cc6

Browse files
author
Mikko Koppanen
committed
Merge pull request php-memcached-dev#109 from mkoppanen/master
Separate tests for serializers
2 parents 8de8b8b + 6d2fc84 commit 55c8cc6

12 files changed

+215
-87
lines changed

package.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,15 @@ http://pear.php.net/dtd/package-2.0.xsd">
118118
<file role='test' name='set_large.phpt'/>
119119
<file role='test' name='setoptions.phpt'/>
120120
<file role='test' name='touch_binary.phpt'/>
121-
<file role='test' name='types.phpt'/>
122-
<file role='test' name='types_multi.phpt'/>
121+
<file role='test' name='types.inc'/>
122+
<file role='test' name='types_igbinary.phpt'/>
123+
<file role='test' name='types_igbinary_multi.phpt'/>
124+
<file role='test' name='types_json.phpt'/>
125+
<file role='test' name='types_json_multi.phpt'/>
126+
<file role='test' name='types_msgpack.phpt'/>
127+
<file role='test' name='types_msgpack_multi.phpt'/>
128+
<file role='test' name='types_php.phpt'/>
129+
<file role='test' name='types_php_multi.phpt'/>
123130
<file role='test' name='undefined_set.phpt'/>
124131
<file role='test' name='vbucket.phpt'/>
125132
<file role='test' name='user-flags.phpt'/>

tests/types.phpt renamed to tests/types.inc

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
--TEST--
2-
Memcached store & fetch type and value correctness
3-
--SKIPIF--
4-
<?php if (!extension_loaded("memcached")) print "skip"; ?>
5-
--FILE--
61
<?php
7-
include dirname (__FILE__) . '/config.inc';
8-
92
class testclass {
103
}
114

12-
function types_simple_test ($m, $options)
5+
function memc_types_test ($m, $options)
136
{
147

158
$data = array(
@@ -77,8 +70,59 @@ function types_simple_test ($m, $options)
7770
}
7871
}
7972

80-
memc_run_test ('types_simple_test', memc_get_serializer_options (version_compare(phpversion("msgpack"), "0.5.5", "<=")));
73+
function memc_types_test_multi ($m, $options)
74+
{
75+
$data = array(
76+
'boolean_true' => true,
77+
'boolean_false' => false,
78+
79+
'string' => "just a string",
80+
'string_empty' => "",
81+
'string_large' => str_repeat ('abcdef0123456789', 500),
82+
83+
'integer_positive_integer' => 10,
84+
'integer_negative_integer' => -10,
85+
'integer_zero_integer' => 0,
86+
87+
'float_positive1' => 3.912131,
88+
'float_positive2' => 1.2131E+52,
89+
'float_negative' => -42.123312,
90+
'float_zero' => 0.0,
91+
92+
'null' => null,
93+
94+
'array_empty' => array(),
95+
'array' => array(1,2,3,"foo"),
96+
97+
'object_array_empty' => (object)array(),
98+
'object_array' => (object)array('a' => 1, 'b' => 2, 'c' => 3),
99+
'object_dummy' => new testclass(),
100+
);
101+
102+
foreach ($data as $key => $value) {
103+
$m->delete($key);
104+
}
105+
$m->setMulti($data);
106+
$actual = $m->getMulti(array_keys($data));
107+
108+
foreach ($data as $key => $value) {
109+
if ($value !== $actual[$key]) {
110+
if (is_object($value)) {
111+
if ($options['ignore_object_type']) {
112+
$value = (object) (array) $value;
113+
if ($value == $actual[$key])
114+
continue;
115+
}
116+
117+
if ($value == $actual[$key] && get_class($value) == get_class($actual[$key]))
118+
continue;
119+
}
81120

82-
?>
83-
--EXPECT--
84-
TEST DONE
121+
echo "=== $key ===\n";
122+
echo "Expected: ";
123+
var_dump($value);
124+
echo "Actual: ";
125+
var_dump($actual[$key]);
126+
}
127+
}
128+
}

tests/types_igbinary.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 and value correctness using igbinary serializer
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("memcached")) print "skip";
6+
if (!Memcached::HAVE_IGBINARY) print "skip igbinary not enabled";
7+
?>
8+
--FILE--
9+
<?php
10+
include dirname (__FILE__) . '/config.inc';
11+
include dirname (__FILE__) . '/types.inc';
12+
13+
memc_run_test ('memc_types_test',
14+
memc_create_combinations ('igbinary', Memcached::SERIALIZER_IGBINARY)
15+
);
16+
17+
?>
18+
--EXPECT--
19+
TEST DONE

tests/types_igbinary_multi.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Memcached multi store & multi fetch type and value correctness using igbinary serializer
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("memcached")) print "skip";
6+
if (!Memcached::HAVE_IGBINARY) print "skip igbinary not enabled";
7+
?>
8+
--FILE--
9+
<?php
10+
include dirname (__FILE__) . '/config.inc';
11+
include dirname (__FILE__) . '/types.inc';
12+
13+
memc_run_test ('memc_types_test_multi',
14+
memc_create_combinations ('igbinary', Memcached::SERIALIZER_IGBINARY)
15+
);
16+
17+
?>
18+
--EXPECT--
19+
TEST DONE

tests/types_json.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 and value correctness using JSON serializer
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("memcached")) print "skip";
6+
if (!Memcached::HAVE_JSON) print "skip json not enabled";
7+
?>
8+
--FILE--
9+
<?php
10+
include dirname (__FILE__) . '/config.inc';
11+
include dirname (__FILE__) . '/types.inc';
12+
13+
memc_run_test ('memc_types_test',
14+
memc_create_combinations ('JSON', Memcached::SERIALIZER_JSON, true)
15+
);
16+
17+
?>
18+
--EXPECT--
19+
TEST DONE

tests/types_json_multi.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Memcached multi store & multi fetch type and value correctness using JSON serializer
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("memcached")) print "skip";
6+
if (!Memcached::HAVE_IGBINARY) print "skip json not enabled";
7+
?>
8+
--FILE--
9+
<?php
10+
include dirname (__FILE__) . '/config.inc';
11+
include dirname (__FILE__) . '/types.inc';
12+
13+
memc_run_test ('memc_types_test_multi',
14+
memc_create_combinations ('JSON', Memcached::SERIALIZER_JSON, true)
15+
);
16+
17+
?>
18+
--EXPECT--
19+
TEST DONE

tests/types_msgpack.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 and value correctness using msgpack serializer
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("memcached")) print "skip";
6+
if (!Memcached::HAVE_MSGPACK) print "skip msgpack not enabled";
7+
?>
8+
--FILE--
9+
<?php
10+
include dirname (__FILE__) . '/config.inc';
11+
include dirname (__FILE__) . '/types.inc';
12+
13+
memc_run_test ('memc_types_test',
14+
memc_create_combinations ('msgpack', Memcached::SERIALIZER_MSGPACK, version_compare(phpversion("msgpack"), "0.5.5", "<="))
15+
);
16+
17+
?>
18+
--EXPECT--
19+
TEST DONE

tests/types_msgpack_multi.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Memcached multi store & fetch type and value correctness using msgpack serializer
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("memcached")) print "skip";
6+
if (!Memcached::HAVE_MSGPACK) print "skip msgpack not enabled";
7+
?>
8+
--FILE--
9+
<?php
10+
include dirname (__FILE__) . '/config.inc';
11+
include dirname (__FILE__) . '/types.inc';
12+
13+
memc_run_test ('memc_types_test_multi',
14+
memc_create_combinations ('msgpack', Memcached::SERIALIZER_MSGPACK, version_compare(phpversion("msgpack"), "0.5.5", "<="))
15+
);
16+
17+
?>
18+
--EXPECT--
19+
TEST DONE

tests/types_multi.phpt

Lines changed: 0 additions & 73 deletions
This file was deleted.

tests/types_php.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Memcached store & fetch type and value correctness using PHP serializer
3+
--SKIPIF--
4+
<?php if (!extension_loaded("memcached")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
include dirname (__FILE__) . '/config.inc';
8+
include dirname (__FILE__) . '/types.inc';
9+
10+
memc_run_test ('memc_types_test',
11+
memc_create_combinations ('PHP', Memcached::SERIALIZER_PHP)
12+
);
13+
14+
?>
15+
--EXPECT--
16+
TEST DONE

0 commit comments

Comments
 (0)