From 94bc65e2038407b8b6d2b23c195b232e07208d22 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 26 Mar 2010 16:39:37 +0100 Subject: [feature/dbal-tests] Added database test & refactored test framework There is now a phpbb_database_test_case which can be used as a base class for tests that require database access. You have to set up a test_config.php file in your tests/ directory containing host, user, pass etc. Extra test functionality has been moved to phpbb_test_case_helpers to provide the same functionality in database tests and regular tests without duplicating the code. This is achieved through delegation of method calls. --- tests/test_framework/phpbb_test_case_helpers.php | 82 ++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tests/test_framework/phpbb_test_case_helpers.php (limited to 'tests/test_framework/phpbb_test_case_helpers.php') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php new file mode 100644 index 0000000000..27a730e2dd --- /dev/null +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -0,0 +1,82 @@ +test_case = $test_case; + } + + public function get_database_config() + { + if (!file_exists('test_config.php')) + { + trigger_error("You have to create a test_config.php like this: + $dbms, + 'dbhost' => $dbhost, + 'dbport' => $dbport, + 'dbname' => $dbname, + 'dbuser' => $dbuser, + 'dbpasswd' => $dbpasswd, + ); + } + + public function new_dbal() + { + global $phpbb_root_path, $phpEx; + $config = $this->get_database_config(); + + require_once '../phpBB/includes/db/' . $config['dbms'] . '.php'; + $dbal = 'dbal_' . $config['dbms']; + $db = new $dbal(); + $db->sql_connect($config['dbhost'], $config['dbuser'], $config['dbpasswd'], $config['dbname'], $config['dbport']); + + return $db; + } + + public function setExpectedTriggerError($errno, $message = '') + { + $exceptionName = ''; + switch ($errno) + { + case E_NOTICE: + case E_STRICT: + PHPUnit_Framework_Error_Notice::$enabled = true; + $exceptionName = 'PHPUnit_Framework_Error_Notice'; + break; + + case E_WARNING: + PHPUnit_Framework_Error_Warning::$enabled = true; + $exceptionName = 'PHPUnit_Framework_Error_Warning'; + break; + + default: + $exceptionName = 'PHPUnit_Framework_Error'; + break; + } + $this->expectedTriggerError = true; + $this->test_case->setExpectedException($exceptionName, (string) $message, $errno); + } +} -- cgit v1.2.1 From a7581085e002035ab5c516fe91fe4ece57087267 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 26 Mar 2010 17:37:01 +0100 Subject: [feature/dbal-tests] Load phpbb-schema after creating the connection to the database --- tests/test_framework/phpbb_test_case_helpers.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tests/test_framework/phpbb_test_case_helpers.php') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 27a730e2dd..f9ab750218 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -23,13 +23,16 @@ class phpbb_test_case_helpers if (!file_exists('test_config.php')) { trigger_error("You have to create a test_config.php like this: - Date: Thu, 1 Apr 2010 19:15:34 +0200 Subject: [feature/dbal-tests] Only output the missing config error message once. The error message was also not properly escaping the variables, thus producing an incorrect example configuration file. --- tests/test_framework/phpbb_test_case_helpers.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'tests/test_framework/phpbb_test_case_helpers.php') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index f9ab750218..0c5932e1ad 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -20,16 +20,28 @@ class phpbb_test_case_helpers public function get_database_config() { + static $show_error = true; + if (!file_exists('test_config.php')) { + if ($show_error) + { + $show_error = false; + } + else + { + $this->test_case->markTestSkipped('Missing test_config.php: See first error.'); + return; + } + trigger_error("You have to create a test_config.php like this: \"