49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace NoccyLabs\LiteDb;
|
||
|
|
||
|
class LiteDbText extends \PhpUnit\Framework\TestCase
|
||
|
{
|
||
|
|
||
|
public function testCreatingNewDatabase()
|
||
|
{
|
||
|
if (file_exists("/tmp/litedbtest.db"))
|
||
|
unlink("/tmp/litedbtest.db");
|
||
|
$db = new LiteDb("/tmp/litedbtest.db", 1, function ($db, $v) {
|
||
|
$db->createStore("test");
|
||
|
});
|
||
|
$this->assertTrue($db->hasStore("test"));
|
||
|
$this->assertFalse($db->hasStore("test2"));
|
||
|
$this->assertEquals(1, $db->getVersion());
|
||
|
}
|
||
|
|
||
|
public function testUpgradingDatabase()
|
||
|
{
|
||
|
$db = new LiteDb("/tmp/litedbtest.db", 2, function ($db, $v) {
|
||
|
$db->createStore("test2");
|
||
|
});
|
||
|
$this->assertTrue($db->hasStore("test"));
|
||
|
$this->assertTrue($db->hasStore("test2"));
|
||
|
$this->assertEquals(2, $db->getVersion());
|
||
|
}
|
||
|
|
||
|
public function testUsingIndexes()
|
||
|
{
|
||
|
$db = new LiteDb("/tmp/litedbtest.db", 3, function ($db, $v) {
|
||
|
$db->createStore("test3")
|
||
|
->addIndex("foo", [ 'unique'=>true, 'primary'=>true ]);
|
||
|
});
|
||
|
$this->assertTrue($db->hasStore("test3"));
|
||
|
$this->assertEquals(3, $db->getVersion());
|
||
|
|
||
|
$store = $db->getStore("test3");
|
||
|
$this->assertInstanceOf(ObjectStore::class, $store);
|
||
|
|
||
|
$store->add([ 'foo'=>42, 'bar'=>314 ]);
|
||
|
|
||
|
$record = $store->get(42);
|
||
|
|
||
|
$this->assertEquals(['foo'=>42, 'bar'=>314], $record);
|
||
|
}
|
||
|
|
||
|
}
|