在我的 Behat 上下文中,我已包含 PHPUnit 的断言,如 the manual 中所述。 :
require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Framework/Assert/Functions.php';
但是,我现在使用 Symfony 的 PHPUnit bridge因此,我删除了显式安装的 PHPUnit,并使用桥引入的 PHPUnit。我需要这样做以避免描述的“多个版本”错误 here .
但是现在,我无法使用 PHPUnit!
PHP Warning: Uncaught exception 'Symfony\Component\Debug\Exception\ContextErrorException' with message 'Warning: require_once(PHPUnit/Autoload.php): failed to open stream: No such file or directory'
如何引用 PHPUnit 桥引入的 PHPUnit 实例?
最佳答案
对于 Symfony 4,这足以让它为我工作:
require_once(__DIR__ . '/../../vendor/bin/.phpunit/phpunit-5.7/vendor/autoload.php');
然而,这并不是一个很好的解决方案,因为如果您使用 PHP 7.2,PHPUnit Bridge 将安装 PHPUnit 6.3 而不是 5.7。
我尝试按如下方式更改composer.json:
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
},
"classmap": [
"vendor/bin/.phpunit"
]
},
它确实有效,但会破坏全新安装,因为在运行simple-phpunit
之前该文件夹不存在。
我怀疑这可以通过使用composer脚本来运行simple-phpunit
来解决,但是我对post-install-cmd
和pre-autoload进行了简短的实验-dump
让我无处可去。
关于php - 使用 Symfony 的 PHPUnit Bridge 时如何在 Behat 中使用 PHPUnit?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45371919/