我在配置 PhpStorm IDE 以使用 http://symfony.com/doc/current/components/phpunit_bridge.html 时遇到问题在使用 Symfony 3.3 时。
我决定只下载 phpunit.phar
到 bin
并使用它。
Symfony 3.4(和 Symfony 4)甚至没有开箱即用的 phpunit.xml.dist
,所以容易使用 phpunit.phar
存在问题.
我已经使用 flex 安装了 PHPUnit:
composer req phpunit
这创建了 phpunit.xml.dist,我可以通过以下方式从命令行运行测试:
php bin/phpunit
但我还是无法让 PhpStorm 使用它。
所以我下载了phpunit.phar
,它可以和提供的phpunit.xml.dist一起工作。
问题一: PhpStorm IDE 有没有办法使用 phpunit-bridge?
问题 2: Symfony 4(phpunit-bridge 或 vanilla phpunit.phar)的最佳实践是什么?
最佳答案
我通常做的是将 PHPStorm 上的 phpunit 测试框架指向由桥创建的 secret .phpunit
目录,例如:
“phar”文件的位置是:
bin/.phpunit/phpunit-(major).(minor)/phpunit
或者在某些情况下:
vendor/bin/.phpunit/phpunit-(major).(minor)/phpunit
在此之后,指定的 phpunit
可执行文件将在执行单元测试时被正确调用,但带有 --no-configuration
选项。这可能会导致自动加载问题(很多“找不到类”错误),因为 Composer 生成的自动加载器没有在任何地方指定。
要解决这个问题,您的项目中应该有一个 phpunit.xml
文件(无论如何这是常见的做法),您可以在其中指定 Composer 的自动加载器,如下所示:
<phpunit bootstrap="vendor/autoload.php">
然后应该在“默认配置文件”选项中指定此 phpunit.xml
,您就可以开始了。
关于使用 phpunit-bridge 的 phpstorm: 它可以作为自定义脚本,但您不会拥有漂亮的界面,也无法通过 PHPStorm 界面运行(和调试)特定测试。
关于php - 如何配置 PhpStorm 以使用 symfony/phpunit-bridge,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47569173/