Created separate mysql config file for tests

This commit is contained in:
Dmitriy Simushev 2012-09-07 14:08:23 +00:00
parent 0861fd73d2
commit 92019f99a4
3 changed files with 43 additions and 17 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
require_once dirname(__FILE__) . '/../../../../webim/libs/classes/database.php'; require_once dirname(__FILE__) . '/../../../../webim/libs/classes/database.php';
require_once dirname(__FILE__) . '/../../../../webim/libs/config.php'; require_once dirname(__FILE__) . '/../database_config.php';
/** /**
* Test class for Database. * Test class for Database.
@ -23,22 +23,22 @@ class DatabaseTest extends PHPUnit_Framework_TestCase {
} }
public static function setUpBeforeClass() { public static function setUpBeforeClass() {
global $mysqlhost, $mysqllogin, $mysqlpass, $mysqldb, $dbencoding, global $db_host, $db_name, $db_user, $db_pass, $tables_prefix,
$mysqlprefix, $use_persistent_connection, $force_charset_in_connection; $db_encoding, $force_charset_in_connection, $use_persistent_connection;
Database::initialize( Database::initialize(
$mysqlhost, $db_host,
$mysqllogin, $db_user,
$mysqlpass, $db_pass,
$use_persistent_connection, $use_persistent_connection,
$mysqldb, $db_name,
$mysqlprefix, $tables_prefix,
$force_charset_in_connection, $force_charset_in_connection,
$dbencoding $db_encoding
); );
$dbh = new PDO( $dbh = new PDO(
"mysql:host={$mysqlhost};dbname={$mysqldb}", "mysql:host={$db_host};dbname={$db_name}",
$mysqllogin, $db_user,
$mysqlpass $db_pass
); );
$dbh->exec( $dbh->exec(
"CREATE TABLE phpunit_test_only " . "CREATE TABLE phpunit_test_only " .
@ -48,11 +48,11 @@ class DatabaseTest extends PHPUnit_Framework_TestCase {
} }
public static function tearDownAfterClass() { public static function tearDownAfterClass() {
global $mysqlhost, $mysqllogin, $mysqlpass, $mysqldb; global $db_host, $db_user, $db_pass, $db_name;
$dbh = new PDO( $dbh = new PDO(
"mysql:host={$mysqlhost};dbname={$mysqldb}", "mysql:host={$db_host};dbname={$db_name}",
$mysqllogin, $db_user,
$mysqlpass $db_pass
); );
$dbh->exec("DROP TABLE phpunit_test_only"); $dbh->exec("DROP TABLE phpunit_test_only");
$dbh = NULL; $dbh = NULL;

View File

@ -1,8 +1,8 @@
<?php <?php
require_once dirname(__FILE__) . '/../../../../webim/libs/classes/settings.php'; require_once dirname(__FILE__) . '/../../../../webim/libs/classes/settings.php';
require_once dirname(__FILE__) . '/../../../../webim/libs/config.php';
require_once dirname(__FILE__) . '/../../../../webim/libs/classes/database.php'; require_once dirname(__FILE__) . '/../../../../webim/libs/classes/database.php';
require_once dirname(__FILE__) . '/../database_config.php';
/** /**
* Test class for Settings. * Test class for Settings.
@ -11,6 +11,18 @@ require_once dirname(__FILE__) . '/../../../../webim/libs/classes/database.php';
class SettingsTest extends PHPUnit_Framework_TestCase { class SettingsTest extends PHPUnit_Framework_TestCase {
public static function setUpBeforeClass() { public static function setUpBeforeClass() {
global $db_host, $db_name, $db_user, $db_pass, $tables_prefix,
$db_encoding, $force_charset_in_connection, $use_persistent_connection;
Database::initialize(
$db_host,
$db_user,
$db_pass,
$use_persistent_connection,
$db_name,
$tables_prefix,
$force_charset_in_connection,
$db_encoding
);
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
"INSERT INTO {chatconfig} (vckey, vcvalue) " . "INSERT INTO {chatconfig} (vckey, vcvalue) " .
@ -25,6 +37,7 @@ class SettingsTest extends PHPUnit_Framework_TestCase {
"DELETE FROM {chatconfig} WHERE vckey = ? OR vckey = ?", "DELETE FROM {chatconfig} WHERE vckey = ? OR vckey = ?",
array('some_test_key', 'some_another_test_key') array('some_test_key', 'some_another_test_key')
); );
Database::destroy();
} }
public function testGet() { public function testGet() {

View File

@ -0,0 +1,13 @@
<?php
$db_host = "";
$db_user = "";
$db_pass = "";
$db_name = "";
$tables_prefix = "";
$db_encoding = "utf8";
$force_charset_in_connection = true;
$use_persistent_connection = false;
?>