Hyperf 单元测试运行报错:PHP Warning: pcntl_fork() has been disabled for security reasons in... 作者: Chuwen 时间: 2023-06-12 分类: PHP ## 背景 因为 Hyperf 使用协程运行,故原本的 PHPUnit 的方式就无法运行,需要使用框架自带的 `co-phpunit` 二进制程序运行 ## 配置 PHPUnit 如果你原本就配置了 PHPUnit,建议删掉重新配置  然后再按照如下步骤进行配置: 1. **PHPUnit 库**选择 *phpunit.phar* 路径 2. *phpunit.phar* 输入框选择你项目路径下的 `vendor/bin/co-phpunit` 文件 3. **测试运行程序** - *默认配置文件* 勾选,选择项目路径下的 `phpunit.xml` 文件 4. 最后点击“确定”保存即可  ## 调整 PHPUnit "运行/调试配置模版"  在第 4 步输入例如:`--prepend /Users/chuwen/wwwroot/xxxxx-hyperf/test/bootstrap.php`,其中 *xxxxx-hyperf* 是项目名,要改成你的项目名  移除在配置前的配置  然后再运行一下就可以了  标签: Hyperf