Tests are now compliant with php-cs-fixer (CamelCase for method, phpdoc valid)
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
@@ -12,456 +13,470 @@ use Domframework\Dblayer;
|
||||
|
||||
class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
// Test with column name 'group', 'object', 'where', 'with space'
|
||||
// Test with table name 'group', 'object', 'where', 'with space'
|
||||
// For the 3 DB engines
|
||||
// Test with column name 'group', 'object', 'where', 'with space'
|
||||
// Test with table name 'group', 'object', 'where', 'with space'
|
||||
// For the 3 DB engines
|
||||
|
||||
public $engine = "{ENGINE}";
|
||||
public $confs = array (
|
||||
"sqlite" => array (
|
||||
"dsn" => "sqlite:/tmp/databaseDBLayer.db",
|
||||
"username" => null,
|
||||
"password" => null,
|
||||
"driver_options" => null,
|
||||
"tableprefix" => "",
|
||||
),
|
||||
"mysql" => array (
|
||||
"dsn" => "mysql:host=127.0.0.1;port=3306;dbname=test",
|
||||
"username" => "root",
|
||||
"password" => "lqsym",
|
||||
"driver_options" => null,
|
||||
"tableprefix" => "",
|
||||
),
|
||||
"pgsql" => array (
|
||||
"dsn" => "pgsql:host=127.0.0.1;port=5432;dbname=dbname",
|
||||
"username" => "root",
|
||||
"password" => "root",
|
||||
"driver_options" => null,
|
||||
"tableprefix" => "",
|
||||
),
|
||||
);
|
||||
public $engine = "{ENGINE}";
|
||||
public $confs = [
|
||||
"sqlite" => [
|
||||
"dsn" => "sqlite:/tmp/databaseDBLayer.db",
|
||||
"username" => null,
|
||||
"password" => null,
|
||||
"driver_options" => null,
|
||||
"tableprefix" => "",
|
||||
],
|
||||
"mysql" => [
|
||||
"dsn" => "mysql:host=127.0.0.1;port=3306;dbname=test",
|
||||
"username" => "root",
|
||||
"password" => "lqsym",
|
||||
"driver_options" => null,
|
||||
"tableprefix" => "",
|
||||
],
|
||||
"pgsql" => [
|
||||
"dsn" => "pgsql:host=127.0.0.1;port=5432;dbname=dbname",
|
||||
"username" => "root",
|
||||
"password" => "root",
|
||||
"driver_options" => null,
|
||||
"tableprefix" => "",
|
||||
],
|
||||
];
|
||||
|
||||
/** @group singleton */
|
||||
public function test_dropTable()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
foreach (
|
||||
array ("users", "grouped", "multiple", "multiple2", "users3",
|
||||
"readOR") as $table
|
||||
) {
|
||||
$db->table = $table;
|
||||
try {
|
||||
$res = $db->dropTable();
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
$db->disconnect();
|
||||
// Never generate an error, just drop the table if it exists, and do noting
|
||||
// if it doesn't exists
|
||||
}
|
||||
/**
|
||||
* @group singleton
|
||||
*/
|
||||
public function testDropTable()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
foreach (
|
||||
["users", "grouped", "multiple", "multiple2", "users3",
|
||||
"readOR"] as $table
|
||||
) {
|
||||
$db->table = $table;
|
||||
try {
|
||||
$res = $db->dropTable();
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
$db->disconnect();
|
||||
// Never generate an error, just drop the table if it exists, and do noting
|
||||
// if it doesn't exists
|
||||
}
|
||||
|
||||
/** @group singleton */
|
||||
public function test_createTable1()
|
||||
{
|
||||
// Create a table named grouped
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group" => array ("varchar", "255", "not null"),
|
||||
"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();
|
||||
$db->disconnect();
|
||||
$this->assertSame(0, $res);
|
||||
}
|
||||
/**
|
||||
* @group singleton
|
||||
*/
|
||||
public function testCreateTable1()
|
||||
{
|
||||
// Create a table named grouped
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = ["group" => ["varchar", "255", "not null"],
|
||||
"object" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = [];
|
||||
$db->primary = "group";
|
||||
$res = $db->createTable();
|
||||
$db->disconnect();
|
||||
$this->assertSame(0, $res);
|
||||
}
|
||||
|
||||
/** @group singleton */
|
||||
public function test_insert1()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group" => array ("varchar", "255", "not null"),
|
||||
"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->insert(array ("group" => "gr ou\"p",
|
||||
"object" => "/éobj%",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"));
|
||||
// SQLite start at 1, MySQL start at 0...
|
||||
$this->assertSame($res, "gr ou\"p");
|
||||
}
|
||||
/**
|
||||
* @group singleton
|
||||
*/
|
||||
public function testInsert1()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = ["group" => ["varchar", "255", "not null"],
|
||||
"object" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = [];
|
||||
$db->primary = "group";
|
||||
$res = $db->insert(["group" => "gr ou\"p",
|
||||
"object" => "/éobj%",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"]);
|
||||
// SQLite start at 1, MySQL start at 0...
|
||||
$this->assertSame($res, "gr ou\"p");
|
||||
}
|
||||
|
||||
public function test_read1()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group" => array ("varchar", "255", "not null"),
|
||||
"object" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db->unique = array ();
|
||||
$res = $db->read(array (array ("group", "gr ou\"p"),
|
||||
array ("object","/éobj%"),
|
||||
array ("where","\$'\""),
|
||||
array ("with space","with space")));
|
||||
$this->assertSame(array (0 => array ("group" => "gr ou\"p",
|
||||
"object" => "/éobj%",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space")), $res);
|
||||
}
|
||||
public function testRead1()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = ["group" => ["varchar", "255", "not null"],
|
||||
"object" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = [];
|
||||
$res = $db->read([["group", "gr ou\"p"],
|
||||
["object","/éobj%"],
|
||||
["where","\$'\""],
|
||||
["with space","with space"]]);
|
||||
$this->assertSame([0 => ["group" => "gr ou\"p",
|
||||
"object" => "/éobj%",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"]], $res);
|
||||
}
|
||||
|
||||
public function test_update1()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group" => array ("varchar", "255", "not null"),
|
||||
"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";
|
||||
// Don't update primary key
|
||||
$res = $db->update("gr ou\"p", array ("object" => "%éàoppp",
|
||||
"with space" => "WITH SPACE"));
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
public function testUpdate1()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = ["group" => ["varchar", "255", "not null"],
|
||||
"object" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = [];
|
||||
$db->primary = "group";
|
||||
// Don't update primary key
|
||||
$res = $db->update("gr ou\"p", ["object" => "%éàoppp",
|
||||
"with space" => "WITH SPACE"]);
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
|
||||
public function test_read2()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group" => array ("varchar", "255", "not null"),
|
||||
"object" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db->unique = array ();
|
||||
$res = $db->read(array (array ("group", "gr ou\"p"),
|
||||
array ("object","%éàoppp"),
|
||||
array ("where","\$'\""),
|
||||
array ("with space","WITH SPACE")));
|
||||
$this->assertSame(array (0 => array ("group" => "gr ou\"p",
|
||||
"object" => "%éàoppp",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "WITH SPACE")), $res);
|
||||
}
|
||||
public function testRead2()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = ["group" => ["varchar", "255", "not null"],
|
||||
"object" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = [];
|
||||
$res = $db->read([["group", "gr ou\"p"],
|
||||
["object","%éàoppp"],
|
||||
["where","\$'\""],
|
||||
["with space","WITH SPACE"]]);
|
||||
$this->assertSame([0 => ["group" => "gr ou\"p",
|
||||
"object" => "%éàoppp",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "WITH SPACE"]], $res);
|
||||
}
|
||||
|
||||
public function test_update2()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group" => array ("varchar", "255", "not null"),
|
||||
"object" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db->unique = array (array ("group","object"));
|
||||
$db->primary = "group";
|
||||
// Update primary key
|
||||
$res = $db->update("gr ou\"p", array ("group" => "NEW GROUP",
|
||||
"object" => "%éàoppp",
|
||||
"with space" => "WITH SPACE"));
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
public function testUpdate2()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = ["group" => ["varchar", "255", "not null"],
|
||||
"object" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = [["group","object"]];
|
||||
$db->primary = "group";
|
||||
// Update primary key
|
||||
$res = $db->update("gr ou\"p", ["group" => "NEW GROUP",
|
||||
"object" => "%éàoppp",
|
||||
"with space" => "WITH SPACE"]);
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
|
||||
public function test_read3()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group" => array ("varchar", "255", "not null"),
|
||||
"object" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db->unique = array ();
|
||||
$res = $db->read(array (array ("group", "NEW GROUP"),
|
||||
array ("object","%éàoppp"),
|
||||
array ("where","\$'\""),
|
||||
array ("with space","WITH SPACE")));
|
||||
$this->assertSame(array (0 => array ("group" => "NEW GROUP",
|
||||
"object" => "%éàoppp",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "WITH SPACE")), $res);
|
||||
}
|
||||
public function testRead3()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = ["group" => ["varchar", "255", "not null"],
|
||||
"object" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = [];
|
||||
$res = $db->read([["group", "NEW GROUP"],
|
||||
["object","%éàoppp"],
|
||||
["where","\$'\""],
|
||||
["with space","WITH SPACE"]]);
|
||||
$this->assertSame([0 => ["group" => "NEW GROUP",
|
||||
"object" => "%éàoppp",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "WITH SPACE"]], $res);
|
||||
}
|
||||
|
||||
public function test_update3()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group" => array ("varchar", "255", "not null"),
|
||||
"object" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db->unique = array ("group");
|
||||
$db->primary = "group";
|
||||
// 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);
|
||||
}
|
||||
public function testUpdate3()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = ["group" => ["varchar", "255", "not null"],
|
||||
"object" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = ["group"];
|
||||
$db->primary = "group";
|
||||
// Update primary key with primary key in unique with same values to test if
|
||||
// the exception is NOT raised
|
||||
$res = $db->update("NEW GROUP", ["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);
|
||||
}
|
||||
|
||||
/** @group singleton */
|
||||
// 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->disconnect();
|
||||
$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"),
|
||||
);
|
||||
/**
|
||||
* @group singleton
|
||||
*/
|
||||
// Part to test the foreign keys
|
||||
public function testCreateTable2()
|
||||
{
|
||||
// Create a table named group
|
||||
$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"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "users";
|
||||
$db->fields = ["user" => ["varchar", "255", "not null"],
|
||||
"groupmember" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->foreign = [
|
||||
"groupmember" => ["grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"],
|
||||
];
|
||||
|
||||
$res = $db->createTable();
|
||||
$this->assertSame(0, $res);
|
||||
}
|
||||
$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"));
|
||||
$db->disconnect();
|
||||
// SQLite start at 1, MySQL start at 0...
|
||||
$this->assertSame($res <= 2 || $res === "Us ou\"r", true);
|
||||
}
|
||||
public function testInsert2()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "users";
|
||||
$db->fields = ["user" => ["varchar", "255", "not null"],
|
||||
"groupmember" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = ["user"];
|
||||
$db->primary = "user";
|
||||
$db->foreign = [
|
||||
"groupmember" => ["grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"],
|
||||
];
|
||||
$res = $db->insert(["user" => "Us ou\"r",
|
||||
"groupmember" => "NEW GROUP",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"]);
|
||||
$db->disconnect();
|
||||
// SQLite start at 1, MySQL start at 0...
|
||||
$this->assertSame($res <= 2 || $res === "Us ou\"r", true);
|
||||
}
|
||||
|
||||
// Test the unique feature
|
||||
public function test_insert3()
|
||||
{
|
||||
$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"));
|
||||
// Unique simple in insert
|
||||
$db->unique = array ("user");
|
||||
$db->primary = "user";
|
||||
$db->foreign = array (
|
||||
"groupmember" => array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
|
||||
);
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $db->insert(array ("user" => "Us ou\"r",
|
||||
"groupmember" => "NEW GROUP",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"));
|
||||
}
|
||||
// Test the unique feature
|
||||
public function testInsert3()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "users";
|
||||
$db->fields = ["user" => ["varchar", "255", "not null"],
|
||||
"groupmember" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
// Unique simple in insert
|
||||
$db->unique = ["user"];
|
||||
$db->primary = "user";
|
||||
$db->foreign = [
|
||||
"groupmember" => ["grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"],
|
||||
];
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $db->insert(["user" => "Us ou\"r",
|
||||
"groupmember" => "NEW GROUP",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"]);
|
||||
}
|
||||
|
||||
public function test_insert4()
|
||||
{
|
||||
$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"));
|
||||
// Unique multiple in insert
|
||||
$db->unique = array (array ("user", "groupmember"));
|
||||
$db->primary = "user";
|
||||
$db->foreign = array (
|
||||
"groupmember" => array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
|
||||
);
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $db->insert(array ("user" => "Us ou\"r",
|
||||
"groupmember" => "NEW GROUP",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"));
|
||||
}
|
||||
public function testInsert4()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "users";
|
||||
$db->fields = ["user" => ["varchar", "255", "not null"],
|
||||
"groupmember" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
// Unique multiple in insert
|
||||
$db->unique = [["user", "groupmember"]];
|
||||
$db->primary = "user";
|
||||
$db->foreign = [
|
||||
"groupmember" => ["grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"],
|
||||
];
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $db->insert(["user" => "Us ou\"r",
|
||||
"groupmember" => "NEW GROUP",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"]);
|
||||
}
|
||||
|
||||
/** @group singleton */
|
||||
// Test multiple actions in one single connection
|
||||
public function test_multiple1()
|
||||
{
|
||||
/**
|
||||
* @group singleton
|
||||
*/
|
||||
// Test multiple actions in one single connection
|
||||
public function testMultiple1()
|
||||
{
|
||||
|
||||
// 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);
|
||||
}
|
||||
// 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 = ["user" => ["varchar", "255", "not null"],
|
||||
"groupmember" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->createTable();
|
||||
$db2 = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db2->table = "multiple2";
|
||||
$db2->fields = ["user" => ["varchar", "255", "not null"],
|
||||
"groupmember" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db2->createTable();
|
||||
$res = $db2->read([["user", "toto"]]);
|
||||
$res = $db->read([["user", "toto"]]);
|
||||
$db->disconnect();
|
||||
$this->assertSame([], $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);
|
||||
}
|
||||
/**
|
||||
* @group singleton
|
||||
*/
|
||||
public function testCreateTable3()
|
||||
{
|
||||
// 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 = ["user" => ["varchar", "255", "not null"],
|
||||
"groupmember" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$res = $db->createTable();
|
||||
$db->disconnect();
|
||||
$this->assertSame(0, $res);
|
||||
}
|
||||
|
||||
/** Check the OR feature on the same column with different value */
|
||||
public function test_readOR1()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "readOR";
|
||||
$db->fields = array ("id" => array ("integer"),
|
||||
"user" => array ("varchar", "255", "not null"));
|
||||
$db->primary = "id";
|
||||
$db->unique = array ("id");
|
||||
$db->createTable();
|
||||
$db->insert(array ("id" => "0", "user" => "test0"));
|
||||
$db->insert(array ("id" => "1", "user" => "test1"));
|
||||
$res = $db->read(
|
||||
array (array ("id", 0), array ("id", 1)),
|
||||
array ("user"),
|
||||
null,
|
||||
true
|
||||
);
|
||||
$db->disconnect();
|
||||
$this->assertSame(array (0 => array ("user" => "test0"),
|
||||
1 => array ("user" => "test1")), $res);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check the OR feature on the same column with different value
|
||||
*/
|
||||
public function testReadOR1()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "readOR";
|
||||
$db->fields = ["id" => ["integer"],
|
||||
"user" => ["varchar", "255", "not null"]];
|
||||
$db->primary = "id";
|
||||
$db->unique = ["id"];
|
||||
$db->createTable();
|
||||
$db->insert(["id" => "0", "user" => "test0"]);
|
||||
$db->insert(["id" => "1", "user" => "test1"]);
|
||||
$res = $db->read(
|
||||
[["id", 0], ["id", 1]],
|
||||
["user"],
|
||||
null,
|
||||
true
|
||||
);
|
||||
$db->disconnect();
|
||||
$this->assertSame([0 => ["user" => "test0"],
|
||||
1 => ["user" => "test1"]], $res);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user