Commit 121c17a7 authored by Eloy Lafuente's avatar Eloy Lafuente
Browse files

MDL-57570 static store: Basic serialize tests with igbinary

This unit test is not really verifying that internally igbinary
in being used but just igbinary availability and, by double
serializing, that it works for a semi-complex object.

The test will be skipped if igbinary is not available.
parent 22f1426b
......@@ -117,4 +117,39 @@ class cachestore_static_test extends cachestore_tests {
'key4', 'key5', 'key6', 'key7', 'keyA', 'keyB', 'keyC'
)));
}
}
\ No newline at end of file
/**
* Simple test to verify igbinary availability and check basic serialization is working ok.
*/
public function test_igbinary_serializer() {
// Skip if igbinary is not available.
if (!extension_loaded('igbinary')) {
$this->markTestSkipped('Cannot test igbinary serializer. Extension missing');
}
// Prepare the static instance.
$defid = 'phpunit/igbinary';
$config = cache_config_testing::instance();
$config->phpunit_add_definition($defid, array(
'mode' => cache_store::MODE_REQUEST,
'component' => 'phpunit',
'area' => 'testigbinary'
));
$definition = cache_definition::load($defid, $config->get_definition_by_id($defid));
$instance = cachestore_static::initialise_test_instance($definition);
// Prepare an object.
$obj = new stdClass();
$obj->someint = 9;
$obj->somestring = '99';
$obj->somearray = [9 => 999, '99' => '9999'];
// Serialize and set.
$objser = igbinary_serialize($obj);
$instance->set('testigbinary', $objser);
// Get and unserialize.
$res = $instance->get('testigbinary');
$resunser = igbinary_unserialize($res);
// Check expectations.
$this->assertSame($objser, $res); // Ok from cache (ig-serialized, 100% same string).
$this->assertEquals($obj, $resunser); // Ok ig-unserialized (equal
$this->assertNotSame($obj, $resunser);// but different objects, obviously).
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment