PHPUnit path can not be resolved
Hi,
I'm getting started with PHP and PhpStorm. Running php scripts and debugging works fine for me.
But I just can't get PHPUnit to work. I've used the standard PEAR installation instructions.
(I'm using Mac Snow Leopard)
I got my PHPUnit installation in /usr/lib/php/PHPUnit.
Like the PhpStorm help suggests I've added /usr/lib/php/PEAR to as content root. But I get the error
message:
Error: (E_WARNING) require_once(PHPUnit/Framework.php): failed to open stream: No such file or directory
PHPUnit is not configured properly
when trying to generate a test class for an existing class.
So I added /usr/lib/php/PHPUnit as content root. I can see the PHPUnit/Framework.php in my project structure.
When I open it, it says
Path 'PHPUnit' not found for every "require" line.
I tryed adding the directories to my include_path in php.ini still no effect.
What am I doing wrong? Thanks for any help.
regards
Fred
Please sign in to leave a comment.
Can anybody just tell me how the PATHs work in PhpStorm?
this is unresolvable:
require 'PHPUnit/Framework/Exception.php';
if I fully qualify the path like this:
require '/usr/lib/php/PHPUnit/Framework/Exception.php';
its shown as resolvable.
But this is not really an option as I don't want to alter all PHPUnit scripts.
The PHPUnit path is known in the unix terminal.
I've added every possible combination as content root to the system...
I've added all paths as include_paths in php.ini
Still PhpStorm does not know the path. So is this a bug or is there some other place where PhpStorm gets it's PATH information?
Ok now thats weird. Fiddling around some more with php.ini and adding removing /usr/lib/php to/from include_path... it finally
just worked. I'm pretty sure I had the same setup not work yesterday. Anyway issue solved for now.
I would still appreciate a quick explanation. The help suggest just adding the PEAR directory to content root to enable PHPUnit
support.
In my case it was impossible until the php.ini include_path was updated.
This is 100% correct -- by doing so you have enabled support for PHPUnit code completion and so that PhpStorm can validate / evaluate your code with its own parser.However, when you run PHPUnit test within PhpStorm IDE it just creates a custom file with test instructions/configuration and then runs it in a hidden console using your default (I guess) PHP installation (it will be something like "php run_this_test.php"). This is where your "include_path" kicks in -- as it should contain the path to your PEAR installation. If it's not using default PHP installation (in case you have more than 1 on your system), then (I guess, again) it should use the one specified in "File -> Settings -> PHP".Hello Fredrick,
Just to complement Andriy's explanation. When you execute PHPUnit tests or generate PHPUnit test class, PhpStorm runs a script with PHP executable taken from File | Settings | PHP | Php home setting, so you need PHPUnit installation to be added to include_path.
Actually, there's no need to add PHPUnit installation as a Content root to get it's classes resolved. Instead, once you configured include_path correctly you open File | Settings | PHP page and click 'Update include paths' button.
Anyway, the confusion you found should be fixed: http://youtrack.jetbrains.net/issue/WI-3035.
Regards,
Kirill
PS Thanks, Andriy! :)
If you have problems with xampp and PHPUnit, this might help: http://www.dimitrioskouzisloukas.com/blog/index.php?blog=2&title=xampp_php_pear_and_jetbrains_intellij_id
Dimitrious,
Thanks for sharing!
I've done everything mentioned, but still get the same error in the original post.
What I find weid is that it says its looking for Framework.php, but that file doesn't exist. It's a folder.
phpStorm 2.0.1
Pear 1.9.2
Okay, so to be fair I feel I must admit that the fault was all mine. I did not have PHPUnit installed. I was using the pear.phpunit.de channel, but was not paying close attention. It was informing me that PHPUnit was dependent upon xml_rpc2, which I later found to be dependent upon the curl extension.
The following steps got me where I needed to be, plus those explained earlier in this post.
1. Enable the curl extension
2. pear install --alldeps pear/XML_RPC2
3. pear install --alldeps phpunit/PHPUnit
FYI
-This is a WAMP server.
-phpunit/PHPUnit is from the channel pear.phpunit.de NOT pear.phpunit.net
Hope this helps someone else.
Mauricia, Thanks for sharing!