/home/lnzliplg/public_html/alt-php80-pecl-leveldb_0.3.0-1.el8.tar
tests/003-openbasedir.phpt 0000644 00000001236 15173034266 0011407 0 ustar 00 --TEST--
leveldb - open base dir
--INI--
open_basedir=.
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
$cwd = getcwd();
$path = $cwd . '/../leveldb_openbasedir.test-db';
$db = new LevelDB($path);
LevelDB::destroy($path);
LevelDB::repair($path);
?>
--EXPECTF--
Warning: LevelDB::__construct(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s) in %s on line %d
Warning: LevelDB::destroy(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s) in %s on line %d
Warning: LevelDB::repair(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s) in %s on line %d
tests/004-write-batch.phpt 0000644 00000001706 15173034266 0011330 0 ustar 00 --TEST--
leveldb - write batch
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb_batch.test-db';
$db = new LevelDB($leveldb_path);
echo "* batch write with setting\n";
$batch = new LevelDBWriteBatch();
$batch->set('batch_foo', 'batch_bar');
$batch->put('batch_foo2', 'batch_bar2');
$batch->delete('batch_foo');
var_dump($db->write($batch));
var_dump($db->get('batch_foo2'));
var_dump($db->get('batch_foo'));
echo "* batch write with delete\n";
$batch->clear();
$batch->delete('batch_foo2');
$batch->set('batch_foo', 'batch again');
var_dump($db->write($batch));
var_dump($db->get('batch_foo2'));
var_dump($db->get('batch_foo'));
?>
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb_batch.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECTF--
* batch write with setting
bool(true)
string(10) "batch_bar2"
bool(false)
* batch write with delete
bool(true)
bool(false)
string(11) "batch again"
tests/008-options.phpt 0000644 00000001651 15173034266 0010615 0 ustar 00 --TEST--
leveldb - options open options
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb_options.test-db';
try {
$db = new LevelDB($leveldb_path, array("create_if_missing" => false));
} catch(LevelDBException $e) {
echo $e->getMessage() . "\n";
}
try {
$db = new LevelDB($leveldb_path, array("max_open_files" => 10));
$db->set("key", "value");
var_dump($db->get("key"));
} catch(LevelDBException $e) {
echo $e->getMessage() . "\n";
}
unset($db);
try {
$db = new LevelDB($leveldb_path, array("error_if_exists" => true));
} catch(LevelDBException $e) {
echo $e->getMessage() . "\n";
}
?>
==DONE==
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb_options.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECTF--
Invalid argument: %s: does not exist (create_if_missing is false)
string(5) "value"
Invalid argument: %s: exists (error_if_exists is true)
==DONE==
tests/013-compactRange.phpt 0000644 00000000712 15173034267 0011517 0 ustar 00 --TEST--
leveldb - compactRange
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb-compactRange.test-db';
$db = new LevelDB($leveldb_path);
for($i=0; $i < 99999; ++$i) {
$db->set("b{$i}", "value{$i}");
}
var_dump($db->compactRange('a', 'Z'));
?>
==DONE==
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb-compactRange.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECTF--
NULL
==DONE==
tests/010-compression.phpt 0000644 00000001102 15173034267 0011444 0 ustar 00 --TEST--
leveldb - compression
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb-compression.test-db';
$db = new LevelDB($leveldb_path, array('compression' => 33));
unset($db);
$db = new LevelDB($leveldb_path, array('compression' => LEVELDB_SNAPPY_COMPRESSION));
$db->set("key", "value");
?>
==DONE==
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb-compression.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECTF--
Warning: LevelDB::__construct(): Unsupported compression type in %s on line %s
==DONE==
tests/006-iterator-foreach.phpt 0000644 00000002061 15173034267 0012353 0 ustar 00 --TEST--
leveldb - iterate through db by foreach
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb_iterator-foreach.test-db';
$db = new LevelDB($leveldb_path);
/* Add test data, and the data will be be sorted */
$data = array(
"First", "Second", "Third", 10, "", "Last"
);
foreach($data as $item) {
$db->set($item, $item);
}
$it = new LevelDBIterator($db);
echo "*** Loop through in foreach style ***\n";
foreach ($it as $key => $value) {
echo "{$key} => {$value}\n";
}
echo "*** Loop through in foreach with newly-created iterator ***\n";
foreach(new LevelDBIterator($db) as $key => $value){
echo "{$key} => {$value}\n";
}
?>
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb_iterator-foreach.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECTF--
*** Loop through in foreach style ***
=>
10 => 10
First => First
Last => Last
Second => Second
Third => Third
*** Loop through in foreach with newly-created iterator ***
=>
10 => 10
First => First
Last => Last
Second => Second
Third => Third
tests/018-snapshot.phpt 0000644 00000002600 15173034267 0010756 0 ustar 00 --TEST--
leveldb - snapshot
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb-snapshot.test-db';
@unlink($leveldb_path);
$db = new LevelDB($leveldb_path);
$db->put("key1", "value1");
$db->put("key2", "value2");
$snapshot = new LevelDBSnapshot($db);
$db->put("key3", "value3");
try {
$it = new LevelDBIterator($db, array('snapshot' => ''));
} catch(LevelDBException $e) {
var_dump($e->getMessage());
}
$it = $db->getIterator(array('snapshot' => $snapshot));
foreach($it as $k => $v) {
echo "$k => $v\n";
}
var_dump($db->get("key3", array('snapshot' => $snapshot)));
var_dump($db->get("key3"));
echo "*** Release snapshot x1 ***\n";
$snapshot->release();
echo "*** Release snapshot x2 ***\n";
$snapshot->release();
echo "*** Try to use released snapshot ***\n";
try {
$it = new LevelDBIterator($db, array('snapshot' => $snapshot));
} catch(LevelDBException $e) {
var_dump($e->getMessage());
}
?>
==DONE==
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb-snapshot.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECTF--
string(69) "Invalid snapshot parameter, it must be an instance of LevelDBSnapshot"
key1 => value1
key2 => value2
bool(false)
string(6) "value3"
*** Release snapshot x1 ***
*** Release snapshot x2 ***
*** Try to use released snapshot ***
string(48) "Invalid snapshot parameter, it has been released"
==DONE==
tests/009-comparator.phpt 0000644 00000003711 15173034267 0011272 0 ustar 00 --TEST--
leveldb - custom comparator
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb-comparator.test-db';
echo "*** could not use invalid custom comparator ***\n";
try {
$db = new LevelDB($leveldb_path, array('comparator' => 'invaid_func'));
} catch(LevelDBException $e) {
echo $e->getMessage() . "\n";
}
echo "*** valid custom comparator ***\n";
$db = new LevelDB($leveldb_path, array('comparator' => 'custom_comparator'));
$values = array(3, 1, 4, 6, 2, 5);
foreach($values as $v) {
$db->set($v, $v);
}
$it = new LevelDBIterator($db);
foreach($it as $v) {
echo "$v\n";
}
unset($it);
unset($db);
echo "*** custom comparator can only open with the same comparator again ***\n";
try {
$db = new LevelDB($leveldb_path);
} catch(LevelDBException $e) {
echo $e->getMessage() . "\n";
}
$db = new LevelDB($leveldb_path, array('comparator' => 'custom_comparator'));
var_dump($db->get(1) == 1);
unset($db);
echo "*** custom comparator which throw exception ***\n";
$db = new LevelDB($leveldb_path, array('comparator' => array('CustomFunc', 'willException')));
try {
$db->set("Hi", "guys");
var_dump($db->get("Hi"));
} catch(Exception $e) {
echo $e->getMessage() . "\n";
}
// reverse DESC
function custom_comparator($a, $b) {
if ($a == $b) {
return 0;
}
return ($a > $b) ? -1 : 1;
}
class CustomFunc {
public static function willException($a, $b) {
throw new Exception("Oops!");
}
}
?>
==DONE==
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb-comparator.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECTF--
*** could not use invalid custom comparator ***
Invalid open option: comparator, invaid_func() is not callable
*** valid custom comparator ***
6
5
4
3
2
1
*** custom comparator can only open with the same comparator again ***
Invalid argument: php_leveldb.custom_comparator%s leveldb.BytewiseComparator
bool(true)
*** custom comparator which throw exception ***
Oops!
==DONE==
tests/012-getProperty.phpt 0000644 00000001763 15173034267 0011446 0 ustar 00 --TEST--
leveldb - getProperty
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb-getProperty.test-db';
$db = new LevelDB($leveldb_path);
for($i=0; $i < 99999; ++$i) {
$db->set("b{$i}", "value{$i}");
}
$stats = $db->getProperty('leveldb.stats');
var_dump($stats !== false);
var_dump(strlen($stats) > 1);
var_dump($db->getProperty('leveldb.num-files-at-level1'));
var_dump($db->getProperty('leveldb.num-files-at-level2'));
var_dump($db->getProperty('leveldb.num-files-at-level3'));
$sstables = $db->getProperty('leveldb.sstables');
var_dump($sstables !== false);
var_dump(strlen($sstables) > 1);
var_dump($db->getProperty('leveldb.anything'));
var_dump($db->getProperty('anythingelse'));
?>
==DONE==
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb-getProperty.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECTF--
bool(true)
bool(true)
string(1) "%d"
string(1) "%d"
string(1) "%d"
bool(true)
bool(true)
bool(false)
bool(false)
==DONE==
tests/011-getApproximateSizes.phpt 0000644 00000001533 15173034267 0013123 0 ustar 00 --TEST--
leveldb - getApproximateSizes
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb-getApproximateSizes.test-db';
$db = new LevelDB($leveldb_path);
for($i=0; $i < 99999; ++$i) {
$db->set("b{$i}", "value");
}
unset($db);
$db = new LevelDB($leveldb_path);
var_dump($db->getApproximateSizes(array("A", "B", 3), array("b0", "Z")));
var_dump($db->getApproximateSizes(array(), array()));
var_dump($db->getApproximateSizes(array("a", "b"), array("c", "Z")));
?>
==DONE==
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb-getApproximateSizes.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECTF--
Warning: LevelDB::getApproximateSizes(): The num of start keys and limit keys didn't match in %s on line %d
bool(false)
array(0) {
}
array(2) {
[0]=>
int(%d)
[1]=>
int(%d)
}
==DONE==
tests/005-iterator.phpt 0000644 00000003365 15173034267 0010755 0 ustar 00 --TEST--
leveldb - iterate through db
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb_iterator.test-db';
$db = new LevelDB($leveldb_path);
/* Add test data, and the data will be be sorted */
$data = array(
"First", "Second", "Third", 10, "", "Last"
);
foreach($data as $item) {
$db->set($item, $item);
}
$it = new LevelDBIterator($db);
echo "*** Loop through ***\n";
for ($it->rewind(); $it->valid(); $it->next()) {
echo $it->key() . " => " . $it->current() . "\n";
}
echo "\n*** Reset to last ***\n";
var_dump($it->last());
var_dump($it->key() . " => " . $it->current());
echo "\n*** Last->next will be invalid ***\n";
var_dump($it->next());
var_dump($it->valid());
var_dump($it->key());
echo "\n*** Seek to give key ***\n";
$it->seek("Second");
var_dump($it->current());
echo "\n*** Seek to a non-exist key will point to nearest next key ***\n";
$it->seek("11");
var_dump($it->current());
echo "\n*** Bound checking ***\n";
$it->rewind();
$it->prev();
$it->prev();
var_dump($it->current());
$it->next();
$it->next();
$it->next();
$it->next();
$it->next();
$it->next();
$it->next();
$it->next();
$it->next();
$it->next();
var_dump($it->current());
var_dump($it->getError());
?>
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb_iterator.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECTF--
*** Loop through ***
=>
10 => 10
First => First
Last => Last
Second => Second
Third => Third
*** Reset to last ***
NULL
string(14) "Third => Third"
*** Last->next will be invalid ***
NULL
bool(false)
bool(false)
*** Seek to give key ***
string(6) "Second"
*** Seek to a non-exist key will point to nearest next key ***
string(5) "First"
*** Bound checking ***
bool(false)
bool(false)
bool(false)
tests/skipif.inc 0000644 00000000132 15173034267 0007672 0 ustar 00 <?php
if (!extension_loaded('leveldb')) die("skip leveldb extension not available\n");
?>