wp-cli:无法在 MAMP 上运行 phpunit

问题描述 投票:0回答:3

我正在遵循插件测试设置/安装说明。我要运行

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

阅读完this博客文章底部的评论后,我发现安装脚本引用了OSX版本的

mysqladmin
。我不确定这是否重要,但我在路径中添加了 MAMP 版本,然后重新运行安装脚本。无论如何,似乎都在
/tmp/
中安装了Wordpress文件。当我运行时出现同样的错误
phpunit

bash wordpress mamp wp-cli
3个回答
4
投票

如果您使用 MAMP,问题可能与您的 MySQL 服务器设置有关。确保选中 MAMP 设置中的

Allow network access
选项:

更新1

在根目录中创建

phpinfo.php
文件(对于 MAMP 通常为
/Applications/MAMP/htdocs
)。粘贴以下内容:

<?php phpinfo() ?>

然后检查

Loaded Configuration File
属性。使用
nano
或终端中的其他文本编辑器打开它。然后找到这 3 个属性
pdo_mysql.default_socket
mysql.default_socket
mysqli.default_socket
并将其更改为您的套接字文件。

参考自http://maccrazy.com/lion-upgrade-killed-my-php-site-and-how-i-fixed-it


1
投票

我终于

phpunit
跑了!!

我无法在任何地方找到此文档...

在安装过程中的某个时刻,Wordpress 核心文件会安装在

/tmp/wordpress/
中。 那个 WordPress 安装有它自己的
wp-config.php
文件,该文件的值不正确。当我更正这些值以匹配我网站的
wp-config.php
时,
phpunit
工作没有问题!

我不确定这是如何发生的,但我的理论是,我第一次使用错误的凭据运行安装脚本。但后来我纠正了它们(我重新运行了安装脚本几次)。但我认为安装脚本没有覆盖原始文件。

+400 致@Nikita Zernov 提供如此多的帮助!


0
投票

通常,如果您通过 ftp 或 telnet 到本地主机,您会得到

conection refused
,如果您想修复错误,请将
httpd.conf
更改为
ServerName localhost

此外,如果您想进行远程登录,请尝试通过以下方式启用远程登录:

System Preferences -> Sharing -> Remote Login box (check it)

对于MySQL问题

确保‘skip-networking’在配置文件中被注释掉(在这种情况下

/opt/local/etc/mysql55/my.conf
)或者启动mysql服务器时,它不以‘–skip-networking’开头

在跳过网络模式下,mysql实例根本不“监听TCP/IP连接”。与 mysqld 的所有交互都必须使用命名管道或共享内存(在 Windows 上)或 Unix 套接字文件(在 Unix 上)” 来自 MySql Docs

© www.soinside.com 2019 - 2024. All rights reserved.