From 95ee51563d5dc1110f79dd870806f6745a573e2d Mon Sep 17 00:00:00 2001 From: "J. King" Date: Wed, 8 Mar 2017 22:16:35 -0500 Subject: [PATCH] First battery of SQLite driver tests --- tests/Db/SQLite3/TestDbDriverSQLite3.php | 73 +++++++++++++++++++++ tests/Db/SQLite3/TestDbStatementSQLite3.php | 4 +- tests/phpunit.xml | 1 + 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 tests/Db/SQLite3/TestDbDriverSQLite3.php diff --git a/tests/Db/SQLite3/TestDbDriverSQLite3.php b/tests/Db/SQLite3/TestDbDriverSQLite3.php new file mode 100644 index 00000000..fa7d5b6a --- /dev/null +++ b/tests/Db/SQLite3/TestDbDriverSQLite3.php @@ -0,0 +1,73 @@ +dbDriver = Db\SQLite3\Driver::class; + $conf->dbSQLite3File = tempnam(sys_get_temp_dir(), 'ook'); + $this->data = new Test\RuntimeData($conf); + $this->drv = new Db\SQLite3\Driver($this->data, true); + } + + function tearDown() { + unset($this->drv); + unlink($this->data->conf->dbSQLite3File); + } + + function testExecAValidStatement() { + $this->assertTrue($this->drv->exec("CREATE TABLE test(id integer primary key)")); + } + + function testExecAnInvalidStatement() { + $this->assertException("engineErrorGeneral", "Db"); + $this->drv->exec("And the meek shall inherit the earth..."); + } + + function testExecMultipleStatements() { + $this->assertTrue($this->drv->exec("CREATE TABLE test(id integer primary key); INSERT INTO test(id) values(2112)")); + $ch = new \SQLite3($this->data->conf->dbSQLite3File); + $this->assertEquals(2112, $ch->querySingle("SELECT id from test")); + } + + function testExecTimeout() { + $ch = new \SQLite3($this->data->conf->dbSQLite3File); + $ch->exec("BEGIN EXCLUSIVE TRANSACTION"); + $this->assertException("general", "Db", "ExceptionTimeout"); + $this->drv->exec("CREATE TABLE test(id integer primary key)"); + } + + function testExecConstraintViolation() { + $this->drv->exec("CREATE TABLE test(id integer not null)"); + $this->assertException("constraintViolation", "Db", "ExceptionInput"); + $this->drv->exec("INSERT INTO test(id) values(null)"); + } + + function testValidQuery() { + $this->assertInstanceOf(Db\SQLite3\Result::class, $this->drv->query("SELECT 1")); + } + + function testInvalidQuery() { + $this->assertException("engineErrorGeneral", "Db"); + $this->drv->query("Apollo was astonished; Dionysus thought me mad"); + } + + function testQueryTimeout() { + $ch = new \SQLite3($this->data->conf->dbSQLite3File); + $ch->exec("BEGIN EXCLUSIVE TRANSACTION"); + $this->assertException("general", "Db", "ExceptionTimeout"); + $this->drv->query("CREATE TABLE test(id integer primary key)"); + } + + function testQueryConstraintViolation() { + $this->drv->exec("CREATE TABLE test(id integer not null)"); + $this->assertException("constraintViolation", "Db", "ExceptionInput"); + $this->drv->query("INSERT INTO test(id) values(null)"); + } +} \ No newline at end of file diff --git a/tests/Db/SQLite3/TestDbStatementSQLite3.php b/tests/Db/SQLite3/TestDbStatementSQLite3.php index 59b8cdbf..c288539e 100644 --- a/tests/Db/SQLite3/TestDbStatementSQLite3.php +++ b/tests/Db/SQLite3/TestDbStatementSQLite3.php @@ -61,7 +61,7 @@ class TestDbStatementSQLite3 extends \PHPUnit\Framework\TestCase { $nativeStatement = $this->c->prepare("SELECT ? as value"); $this->assertException("paramTypeMissing", "Db"); $s = new self::$imp($this->c, $nativeStatement, []); - $s->runArray([1])->get(); + $s->runArray([1]); } function testViolateConstraint() { @@ -69,6 +69,6 @@ class TestDbStatementSQLite3 extends \PHPUnit\Framework\TestCase { $nativeStatement = $this->c->prepare("INSERT INTO test(id) values(?)"); $s = new self::$imp($this->c, $nativeStatement, ["int"]); $this->assertException("constraintViolation", "Db", "ExceptionInput"); - $s->runArray([null])->get(); + $s->runArray([null]); } } \ No newline at end of file diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 27c9c01a..1153fa44 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -31,6 +31,7 @@ Db/SQLite3/TestDbResultSQLite3.php Db/SQLite3/TestDbStatementSQLite3.php + Db/SQLite3/TestDbDriverSQLite3.php \ No newline at end of file