Current File : /home/mmdealscpanel/yummmdeals.com/alt-php83-pecl-leveldb_0.3.0-1.el8.tar
tests/010-compression.phpt000064400000001102150413221030011423 0ustar00--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/019-null-comparator.phpt000064400000001043150413221030012216 0ustar00--TEST--
leveldb - NULL comparator should not throw exception
--DESCRIPTION--
NULL is the default value of comparator open options
open with null shouldn't throw exception
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php

$leveldb_path = dirname(__FILE__) . '/null-comparator.test-db';

$db = new LevelDB($leveldb_path, array('comparator' => NULL));

?>
Should no exception
==DONE==
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/null-comparator.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECT--
Should no exception
==DONE==
tests/018-snapshot.phpt000064400000002600150413221030010735 0ustar00--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/011-getApproximateSizes.phpt000064400000001533150413221030013102 0ustar00--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/008-options.phpt000064400000001651150413221030010575 0ustar00--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/003-openbasedir.phpt000064400000001236150413221040011370 0ustar00--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/014-iterator-destroy.phpt000064400000001043150413221040012413 0ustar00--TEST--
leveldb - iterator destroy
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php

$leveldb_path = dirname(__FILE__) . '/leveldb_iterator_destroy.test-db';
$db = new LevelDB($leveldb_path);

$db->set("key", "value");
$it = new LevelDBIterator($db);

$it->destroy();
try {
	$it->next();
} catch(LevelDBException $e) {
	echo $e->getMessage() . "\n";
}
?>
==DONE==
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb_iterator_destroy.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECTF--
Iterator has been destroyed
==DONE==
tests/015-double-iterator.phpt000064400000001000150413221040012166 0ustar00--TEST--
leveldb - Fixed bug segfault when double construct iterator
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php

$leveldb_path = dirname(__FILE__) . '/leveldb_iterator_double_construct.test-db';
$db = new LevelDB($leveldb_path);

$it1 = new LevelDBIterator($db);
$it2 = new LevelDBIterator($db);

$it1->destroy();
$it2->destroy();
?>
==DONE==
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb_iterator_double_construct.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECTF--
==DONE==
tests/012-getProperty.phpt000064400000001763150413221040011426 0ustar00--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/009-comparator.phpt000064400000003711150413221040011252 0ustar00--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/skipif.inc000064400000000132150413221040007652 0ustar00<?php
	if (!extension_loaded('leveldb')) die("skip leveldb extension not available\n");
?>tests/007-db-close.phpt000064400000001067150413221040010573 0ustar00--TEST--
leveldb - db close
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php

$leveldb_path = dirname(__FILE__) . '/leveldb_close.test-db';
$db = new LevelDB($leveldb_path);

$db->close();


unset($it);
unset($db);

// ensure destructeur properly close the db */
LevelDB::destroy($leveldb_path);
var_dump(file_exists($leveldb_path));
?>
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb_close.test-db';
if (file_exists($leveldb_path)) LevelDB::destroy($leveldb_path);
?>
--EXPECTF--
Deprecated: %s LevelDB::close() is deprecated in %s
bool(false)
tests/016-different-iterators-should-differ.phpt000064400000001472150413221040015614 0ustar00--TEST--
leveldb - different iterators should not affect each other
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php

$leveldb_path = dirname(__FILE__) . '/leveldb_iterator_should_not_affect_eachother.test-db';
$db = new LevelDB($leveldb_path);

foreach(array(1, 2, 3, 4) as $k) {
	$db->put($k, $k);
}

$it1 = new LevelDBIterator($db);
$it2 = new LevelDBIterator($db);

foreach($it1 as $k => $v) {
	echo "$k => $v\n";
}

$it1->rewind();
var_dump($it1->next());
var_dump($it1->next());
var_dump($it1->current());
var_dump($it2->current());

$it1->destroy();
$it2->destroy();
?>
==DONE==
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb_iterator_should_not_affect_eachother.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECTF--
1 => 1
2 => 2
3 => 3
4 => 4
NULL
NULL
string(1) "3"
string(1) "1"
==DONE==
tests/013-compactRange.phpt000064400000000712150413221040011477 0ustar00--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/005-iterator.phpt000064400000003365150413221040010735 0ustar00--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/017-db-getIterator.phpt000064400000001210150413221050011747 0ustar00--TEST--
leveldb - LevelDB::getIterator()
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php

$leveldb_path = dirname(__FILE__) . '/leveldb_get_iterator.test-db';
$db = new LevelDB($leveldb_path);

foreach(range(1, 9) as $item) {
	$db->set($item, $item);
}

$it = $db->getIterator();

var_dump(get_class($it));

for ($it->rewind(); $it->valid(); $it->next()) {
	echo $it->key() . " => " . $it->current() . "\n";
}
?>
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/leveldb_get_iterator.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECTF--
string(15) "LevelDBIterator"
1 => 1
2 => 2
3 => 3
4 => 4
5 => 5
6 => 6
7 => 7
8 => 8
9 => 9
tests/leveldb.inc000064400000000230150413221050010002 0ustar00<?php

function leveldb_empty($db) {
	$it = new LevelDBIterator($db);

	for($it->rewind(); $it->valid(); $it->next()) {
		$db->delete($it->key());
	}
}
tests/002-db-management.phpt000064400000000471150413221050011574 0ustar00--TEST--
leveldb - db management
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php

$path = dirname(__FILE__) . '/leveldb-db-op.test-db';
$db = new LevelDB($path);
$db->set("key", "value");

unset($db);
var_dump(LevelDB::destroy($path));
var_dump(file_exists($path));
?>
--EXPECTF--
bool(true)
bool(false)
tests/006-iterator-foreach.phpt000064400000002061150413221050012334 0ustar00--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/004-write-batch.phpt000064400000001706150413221050011312 0ustar00--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/001-basic.phpt000064400000001176150413221050010160 0ustar00--TEST--
leveldb - basic: get(), set(), put(), delete()
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php

$leveldb_path = __DIR__ . '/leveldb-basic.test-db';
$db = new LevelDB($leveldb_path);

var_dump($db->set('key', 'value'));
var_dump($db->get('key'));
var_dump($db->get('non-exists-key'));
var_dump($db->put('name', 'reeze'));
var_dump($db->get('name'));
var_dump($db->delete('name'));
var_dump($db->get('name'));
?>
--CLEAN--
<?php
$leveldb_path = __DIR__ . '/leveldb-basic.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECTF--
bool(true)
string(5) "value"
bool(false)
bool(true)
string(5) "reeze"
bool(true)
bool(false)
tests/020-null-snapshot.phpt000064400000000725150413221050011706 0ustar00--TEST--
leveldb - NULL snapshot should not throw exception
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php

$leveldb_path = dirname(__FILE__) . '/null-snapshot.test-db';

$db = new LevelDB($leveldb_path);

var_dump($db->get("key", array('snapshot' => NULL)));

?>
Should no exception
==DONE==
--CLEAN--
<?php
$leveldb_path = dirname(__FILE__) . '/null-snapshot.test-db';
LevelDB::destroy($leveldb_path);
?>
--EXPECT--
bool(false)
Should no exception
==DONE==