From f0adf08b1e384c322d948487b5e858400d7dba92 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Thu, 9 Mar 2017 09:44:50 -0500 Subject: [PATCH] Add tests for type mismatches --- tests/Db/SQLite3/TestDbDriverSQLite3.php | 12 ++++++++++++ tests/Db/SQLite3/TestDbStatementSQLite3.php | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/Db/SQLite3/TestDbDriverSQLite3.php b/tests/Db/SQLite3/TestDbDriverSQLite3.php index fa7d5b6..640a863 100644 --- a/tests/Db/SQLite3/TestDbDriverSQLite3.php +++ b/tests/Db/SQLite3/TestDbDriverSQLite3.php @@ -49,6 +49,12 @@ class TestDbDriverSQLite3 extends \PHPUnit\Framework\TestCase { $this->drv->exec("INSERT INTO test(id) values(null)"); } + function testExecTypeViolation() { + $this->drv->exec("CREATE TABLE test(id integer primary key)"); + $this->assertException("typeViolation", "Db", "ExceptionInput"); + $this->drv->exec("INSERT INTO test(id) values('ook')"); + } + function testValidQuery() { $this->assertInstanceOf(Db\SQLite3\Result::class, $this->drv->query("SELECT 1")); } @@ -70,4 +76,10 @@ class TestDbDriverSQLite3 extends \PHPUnit\Framework\TestCase { $this->assertException("constraintViolation", "Db", "ExceptionInput"); $this->drv->query("INSERT INTO test(id) values(null)"); } + + function testQueryTypeViolation() { + $this->drv->exec("CREATE TABLE test(id integer primary key)"); + $this->assertException("typeViolation", "Db", "ExceptionInput"); + $this->drv->query("INSERT INTO test(id) values('ook')"); + } } \ No newline at end of file diff --git a/tests/Db/SQLite3/TestDbStatementSQLite3.php b/tests/Db/SQLite3/TestDbStatementSQLite3.php index c288539..0600c57 100644 --- a/tests/Db/SQLite3/TestDbStatementSQLite3.php +++ b/tests/Db/SQLite3/TestDbStatementSQLite3.php @@ -71,4 +71,12 @@ class TestDbStatementSQLite3 extends \PHPUnit\Framework\TestCase { $this->assertException("constraintViolation", "Db", "ExceptionInput"); $s->runArray([null]); } + + function testMismatchTypes() { + $this->c->exec("CREATE TABLE test(id integer primary key)"); + $nativeStatement = $this->c->prepare("INSERT INTO test(id) values(?)"); + $s = new self::$imp($this->c, $nativeStatement, ["str"]); + $this->assertException("typeViolation", "Db", "ExceptionInput"); + $s->runArray(['ook']); + } } \ No newline at end of file