dblayer : add more debug

dblayer : add more unit tests (foreign keys)
dblayer : add the same answer when updating a line with the same informations
dblayer : better support of foreign keys


git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1842 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2014-09-22 10:52:53 +00:00
parent 19966c094c
commit b034fa3625
2 changed files with 161 additions and 37 deletions

View File

@@ -39,20 +39,22 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase
$dbconfig = $this->confs["{ENGINE}"];
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$db->table = "grouped";
try
foreach (array ("users", "grouped") as $table)
{
$res = $db->dropTable();
}
catch (Exception $e)
{
$db->table = $table;
try
{
$res = $db->dropTable();
}
catch (Exception $e)
{
}
}
// Never generate an error, just drop the table if it exists, and do noting
// if it doesn't exists
}
public function test_createTable ()
public function test_createTable1 ()
{
// Create a table named group
$dbconfig = $this->confs["{ENGINE}"];
@@ -63,11 +65,13 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase
"object"=>array ("varchar", "255", "not null"),
"where"=>array ("varchar", "255", "not null"),
"with space"=>array ("varchar", "255", "not null"));
$db->unique = array ();
$db->primary = "group";
$res = $db->createTable ();
$this->assertSame (0, $res);
}
public function test_insert ()
public function test_insert1 ()
{
$dbconfig = $this->confs["{ENGINE}"];
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
@@ -78,6 +82,7 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase
"where"=>array ("varchar", "255", "not null"),
"with space"=>array ("varchar", "255", "not null"));
$db->unique = array ();
$db->primary = "group";
$res = $db->insert (array ("group"=>"gr ou\"p",
"object"=>"/éobj%",
"where"=>"\$'\"",
@@ -198,10 +203,60 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase
"with space"=>array ("varchar", "255", "not null"));
$db->unique = array ("group");
$db->primary = "group";
// Update primary key with primary key in unique
// Update primary key with primary key in unique with same values to test if
// the exception is NOT raised
$res = $db->update ("NEW GROUP", array ("group"=>"NEW GROUP",
"object"=>"%éàoppp",
"with space"=>"WITH SPACE"));
// SQLite and PostgreSQL return 1 line modified
// MySQL return 0 by default because there is no modification on the line
// http://fr2.php.net/manual/en/pdostatement.rowcount.php#104930
// Now, the MYSQL_ATTR_FOUND_ROWS is added to connection to be the same in
// all the engines
$this->assertSame (1, $res);
}
// Part to test the foreign keys
public function test_createTable2 ()
{
// Create a table named group
$dbconfig = $this->confs["{ENGINE}"];
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$db->table = "users";
$db->fields = array ("user"=>array ("varchar", "255", "not null"),
"groupmember"=>array ("varchar", "255", "not null"),
"where"=>array ("varchar", "255", "not null"),
"with space"=>array ("varchar", "255", "not null"));
$db->foreign = array (
"groupmember"=>array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
);
$res = $db->createTable ();
$this->assertSame (0, $res);
}
public function test_insert2 ()
{
$dbconfig = $this->confs["{ENGINE}"];
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$db->table = "users";
$db->fields = array ("user"=>array ("varchar", "255", "not null"),
"groupmember"=>array ("varchar", "255", "not null"),
"where"=>array ("varchar", "255", "not null"),
"with space"=>array ("varchar", "255", "not null"));
$db->unique = array ("user");
$db->primary = "user";
$db->foreign = array (
"groupmember"=>array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
);
$res = $db->insert (array ("user"=>"Us ou\"r",
"groupmember"=>"NEW GROUP",
"where"=>"\$'\"",
"with space"=>"with space"));
// SQLite start at 1, MySQL start at 0...
$this->assertThat($res, $this->lessThanOrEqual(2));
}
}