mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[task/mssql-db-tests] No longer display an error when skipping db tests.
Tests are run with sqlite by default now anyway, so in the majority of cases the error message explaining how to set up database test running will not be displayed anyway. Database tests are now generally simply skipped if no configuration can be found. The RUNNING_TESTS.txt file explains how to set them up however, and more info is available on the wiki. The get_database_config method was moved from test_case_helpers to database_test_case because it has no general purpose. PHPBB3-9868
This commit is contained in:
parent
ee846c461c
commit
9dbbfea5fd
3 changed files with 70 additions and 76 deletions
|
@ -1,33 +1,51 @@
|
||||||
Running Tests
|
Running Tests
|
||||||
-------------
|
=============
|
||||||
|
|
||||||
Prerequisites
|
Prerequisites
|
||||||
-------------
|
=============
|
||||||
|
|
||||||
PHPUnit
|
PHPUnit
|
||||||
=======
|
-------
|
||||||
|
|
||||||
phpBB unit tests use PHPUnit framework. Version 3.3 or better is required
|
phpBB unit tests use PHPUnit framework. Version 3.3 or better is required
|
||||||
to run the tests. PHPUnit prefers to be installed via PEAR; refer to
|
to run the tests. PHPUnit prefers to be installed via PEAR; refer to
|
||||||
http://www.phpunit.de/ for more information.
|
http://www.phpunit.de/ for more information.
|
||||||
|
|
||||||
PHP extensions
|
PHP extensions
|
||||||
==============
|
--------------
|
||||||
|
|
||||||
Unit tests use several PHP extensions that board code does not use. Currently
|
Unit tests use several PHP extensions that board code does not use. Currently
|
||||||
the following PHP extensions must be installed and enabled to run unit tests:
|
the following PHP extensions must be installed and enabled to run unit tests:
|
||||||
|
|
||||||
- ctype
|
- ctype
|
||||||
|
|
||||||
|
Database Tests
|
||||||
|
--------------
|
||||||
|
By default all tests requiring a database connection will use sqlite. If you
|
||||||
|
do not have sqlite installed the tests will be skipped. If you wish to run the
|
||||||
|
tests on a different database you have to create a test_config.php file within
|
||||||
|
your tests directory following the same format as phpBB's config.php. An example
|
||||||
|
for mysqli can be found below. More information on configuration options can be
|
||||||
|
found on the wiki (see below).
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$dbms = 'mysqli';
|
||||||
|
$dbhost = 'localhost';
|
||||||
|
$dbport = '';
|
||||||
|
$dbname = 'database';
|
||||||
|
$dbuser = 'user';
|
||||||
|
$dbpasswd = 'password';
|
||||||
|
|
||||||
|
|
||||||
Running
|
Running
|
||||||
-------
|
=======
|
||||||
|
|
||||||
Once the prerequisites are installed, run the tests from tests directory:
|
Once the prerequisites are installed, run the tests from tests directory:
|
||||||
|
|
||||||
$ phpunit all_tests.php
|
$ phpunit all_tests.php
|
||||||
|
|
||||||
More Information
|
More Information
|
||||||
----------------
|
================
|
||||||
|
|
||||||
Further information is available on phpbb wiki:
|
Further information is available on phpbb wiki:
|
||||||
http://wiki.phpbb.com/display/DEV/Unit+Tests
|
http://wiki.phpbb.com/display/DEV/Unit+Tests
|
||||||
|
|
|
@ -81,6 +81,41 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get_database_config()
|
||||||
|
{
|
||||||
|
static $show_error = true;
|
||||||
|
|
||||||
|
if (file_exists('test_config.php'))
|
||||||
|
{
|
||||||
|
include('test_config.php');
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'dbms' => $dbms,
|
||||||
|
'dbhost' => $dbhost,
|
||||||
|
'dbport' => $dbport,
|
||||||
|
'dbname' => $dbname,
|
||||||
|
'dbuser' => $dbuser,
|
||||||
|
'dbpasswd' => $dbpasswd,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>='))
|
||||||
|
{
|
||||||
|
// Silently use sqlite
|
||||||
|
return array(
|
||||||
|
'dbms' => 'sqlite',
|
||||||
|
'dbhost' => 'phpbb_unit_tests.sqlite2', // filename
|
||||||
|
'dbport' => '',
|
||||||
|
'dbname' => '',
|
||||||
|
'dbuser' => '',
|
||||||
|
'dbpasswd' => '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->markTestSkipped('Missing test_config.php: See first error.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE: This function is not the same as split_sql_file from functions_install
|
// NOTE: This function is not the same as split_sql_file from functions_install
|
||||||
public function split_sql_file($sql, $dbms)
|
public function split_sql_file($sql, $dbms)
|
||||||
{
|
{
|
||||||
|
@ -115,7 +150,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
|
||||||
{
|
{
|
||||||
static $already_connected;
|
static $already_connected;
|
||||||
|
|
||||||
$database_config = $this->get_test_case_helpers()->get_database_config();
|
$database_config = $this->get_database_config();
|
||||||
|
|
||||||
$dbms_data = $this->get_dbms_data($database_config['dbms']);
|
$dbms_data = $this->get_dbms_data($database_config['dbms']);
|
||||||
|
|
||||||
|
@ -190,7 +225,16 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
|
||||||
|
|
||||||
public function new_dbal()
|
public function new_dbal()
|
||||||
{
|
{
|
||||||
return $this->get_test_case_helpers()->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 = '')
|
public function setExpectedTriggerError($errno, $message = '')
|
||||||
|
|
|
@ -18,74 +18,6 @@ class phpbb_test_case_helpers
|
||||||
$this->test_case = $test_case;
|
$this->test_case = $test_case;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_database_config()
|
|
||||||
{
|
|
||||||
static $show_error = true;
|
|
||||||
|
|
||||||
if (file_exists('test_config.php'))
|
|
||||||
{
|
|
||||||
include('test_config.php');
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'dbms' => $dbms,
|
|
||||||
'dbhost' => $dbhost,
|
|
||||||
'dbport' => $dbport,
|
|
||||||
'dbname' => $dbname,
|
|
||||||
'dbuser' => $dbuser,
|
|
||||||
'dbpasswd' => $dbpasswd,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>='))
|
|
||||||
{
|
|
||||||
// Silently use sqlite
|
|
||||||
return array(
|
|
||||||
'dbms' => 'sqlite',
|
|
||||||
'dbhost' => 'phpbb_unit_tests.sqlite2', // filename
|
|
||||||
'dbport' => '',
|
|
||||||
'dbname' => '',
|
|
||||||
'dbuser' => '',
|
|
||||||
'dbpasswd' => '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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:
|
|
||||||
\"<?php
|
|
||||||
\$dbms = 'mysqli';
|
|
||||||
\$dbhost = 'localhost';
|
|
||||||
\$dbport = '';
|
|
||||||
\$dbname = 'database';
|
|
||||||
\$dbuser = 'user';
|
|
||||||
\$dbpasswd = 'password';
|
|
||||||
\"
|
|
||||||
|
|
||||||
NOTE: The database is dropped and recreated with the phpbb-db-schema! Do NOT specify a database with important data.", E_USER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = '')
|
public function setExpectedTriggerError($errno, $message = '')
|
||||||
{
|
{
|
||||||
$exceptionName = '';
|
$exceptionName = '';
|
||||||
|
|
Loading…
Add table
Reference in a new issue