dblayer tests : add the disconnect when needed to deconnect from the singleton

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2260 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2015-08-20 12:21:19 +00:00
parent e0b6aa77d2
commit ec235d606d

View File

@@ -34,12 +34,14 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase
), ),
); );
/** @group singleton */
public function test_dropTable () public function test_dropTable ()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"], $db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]); $dbconfig["password"], $dbconfig["driver_options"]);
foreach (array ("users", "grouped") as $table) foreach (array ("users", "grouped", "multiple", "multiple2", "users3") as
$table)
{ {
$db->table = $table; $db->table = $table;
try try
@@ -54,9 +56,10 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase
// if it doesn't exists // if it doesn't exists
} }
/** @group singleton */
public function test_createTable1 () public function test_createTable1 ()
{ {
// Create a table named group // Create a table named grouped
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"], $db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]); $dbconfig["password"], $dbconfig["driver_options"]);
@@ -68,9 +71,11 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase
$db->unique = array (); $db->unique = array ();
$db->primary = "group"; $db->primary = "group";
$res = $db->createTable (); $res = $db->createTable ();
$db->disconnect ();
$this->assertSame (0, $res); $this->assertSame (0, $res);
} }
/** @group singleton */
public function test_insert1 () public function test_insert1 ()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
@@ -216,11 +221,15 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase
$this->assertSame (1, $res); $this->assertSame (1, $res);
} }
/** @group singleton */
// Part to test the foreign keys // Part to test the foreign keys
public function test_createTable2 () public function test_createTable2 ()
{ {
// Create a table named group // Create a table named group
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$db->disconnect ();
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"], $db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]); $dbconfig["password"], $dbconfig["driver_options"]);
$db->table = "users"; $db->table = "users";
@@ -255,6 +264,7 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase
"groupmember"=>"NEW GROUP", "groupmember"=>"NEW GROUP",
"where"=>"\$'\"", "where"=>"\$'\"",
"with space"=>"with space")); "with space"=>"with space"));
$db->disconnect ();
// SQLite start at 1, MySQL start at 0... // SQLite start at 1, MySQL start at 0...
$this->assertThat($res, $this->lessThanOrEqual(2)); $this->assertThat($res, $this->lessThanOrEqual(2));
} }
@@ -305,4 +315,50 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase
"where"=>"\$'\"", "where"=>"\$'\"",
"with space"=>"with space")); "with space"=>"with space"));
} }
/** @group singleton */
// Test multiple actions in one single connection
public function test_multiple1 ()
{
// Create a table named group
$dbconfig = $this->confs["{ENGINE}"];
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$db->table = "multiple";
$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->createTable ();
$db2 = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$db2->table = "multiple2";
$db2->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"));
$db2->createTable ();
$res = $db2->read (array (array ("user", "toto")));
$res = $db->read (array (array ("user", "toto")));
$db->disconnect ();
$this->assertSame (array (), $res);
}
/** @group singleton */
public function test_createTable3 ()
{
// Create a table named group
$dbconfig = $this->confs["{ENGINE}"];
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$db->table = "users3";
$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"));
$res = $db->createTable ();
$db->disconnect ();
$this->assertSame (0, $res);
}
} }