aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/test_framework/framework.php3
-rw-r--r--tests/test_framework/phpbb_database_test_case.php42
-rw-r--r--tests/test_framework/phpbb_test_case.php30
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php82
4 files changed, 137 insertions, 20 deletions
diff --git a/tests/test_framework/framework.php b/tests/test_framework/framework.php
index 5913d20ca0..abdcd1ad79 100644
--- a/tests/test_framework/framework.php
+++ b/tests/test_framework/framework.php
@@ -33,4 +33,7 @@ if (version_compare(PHPUnit_Runner_Version::id(), '3.3.0', '<'))
}
require_once 'PHPUnit/Framework.php';
+require_once 'PHPUnit/Extensions/Database/TestCase.php';
+require_once 'test_framework/phpbb_test_case_helpers.php';
require_once 'test_framework/phpbb_test_case.php';
+require_once 'test_framework/phpbb_database_test_case.php';
diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php
new file mode 100644
index 0000000000..f0aa54ec8d
--- /dev/null
+++ b/tests/test_framework/phpbb_database_test_case.php
@@ -0,0 +1,42 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2008 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_TestCase
+{
+ protected $test_case_helpers;
+
+ public function init_test_case_helpers()
+ {
+ if (!$this->test_case_helpers)
+ {
+ $this->test_case_helpers = new phpbb_test_case_helpers($this);
+ }
+ }
+
+ public function getConnection()
+ {
+ $this->init_test_case_helpers();
+ $database_config = $this->test_case_helpers->get_database_config();
+
+ $pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']);
+ return $this->createDefaultDBConnection($pdo, 'testdb');
+ }
+
+ public function new_dbal()
+ {
+ $this->init_test_case_helpers();
+ return $this->test_case_helpers->new_dbal();
+ }
+
+ public function setExpectedTriggerError($errno, $message = '')
+ {
+ $this->init_test_case_helpers();
+ $this->test_case_helpers->setExpectedTriggerError($errno, $message);
+ }
+}
diff --git a/tests/test_framework/phpbb_test_case.php b/tests/test_framework/phpbb_test_case.php
index 3cf2a9d442..af867b29ff 100644
--- a/tests/test_framework/phpbb_test_case.php
+++ b/tests/test_framework/phpbb_test_case.php
@@ -9,29 +9,19 @@
class phpbb_test_case extends PHPUnit_Framework_TestCase
{
- protected $expectedTriggerError = false;
+ protected $test_case_helpers;
- public function setExpectedTriggerError($errno, $message = '')
+ public function init_test_case_helpers()
{
- $exceptionName = '';
- switch ($errno)
+ if (!$this->test_case_helpers)
{
- 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->test_case_helpers = new phpbb_test_case_helpers($this);
}
- $this->expectedTriggerError = true;
- $this->setExpectedException($exceptionName, (string) $message, $errno);
+ }
+
+ public function setExpectedTriggerError($errno, $message = '')
+ {
+ $this->init_test_case_helpers();
+ $this->test_case_helpers->setExpectedTriggerError($errno, $message);
}
}
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 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2008 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+class phpbb_test_case_helpers
+{
+ protected $expectedTriggerError = false;
+
+ protected $test_case;
+
+ public function __construct($test_case)
+ {
+ $this->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:
+<?php
+$dbms = 'mysqli';
+$dbhost = 'localhost';
+$dbport = '';
+$dbname = 'database';
+$dbuser = 'user';
+$dbpasswd = 'password';", E_USER_ERROR);
+ }
+ include('test_config.php');
+
+ return array(
+ 'dbms' => $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);
+ }
+}