本文介绍了如何配置PhpStorm以使用symfony/phpunit-bridge的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在配置PhpStorm IDE以使用 http://symfony.com/doc时遇到问题/current/components/phpunit_bridge.html ,同时使用Symfony 3.3.

I had problems with configuring PhpStorm IDE to use http://symfony.com/doc/current/components/phpunit_bridge.html while working with Symfony 3.3.

我决定只将phpunit.phar下载到bin并使用它.

I decided to just download phpunit.phar to bin and use it instead.

Symfony 3.4(和Symfony 4)甚至没有开箱即用的phpunit.xml.dist,因此容易使用phpunit.phar会出现问题.

Symfony 3.4 (and Symfony 4), does not even have phpunit.xml.dist out of the box, so there is a problem with using phpunit.phar easily.

我已经使用flex安装了PHPUnit:

I've installed PHPUnit using flex:

composer req phpunit

这创建了phpunit.xml.dist,我可以通过以下方式从命令行运行测试:

That created phpunit.xml.dist and I was able to run tests from command line by:

php bin/phpunit

但是我还是不能让PhpStorm使用它.

But again I could not make PhpStorm use it.

所以我下载了phpunit.phar,它可以与提供的phpunit.xml.dist一起使用.

So I downloaded phpunit.phar and it can work together with provided phpunit.xml.dist.

问题1: PhpStorm IDE是否可以使用phpunit-bridge?

Question 1: Is there any way for PhpStorm IDE to use phpunit-bridge?

问题2::Symfony 4(phpunit-bridge或vanilla phpunit.phar)的最佳做法是什么?

Question 2: What is the best practice for Symfony 4 (phpunit-bridge or vanilla phpunit.phar)?

推荐答案

我通常要做的是将我在PHPStorm上的phpunit测试框架指向由网桥创建的秘密.phpunit目录,例如:

What I usually do is point my phpunit testing framework on PHPStorm to the secret .phpunit directory which was created by the bridge, like:

"phar"文件的位置为:

The location of the "phar" file is:

bin/.phpunit/phpunit-(major).(minor)/phpunit

或在某些情况下:

vendor/bin/.phpunit/phpunit-(major).(minor)/phpunit


此后,执行单元测试时将正确调用指定的phpunit可执行文件,但带有--no-configuration选项.这可能会导致自动加载问题(很多找不到类"的错误),因为未在任何地方指定由Composer生成的自动加载器.


After this, the specified phpunit executable will be called correctly when exeuting unit-tests, but with a --no-configuration option. This can cause autoloading problems (a lot of "class not found" errors), because the autoloader generated by Composer is not specified anywhere.

要解决此问题,您的项目中应该有一个phpunit.xml文件(无论如何这都是惯例),在其中您指定Composer的自动加载器,如下所示:

To fix this, you should have a phpunit.xml file in your project (this is common practice anyway), in which you specify Composer's autoloader, something like this:

<phpunit bootstrap="vendor/autoload.php">

然后应在默认配置文件"选项中指定此phpunit.xml,您应该一切顺利.

This phpunit.xml should then be specified in the "Default configuration file" option and you should be good to go.

关于使用phpunit-bridge的phpstorm:可以将其作为自定义脚本,但是您将没有很好的界面,也无法通过PHPStorm界面运行(和调试)特定测试.

Regarding phpstorm using phpunit-bridge:It's possible as a custom script, but you won't have the nice interface and the possibility to run (and debug) specific tests via PHPStorm interface.

这篇关于如何配置PhpStorm以使用symfony/phpunit-bridge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:56
查看更多