如何设置PHPUnit PolyFill以在Mac上进行测试?

时间:2022-02-06 作者:StevieD

通过brew安装了带有PHP的mac开发机器。我正在尝试设置测试工具。我成功地搭建了测试脚手架wp cli并管理以获取bin/install-wp-tests.sh 做自己的事。

但我有个错误phpunit tests/test-sample.php:

Error: The PHPUnit Polyfills library is a requirement for running the WP test suite.
If you are trying to run plugin/theme integration tests, make sure the PHPUnit Polyfills library (https://github.com/Yoast/PHPUnit-Polyfills) is available and either load the autoload file of this library in your own test bootstrap before calling the WP Core test bootstrap file; or set the absolute path to the PHPUnit Polyfills library in a "WP_TESTS_PHPUNIT_POLYFILLS_PATH" constant to allow the WP Core bootstrap to load the Polyfills.

If you are trying to run the WP Core tests, make sure to set the "WP_RUN_CORE_TESTS" constant to 1 and run `composer update -W` before running the tests.
Once the dependencies are installed, you can run the tests using the Composer-installed version of PHPUnit or using a PHPUnit phar file, but the dependencies do need to be installed whichever way the tests are run.
所以我跑了composer require --dev yoast/phpunit-polyfills 并打开了一个新的终端窗口,但仍然得到相同的错误。跑步brew doctor 不显示任何与php或composer相关的内容。

我不太会用PHP开发,所以我不知道还有什么可以尝试的。

2 个回复
SO网友:StevieD

好吧,我在读一本过时的教程。用于运行测试的命令现在为:

vendor/bin/phpunit <path_to_file>

这个命令应该从wordpress的根目录运行。

SO网友:Scruffy Paws

我也遇到了同样的问题,通过将composer自动加载添加到测试/引导程序的顶部,解决了这个问题。php文件。。。

require \'vendor/autoload.php\';
之后我可以正常运行phpunit 命令

相关推荐

pingbacks testing

关于新wp安装(3.0.4)中PBs的功能测试,我有几个问题:发布帖子时是立即发送pingback,还是将其安排为cron作业?如果后者正确,作业多久运行一次,我可以手动触发它吗?除了将“尝试通知文章中链接到的任何博客”设置为“开”,当然还有帖子内容中指向另一个博客的链接之外,还有其他关于发送PBs的术语吗?(例如,发件人的帖子应该是公开的而不是私有的吗?博客应该是非私有的吗?)出站链接应该放在帖子内容中,还是可以放在帖子的自定义字段中,以便发送PB?如果我的博客中没有发送或接收PBs,那么调试和检测问题