WP_UnitTestCase - 如何使用 phpunit PHAR 正确配置 include_path
WP_UnitTestCase - how to configure the include_path correctly with phpunit PHAR
我正在尝试为我的 wordpress 插件编写 php 单元测试,并且一直在本地关注 writing-wordpress-plugin-unit-tests tutorial. I've cloned the 'core.trac.wordpress.org/browser/tests/trunk/includes'
我已经按照此处所述通过 PHAR 机制安装了 php 单元:https://phpunit.de/manual/current/en/installation.html#installation.requirements。我还有一个composer.json配置
[14:11:04@~]$ phpunit --version
PHPUnit 4.7.3 by Sebastian Bergmann and contributors.
在我的/etc/php.ini 文件中有
include_path="."
当我 运行 我的 php 设备出现此错误时
[14:18:07@bhaawp]$ phpunit
PHP Fatal error: require_once(): Failed opening required 'PHPUnit/Autoload.php' (include_path='.') in /Users/pauloconnell/projects/bhaawp/wp-phpunit/bootstrap.php on line 7
bootstrap.php 文件包含此内容
<?php
/**
* Installs WordPress for running the tests and loads WordPress and the test libraries
*/
require_once 'PHPUnit/Autoload.php';
我想我需要将 phpunit 文件夹添加到路径中,但我对应该将其设置在哪里有心理障碍?
PHPUnit 没有名为 PHPUnit/Autoload.php
的文件(不再)。
如果 Wordpress 的测试套件和/或测试 Wordpress 插件的最佳实践提到/使用该文件,那么这将表明 Wordpress 依赖于过时版本的 PHPUnit。
您需要克隆 https://core.trac.wordpress.org/browser/trunk/tests/phpunit/includes/。您克隆的是旧的,不再更新。
您将看到 new bootstrap.php 中不再存在该行。
我正在尝试为我的 wordpress 插件编写 php 单元测试,并且一直在本地关注 writing-wordpress-plugin-unit-tests tutorial. I've cloned the 'core.trac.wordpress.org/browser/tests/trunk/includes'
我已经按照此处所述通过 PHAR 机制安装了 php 单元:https://phpunit.de/manual/current/en/installation.html#installation.requirements。我还有一个composer.json配置
[14:11:04@~]$ phpunit --version
PHPUnit 4.7.3 by Sebastian Bergmann and contributors.
在我的/etc/php.ini 文件中有
include_path="."
当我 运行 我的 php 设备出现此错误时
[14:18:07@bhaawp]$ phpunit
PHP Fatal error: require_once(): Failed opening required 'PHPUnit/Autoload.php' (include_path='.') in /Users/pauloconnell/projects/bhaawp/wp-phpunit/bootstrap.php on line 7
bootstrap.php 文件包含此内容
<?php
/**
* Installs WordPress for running the tests and loads WordPress and the test libraries
*/
require_once 'PHPUnit/Autoload.php';
我想我需要将 phpunit 文件夹添加到路径中,但我对应该将其设置在哪里有心理障碍?
PHPUnit 没有名为 PHPUnit/Autoload.php
的文件(不再)。
如果 Wordpress 的测试套件和/或测试 Wordpress 插件的最佳实践提到/使用该文件,那么这将表明 Wordpress 依赖于过时版本的 PHPUnit。
您需要克隆 https://core.trac.wordpress.org/browser/trunk/tests/phpunit/includes/。您克隆的是旧的,不再更新。
您将看到 new bootstrap.php 中不再存在该行。