wordpress-develop单元测试无法获取mysqli

时间:2017-08-31 20:28:26

标签: wordpress mysqli phpunit

我在堆栈溢出时看到了很多mysqli错误,但似乎都没有与wordpress-develop相关

我设置了测试文件夹bootstrap.php。

if ( function_exists( 'xdebug_disable' ) ) {
xdebug_disable();
}
if ( false !== getenv( 'WP_DEVELOP_DIR' ) ) {
require getenv( 'WP_DEVELOP_DIR' ) . '\tests\phpunit\includes\bootstrap.php';
}
if ( false !== getenv( 'WP_PLUGIN_DIR' ) ) {
define( 'WP_PLUGIN_DIR', getenv( 'WP_PLUGIN_DIR' ) );
}

phpunit.xml

<phpunit bootstrap="tests/bootstrap.php">
    <testsuites>
        <testsuite>
            <directory prefix="test-" suffix=".php">./tests/</directory>
        </testsuite>
    </testsuites>
</phpunit>

配置

define( 'DB_NAME', 'bitnami_wordpress_testing' );
define( 'DB_USER', 'root' );
define( 'DB_PASSWORD', '' );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );

当我运行一个简单的测试时

class test extends WP_UnitTestCase {
    public function test_foo_is_foo() {
        $this->assertTrue( 'foo' === 'foo' );
    }
}

我得到了结果以及一系列警告。

PHP Warning:  mysqli_query(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1812
PHP Warning:  mysqli_errno(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1708
PHP Warning:  mysqli_error(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1735
PHP Warning:  mysqli_affected_rows(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1760
PHP Warning:  mysqli_query(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1812
PHP Warning:  mysqli_errno(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1708
PHP Warning:  mysqli_error(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1735
PHP Warning:  mysqli_affected_rows(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1760
PHP Warning:  mysqli_query(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1812
PHP Warning:  mysqli_errno(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1708
PHP Warning:  mysqli_error(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1735
PHP Warning:  mysqli_affected_rows(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1760
PHP Warning:  mysqli_query(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1812
PHP Warning:  mysqli_errno(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1708
PHP Warning:  mysqli_error(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1735
PHP Warning:  mysqli_affected_rows(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1760
PHP Warning:  mysqli_query(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1812
PHP Warning:  mysqli_errno(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1708
PHP Warning:  mysqli_error(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1735
PHP Warning:  mysqli_affected_rows(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1760
PHP Warning:  mysqli_query(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1812
PHP Warning:  mysqli_errno(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1708
PHP Warning:  mysqli_error(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1735
PHP Warning:  mysqli_affected_rows(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1760
PHP Warning:  mysqli_query(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1812
PHP Warning:  mysqli_errno(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1708
PHP Warning:  mysqli_error(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1735
PHP Warning:  mysqli_affected_rows(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1760
PHP Warning:  mysqli_query(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1812
PHP Warning:  mysqli_errno(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1708
PHP Warning:  mysqli_error(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1735
PHP Warning:  mysqli_affected_rows(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1760
PHP Warning:  mysqli_query(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1812
PHP Warning:  mysqli_errno(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1708
PHP Warning:  mysqli_error(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1735
PHP Warning:  mysqli_affected_rows(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1760
PHP Warning:  mysqli_query(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1812
PHP Warning:  mysqli_errno(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1708
PHP Warning:  mysqli_error(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1735
PHP Warning:  mysqli_affected_rows(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1760
PHP Warning:  mysqli_query(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1812
PHP Warning:  mysqli_errno(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1708
PHP Warning:  mysqli_error(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1735
PHP Warning:  mysqli_affected_rows(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1760
PHP Warning:  mysqli_query(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1812
PHP Warning:  mysqli_errno(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1708
PHP Warning:  mysqli_error(): Couldn't fetch mysqli in C:\Documents\wordpress-develop\src\wp-includes\wp-db.php on line 1735

我测试了几种基本方法,似乎也没有从数据库中获取信息。不确定重复警告是否有任何意义。有wordpress-develop经验的人都知道这个问题可能来自哪里。或者也许有人知道一个更好的方法/首选教程,用于启动和运行wordpress单元测试?

1 个答案:

答案 0 :(得分:0)

我有同样的问题,但是当我以前使用5.0。*版本时,将phpunit更新到6.5版(用于WordPress 4.9.4进行测试)时,警告消失了。