public function testFix()
{
$expectedData = array('Normal', 'High-value Char: ' . chr(231) . 'a-va?');
$brokenSerialization = 'a:2:{i:0;s:6:"Normal";i:1;s:23:"High-value Char: ▒a-va?";}';
$expectedError = array('errno' => 8, 'errstr' => 'unserialize(): Error at offset 55 of 60 bytes');
$reportedError = array();
set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) use(&$reportedError) {
$reportedError = compact('errno', 'errstr');
});
unserialize($brokenSerialization);
is($expectedError['errno'], $reportedError['errno']);
// Because HHVM's unserialize() error message does not contain enough info to properly test.
if (!defined('HHVM_VERSION')) {
is($expectedError['errstr'], $reportedError['errstr']);
}
restore_error_handler();
$fixedSerialization = Ser::fix($brokenSerialization);
$unserializedData = unserialize($fixedSerialization);
is($expectedData[0], $unserializedData[0], 'Did not properly fix the broken serialized data.');
is(substr($expectedData[1], 0, 10), substr($unserializedData[1], 0, 10), 'Did not properly fix the broken serialized data.');
}