Skip to content

Commit

Permalink
MDL-57570 static store: Basic serialize tests with igbinary
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stronk7 committed Jan 18, 2017
1 parent 22f1426 commit 121c17a
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion cache/stores/static/tests/static_test.php
Expand Up @@ -117,4 +117,39 @@ public function test_maxsize() {
'key4', 'key5', 'key6', 'key7', 'keyA', 'keyB', 'keyC'
)));
}
}

/**
* 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).
}
}

0 comments on commit 121c17a

Please sign in to comment.