1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
<?php
class testclass {
}
function memc_types_test ($m, $options)
{
$data = array(
array('boolean_true', true),
array('boolean_false', false),
array('string', "just a string"),
array('string_empty', ""),
array('integer_positive_integer', 10),
array('integer_negative_integer', -10),
array('integer_zero_integer', 0),
array('float_positive1', 3.912131),
array('float_positive2', 1.2131E+501),
array('float_positive2', 1.2131E+52),
array('float_negative', -42.123312),
array('float_zero', 0.0),
array('null', null),
array('array_empty', array()),
array('array', array(1,2,3,"foo")),
array('object_array_empty', (object)array()),
array('object_array', (object)array("a" => "1","b" => "2","c" => "3")),
array('object_dummy', new testclass()),
);
foreach ($data as $key => $value) {
$m->delete($key);
}
foreach ($data as $types) {
$key = $types [0];
$value = $types [1];
$m->set($key, $value);
$actual = $m->get($key);
if ($value !== $actual) {
if (is_object($actual)) {
if ($options['ignore_object_type']) {
$value = (object) (array) $value;
if ($value == $actual)
continue;
}
if ($value == $actual && get_class($value) == get_class($actual))
continue;
}
echo "=== $types[0] ===\n";
echo "Expected: ";
var_dump($types[1]);
echo "Actual: ";
var_dump($actual);
}
}
$m->flush();
if (($actual = $m->get(uniqid ('random_key_'))) !== false) {
echo "Expected: null";
echo "Actual: " . gettype($actual);
}
}
function memc_types_test_multi ($m, $options)
{
$data = array(
'boolean_true' => true,
'boolean_false' => false,
'string' => "just a string",
'string_empty' => "",
'string_large' => str_repeat ('abcdef0123456789', 500),
'integer_positive_integer' => 10,
'integer_negative_integer' => -10,
'integer_zero_integer' => 0,
'float_positive1' => 3.912131,
'float_positive2' => 1.2131E+52,
'float_negative' => -42.123312,
'float_zero' => 0.0,
'null' => null,
'array_empty' => array(),
'array' => array(1,2,3,"foo"),
'object_array_empty' => (object)array(),
'object_array' => (object)array('a' => 1, 'b' => 2, 'c' => 3),
'object_dummy' => new testclass(),
);
foreach ($data as $key => $value) {
$m->delete($key);
}
$m->setMulti($data);
$actual = $m->getMulti(array_keys($data));
foreach ($data as $key => $value) {
if ($value !== $actual[$key]) {
if (is_object($value)) {
if ($options['ignore_object_type']) {
$value = (object) (array) $value;
if ($value == $actual[$key])
continue;
}
if ($value == $actual[$key] && get_class($value) == get_class($actual[$key]))
continue;
}
echo "=== $key ===\n";
echo "Expected: ";
var_dump($value);
echo "Actual: ";
var_dump($actual[$key]);
}
}
}
|