Как я могу отлаживать подключение к базе данных для модульного тестирования?

Я установил среду WordPress на своем Mac с MAMP, и я запускаю 3.5.1 локально (например, http://localhost:8888/blog works). Я пытаюсь запустить единичный тестовый костюм с wordpress.org и не удается подключиться к базе данных.

 $svn co https://unit-tests.svn.wordpress.org/trunk wordpress-tests $cd wordpress-tests $cp wp-tests-config-sample.php wp-tests-config.php 

edit wp-test-config.php для моей настройки

 $ cat wp-tests-config.php <?php /* Path to the WordPress codebase you'd like to test. Add a backslash in the end. */ define( 'ABSPATH', '/Applications/MAMP/htdocs/blog/' ); // Test with multisite enabled: (previously -m) // define( 'WP_TESTS_MULTISITE', true ); // Force known bugs: (previously -f) // define( 'WP_TESTS_FORCE_KNOWN_BUGS', true ); // Test with WordPress debug mode on (previously -d) // define( 'WP_DEBUG', true ); // ** MySQL settings ** // // This configuration file will be used by the copy of WordPress being tested. // wordpress/wp-config.php will be ignored. // WARNING WARNING WARNING! // These tests will DROP ALL TABLES in the database with the prefix named below. // DO NOT use a production database or one that is shared with something else. define( 'DB_NAME', 'wordpress' ); define( 'DB_USER', 'root' ); define( 'DB_PASSWORD', 'root' ); define( 'DB_HOST', 'localhost:8889' ); define( 'DB_CHARSET', 'utf8' ); define( 'DB_COLLATE', '' ); $table_prefix = 'wp_'; // Only numbers, letters, and underscores please! define( 'WP_TESTS_DOMAIN', 'example.org' ); define( 'WP_TESTS_EMAIL', 'admin@example.org' ); define( 'WP_TESTS_TITLE', 'Test Blog' ); define( 'WP_PHP_BINARY', 'php' ); define( 'WPLANG', '' ); 

Но, когда я пытаюсь запустить тестовый пакет, я phpunit не могу подключиться к базе данных:

 $phpunit ... <h1>Error establishing a database connection</h1> <p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>localhost:8889</code>. This could mean your host's database server is down.</p> ... 

Может ли кто-нибудь помочь отладить эту проблему?

** РЕДАКТИРОВАТЬ **

После добавления wp-content/db-error.php как описано ниже. Я получаю следующую ошибку:

 $ phpunit PHP Warning: mysql_error() expects parameter 1 to be resource, boolean given in /Users/spinlock/WordPress/wordpress-3.5.1/wp-includes/wp-db.php on line 1023 WordPress database error for query made by require_once('/Users/spinlock/WordPress/wordpress-3.5.1/wp-settings.php'), wp_set_wpdb_vars, dead_db, require_once('/Users/spinlock/WordPress/wordpress-3.5.1/wp-content/db-error.php') Running as single site... To run multisite, use -c multisite.xml PHP Warning: mysql_error() expects parameter 1 to be resource, boolean given in /Users/spinlock/WordPress/wordpress-3.5.1/wp-includes/wp-db.php on line 1023 WordPress database error for query made by PHPUnit_TextUI_Command::main, PHPUnit_TextUI_Command->run, PHPUnit_TextUI_Command->handleArguments, PHPUnit_TextUI_Command->handleBootstrap, PHPUnit_Util_Fileloader::checkAndLoad, PHPUnit_Util_Fileloader::load, include_once('/Users/spinlock/WordPress/wordpress-tests/includes/bootstrap.php'), require_once('/Users/spinlock/WordPress/wordpress-3.5.1/wp-settings.php'), wp_set_wpdb_vars, dead_db, require_once('/Users/spinlock/WordPress/wordpress-3.5.1/wp-content/db-error.php') 

wp-db.php строка 1023 – это реализация print_error() и она задыхается здесь:

 1019 function print_error( $str = '' ) { 1020 global $EZSQL_ERROR; 1021 1022 if ( !$str ) 1023 $str = mysql_error( $this->dbh ); 1024 $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str ); 1025 

Решение

Хорошо, я, наконец, получил эту работу, изменив DB_HOST на localhost:/Applications/MAMP/tmp/mysql/mysql.sock .

И тесты выполняются:

 $ phpunit Installing... Running as single site... To run multisite, use -c multisite.xml Not running ajax tests... To execute these, use --group ajax. PHPUnit 3.7.19 by Sebastian Bergmann. Configuration read from /Users/spinlock/WordPress/wordpress-tests/phpunit.xml.dist .............FFF................PHP Fatal error: Call to undefined function wp_unslash() in /Users/spinlock/WordPress/wordpress-tests/tests/attachment/slashes.php on line 45 Fatal error: Call to undefined function wp_unslash() in /Users/spinlock/WordPress/wordpress-tests/tests/attachment/slashes.php on line 45 

Solutions Collecting From Web of "Как я могу отлаживать подключение к базе данных для модульного тестирования?"