I've been trying to setup up PHPUnit in PhpStorm 8.0.1 with no luck. I downloaded phpunit.phar and set the path to the phar in PhpStorm's settings as well as a phpunit configuration file, but when I try to run a test it fails with the following output:
/usr/bin/php /tmp/ide-phpunit.php --no-configuration MyTest /project/MyTest.php
Testing started at 9:31 PM ...
Process finished with exit code 1
Cannot find PHPUnit in include path (.:/usr/share/pear)
I'm no expert, but it doesn't seem like it's using the phpunit.phar as the tests run fine when I run
$ phpunit
in the terminal.
I solved similar problem (not showing hints of PHPUnit_Fremwork_TestCase class) by this:
Download desired version of php.
Then in phpstorm -> File/Settings../Languages & Frameworks/PHP tab click "..." button next to "Interpreter" and set path to downloaded PHP.
Next, add the Include path which will point to location where you have phpunit.phar file
Then in phpstorm -> File/Settings../Languages & Frameworks/PHP/PHPUnit tab chose radio button "Load from include path" and optionaly set bootstrap and config file.
Now you should not get:
Cannot find PHPUnit in include path (.:/usr/share/pear)
Related
I have a WP project with structure:
public_html/ // wp-project stuff like wp-config, etc)
tests/ // phpunit test classes
When running in bash shell:
$phpunit /tests
all the the tests pass just fine
But Jenkins is failing on on one of the plugins classes (which is namespaced) not found.
Not sure why this is happening (or how to fix) ?
When running a test using PHPStorm it loads a configuration from an other project.
/usr/bin/php /private/var/folders/jv/rch25xnj6y3cl_yf4s6qq64m0000gn/T/ide-phpunit.php --bootstrap /Users/reneterstegen/Sites/www.domain1.com/app/bootstrap.php.cache --configuration /Users/reneterstegen/Sites/www.one-of-my-other-projects.com/app/phpunit.xml.dist --filter "/::itLoadsTheForm( .*)?$/" Stegeman\Bundle\SearchBundle\Tests\SearchControllerTest /Users/reneterstegen/Sites/www.domain1.com/src/Stegeman/Bundle/SearchBundle/Tests/SearchControllerTest.php
This causes a fatal:
Class 'JMS\SerializerBundle\JMSSerializerBundle' not found in /Users/reneterstegen/Sites/www.one-of-my-other-projects.com/app/AppKernel.php on line 21
This makes sense since the project I am testing is nog using this bundle.
I've already set the default configuration file and default bootstrap file settings in the PHPUnit section in preferences.
Question: Can somebody tell me how to change the configuration used by phpunit in PHPStorm?
Can somebody tell me how to change the configuration used by phpunit in PHPStorm?
You can always specify custom ("alternative") config file per Run/Debug Configuration -- it will be used instead of Default one that you have set in Preferences.
https://confluence.jetbrains.com/display/PhpStorm/PHPUnit+support+in+PhpStorm#PHPUnitsupportinPhpStorm-3.CreatingaRunConfiguration
Here you have to tick the "Use alternative configuration file" and specify full path to it (either manually or via "..." button). NOTE: if you click on a button next to "..." one it will allow you to edit paths to Default config files (the ones from Preferences).
Please note that if you have defined your bootstrap file in that Default section as well .. it will also be used and AFAIK you cannot override it. It will be better if you provide bootstrap file in actual config file.
I am trying to install composer on windows (symfony 2 project). The problem is that I always get some strage errors - that a couple of files are not in the allowed path.
I've tried a couple of methods to install compsoer:
Downloading raw composer.phar file, throwing it into the symfony2 root folder and running composer installation command. It gives me an error that usr/.../composer/.htaccess is not within the allowed path
php -r "path" gives similar results as above, but with more "not in the allowed path" errors
Windows installer - it throws an error that the installer couldn't execute php.exe file, no idea why.
What's wrong?
Adjust open_basedir in your php.ini to include the path to your project and the other paths that composer tries to load from/write to. The variable accepts multiple paths separated by : (unix) or ; (windows).
open_basedir = "/home/sites/yoursites/:/tmp/:/"
... or remove the restriction completely from php.ini.
; remove open_basedir completely ...
; <nothing here>
; ... comment it out like this ...
; open_basedir = "..."
; ... or set it to an empty value like this ...
open_basedir =
You can find the location of the correct php.ini for the CLI sapi with:
php --ini
First, you should make sure that the path of php.exe is in your ENV (Environment variable);
Second, if composer's windows installer can't install, just try to use "Run With Administrator Permission", and if it also does not work, just comment me your error.
I try to understand PHPUnit tests in Netbeans. I set correct phpunit.bat path and the phpunit-skelgen.bat file as well.
When I try to create test for some file, using the netbeans option such us "create test file" I get correct directory structure, but the files are placed incorrectly.
Next, following the tutorials from web I set the test folder (to jobeet/tests), the phpunit bootstrap to jobeet\app\bootstrap.php.cache and the xml configuration file to jobeet\app\phpunit.xml.dist
Please see the screenshots below
I would like to run some unit Tests individually with PHPUnit, but I have certain classes separated from the Tests, since I am using the symfony framework, and I group the Tests and the Classes in different folders.
I would like to run the Tests individually like this:
php phpunit.phar MyTest.php
The problem is that the test file uses the classes from the controllers, and phpunit doesnt seem to be able to import the needed classes for the test.
This is not a problem to run all the tests together, thanks to phpunit.xml but when I want to run them individualy, its a problem.
How could I fix this?
You have to point phpunit where you have your phpunit.xml config file (because it must know the autoloader for example). If you have default symfony 2 structure it will be in app directory, so just run your test like that (I assume that you are in project root path):
phpunit -c app/ --filter="concreteTestPattern" src/Acme/DemoBundle/Tests/MyTest.php
edit:
Above will run all tests which names match to the pattern: /.*concreteTestPattern.*/
You would use the --filter argument in your PHPUnit command string. This will only run tests that match the pattern given. If you pass only the complete name of the test that you want run, phpunit should only run that test.
If you have a data provider associated with the test and only want to run one test case, you can also filter that by using --filter <testName>::<testcase name>
PHPUnit can be set to execute using a configuration file.
In our Symfony2 project this file is located at app/phpunit.xml.dist.
As this file is suffixed with .dist, you need to copy its contents into a file called app/phpunit.xml.
If you are using a VCS such as Git, you should add the new app/phpunit.xml file to the VCS ignore list.
You will also notice the configuration is specifying the bootstrap file located at app/bootstrap.php.cache. This file is used by PHPUnit to get the testing environment setup.
We can execute this test by running the following command from the root directory of the project. The -c option specifies that PHPUnit should load its configuration from the app directory.
$ phpunit -c app