Browse Source

Add tests for type mismatches

microsub
J. King 7 years ago
parent
commit
f0adf08b1e
  1. 12
      tests/Db/SQLite3/TestDbDriverSQLite3.php
  2. 8
      tests/Db/SQLite3/TestDbStatementSQLite3.php

12
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')");
}
}

8
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']);
}
}
Loading…
Cancel
Save