Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

php - How to configure PhpStorm to use symfony/phpunit-bridge

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

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

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.

I've installed PHPUnit using flex:

composer req phpunit

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

php bin/phpunit

But again I could not make PhpStorm use it.

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

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

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

question from:https://stackoverflow.com/questions/47569173/how-to-configure-phpstorm-to-use-symfony-phpunit-bridge

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

The location of the "phar" file is:

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

or in some cases:

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

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.

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">

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


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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...