1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
<?php
/**
*
* @package testing
* @copyright (c) 2008 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
class phpbb_test_case_helpers
{
protected $expectedTriggerError = false;
protected $test_case;
public function __construct($test_case)
{
$this->test_case = $test_case;
}
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);
}
public function makedirs($path)
{
mkdir($path, 0777, true);
}
static public function get_test_config()
{
$config = array();
if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>='))
{
$config = array_merge($config, array(
'dbms' => 'sqlite',
'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename
'dbport' => '',
'dbname' => '',
'dbuser' => '',
'dbpasswd' => '',
));
}
if (isset($_SERVER['PHPBB_TEST_CONFIG']))
{
// Could be an absolute path
$test_config = $_SERVER['PHPBB_TEST_CONFIG'];
}
else
{
$test_config = dirname(__FILE__) . '/../test_config.php';
}
if (file_exists($test_config))
{
include($test_config);
$config = array_merge($config, array(
'dbms' => $dbms,
'dbhost' => $dbhost,
'dbport' => $dbport,
'dbname' => $dbname,
'dbuser' => $dbuser,
'dbpasswd' => $dbpasswd,
));
if (isset($phpbb_functional_url))
{
$config['phpbb_functional_url'] = $phpbb_functional_url;
}
}
if (isset($_SERVER['PHPBB_TEST_DBMS']))
{
$config = array_merge($config, array(
'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $_SERVER['PHPBB_TEST_DBMS'] : '',
'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '',
'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '',
'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '',
'dbuser' => isset($_SERVER['PHPBB_TEST_DBUSER']) ? $_SERVER['PHPBB_TEST_DBUSER'] : '',
'dbpasswd' => isset($_SERVER['PHPBB_TEST_DBPASSWD']) ? $_SERVER['PHPBB_TEST_DBPASSWD'] : ''
));
}
if (isset($_SERVER['PHPBB_FUNCTIONAL_URL']))
{
$config = array_merge($config, array(
'phpbb_functional_url' => isset($_SERVER['PHPBB_FUNCTIONAL_URL']) ? $_SERVER['PHPBB_FUNCTIONAL_URL'] : '',
));
}
return $config;
}
}
|