我正在遵循插件测试设置/安装说明。我得wp scaffold plugin-tests my-plugin
跑了。但是在下一步尝试运行时,bash bin/install-wp-tests.sh wordpress_test root '' localhost latest
我收到以下错误:
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to MySQL server on 'localhost' (61)'
Check that mysqld is running on localhost and that the port is 3306.
You can check this by doing 'telnet localhost 3306'
我的本地 Wordpress 站点正在运行 MAMP(正在运行)。我不确定这是否与安装脚本相关,因为我认为它正在创建一个临时数据库来运行测试......它使用内置的 OSX mysql 还是 MAMP 的 MySQL 是否重要?
这是来自的输出wp --info
$ ./vendor/wp-cli/wp-cli/bin/wp --info
PHP binary: /Applications/MAMP/bin/php/php5.6.10/bin/php
PHP version: 5.6.10
php.ini used: /Applications/MAMP/bin/php/php5.6.10/conf/php.ini
WP-CLI root dir: /Applications/MAMP/htdocs/pipeline/wp-content/plugins/wp-github-pipeline/vendor/wp-cli/wp-cli
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 0.19.2
更新 2 我发现最初没有安装 MySQL ......这就是我无法连接的原因!但现在是。我运行了安装脚本,这有效......
$ ./vendor/wp-cli/wp-cli/bin/wp db tables
wp_users
wp_usermeta
wp_posts
wp_comments
wp_links
wp_options
wp_postmeta
wp_terms
wp_term_taxonomy
wp_term_relationships
wp_commentmeta
但是当我跑步时,phpunit
我得到了这个:
$ phpunit
PHP Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452
PHP Stack trace:
PHP 1. {main}() /private/tmp/wordpress-tests-lib/includes/install.php:0
PHP 2. require_once() /private/tmp/wordpress-tests-lib/includes/install.php:21
PHP 3. require_wp_db() /private/tmp/wordpress/wp-settings.php:79
PHP 4. wpdb->__construct() /private/tmp/wordpress/wp-includes/load.php:350
PHP 5. wpdb->db_connect() /private/tmp/wordpress/wp-includes/wp-db.php:649
PHP 6. mysqli_real_connect() /private/tmp/wordpress/wp-includes/wp-db.php:1452
Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452
我的部分问题是我不清楚 wp-cli 是否应该完全在本机 (cli) PHP/Mysql 或 MAMP 的 PHP/Mysql 或两者的某种组合上运行。
更新 4 我很确定最后一个问题是 phpunit 需要安装在 MAMP 中,但我是从 OSX 运行它...
$which phpunit
/usr/bin/phpunit
在这个要点中提到。
更新 6
事实证明,您不能再使用 pear 安装 phpunit。所以我将它添加为 require-dev 下的作曲家依赖项,但是当我运行该版本时,我得到了同样的错误!
$ ./vendor/phpunit/phpunit/phpunit
PHP Warning: mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452
PHP Stack trace:
PHP 1. {main}() /private/tmp/wordpress-tests-lib/includes/install.php:0
PHP 2. require_once() /private/tmp/wordpress-tests-lib/includes/install.php:21
PHP 3. require_wp_db() /private/tmp/wordpress/wp-settings.php:79
PHP 4. wpdb->__construct() /private/tmp/wordpress/wp-includes/load.php:350
PHP 5. wpdb->db_connect() /private/tmp/wordpress/wp-includes/wp-db.php:649
PHP 6. mysqli_real_connect() /private/tmp/wordpress/wp-includes/wp-db.php:1452
Warning: mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452
我什至将它添加到我的路径中以确保...
$ which phpunit
/Applications/MAMP/htdocs/pipeline/wp-content/plugins/wp-github-pipeline/vendor/phpunit/phpunit/phpunit
更新 7
在阅读了这篇博文底部的评论后,我看到安装脚本引用了 OSX 版本的mysqladmin
. 我不确定这是否重要,但我在路径中添加了 MAMP 版本,并重新运行了安装脚本。/tmp/
无论如何,它似乎都安装了 Wordpress 文件。我运行时出现同样的错误phpunit