3 if( php_sapi_name() != 'cli' ) {
4 echo 'Must be run from the command line.';
8 error_reporting( E_ALL
);
9 define( "MEDIAWIKI", true );
11 set_include_path( get_include_path() . PATH_SEPARATOR
. 'PHPUnit' );
12 set_include_path( get_include_path() . PATH_SEPARATOR
. '..' );
14 // Error handling when requiring PHPUnit.php
15 function phpunitErrorHandler( $erno, $errstr, $errfile, $errline) {
16 echo "Unable to include PHPUnit.php, you should install it first (see README).\n";
20 set_error_handler('phpunitErrorHandler');
21 require_once( 'PHPUnit.php' );
22 restore_error_handler();
37 if( file_exists( 'LocalTestSettings.php' ) ) {
38 include( './LocalTestSettings.php' );
50 if( isset( $_SERVER['argv'][1] ) ) {
52 $tests = array( $_SERVER['argv'][1] );
55 foreach( $tests as $test ) {
56 require_once( $test . '.php' );
57 $suite = new PHPUnit_TestSuite( $test );
58 $result = PHPUnit
::run( $suite );
59 echo $result->toString();
63 * @param string $serverType
64 * @param array $tables
66 function &buildTestDatabase( $serverType, $tables ) {
67 global $testOptions, $wgDBprefix;
68 $wgDBprefix = 'parsertest';
70 $testOptions[$serverType]['server'],
71 $testOptions[$serverType]['user'],
72 $testOptions[$serverType]['password'],
73 $testOptions[$serverType]['database'] );
75 if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
76 # Database that supports CREATE TABLE ... LIKE
77 foreach ($tables as $tbl) {
78 $newTableName = $db->tableName( $tbl );
79 #$tableName = $this->oldTableNames[$tbl];
81 $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName INCLUDING DEFAULTS)");
84 # Hack for MySQL versions < 4.1, which don't support
85 # "CREATE TABLE ... LIKE". Note that
86 # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
87 # would not create the indexes we need....
88 foreach ($tables as $tbl) {
89 $res = $db->query("SHOW CREATE TABLE $tbl");
90 $row = $db->fetchRow($res);
92 $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
93 . $wgDBprefix . '\\1`', $create);
94 if ($create === $create_tmp) {
95 # Couldn't do replacement
96 wfDie( "could not create temporary table $tbl" );
98 $db->query($create_tmp);