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
524 views
in Technique[技术] by (71.8m points)

php - PHPUnit via Composer and PhpStorm

I'm now trying for hours to setup PhpStorm for unit testing. Whatever I do, I get this

Process finished with exit code 1
Cannot find PHPUnit in include path ...

PHPUnit is (via command line) accessible from anywhere; I've set the correct include path and have added PHPUnit to the external libraries. No chance.

Is it possible at all or does it only work with installations via PEAR? I've worked through all related questions here, am on Mac and PHPUnit is running smoothly via CLI.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

@aderuwe's answer works but that config isn't scoped per project, it's for all projects. Since PHPStorm 6 (actually even EAP version PS-126.260) you can do the following:

  1. Go to File -> Settings -> PHP -> PHPUNIT.
  2. Select Use custom loader and then enter the autoload.php file from your projects vendor directory. This autoloader will autoload all the dependencies managed by Composer (including PHPUnit).
  3. Specify the default configuration file (this is usually phpunit.xml.dist from your project's app directory).

<code>PHP</code> -> <code>PHPUNIT</code>

That needs to be repeated per project, but the following needs to be done once.

You need to configure you defaults in PHPStorm correctly.

  1. Go to Run -> Edit Configurations... or just click the dropdown menu on the toolbar and select Edit Configurations....
  2. Go to Defaults -> PHPUnit
  3. Under Test Scope, select Defined in configuration file
  4. Make sure the Interpreter options textfield is empty
  5. Go to PHPUnit (above Defaults) and delete any entry under it (so that next time you a test on a particular file, etc. it'll set up a new one but using the new default).

<code>Edit Configurations...</code>


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

...