Asked  4 Months ago    Answers:  5   Viewed   63 times

I can't make PHPUnit 4.2.6 to work with PHPStorm 8.

PHPUnit is loaded as phar inside PHPStorm 8 settings.

Whenever i try to run unit test in PHPStorm i get this error:

Parse error: syntax error, unexpected '}' in /private/var/folders/qh/xjz1kr297v34pl6zy70_2rl00000gn/T/ide-phpunit.php(171) : eval()'d code on line 1

Call Stack:
0.0006     344584   1. {main}() /private/var/folders/qh/xjz1kr297v34pl6zy70_2rl00000gn/T/ide-phpunit.php:0
0.0007     344880   2. IDE_PHPUnit_Loader::init() /private/var/folders/qh/xjz1kr297v34pl6zy70_2rl00000gn/T/ide-phpunit.php:194


Warning: require_once(PHPUnit/Runner/Version.php): failed to open stream: No such file or directory in /private/var/folders/qh/xjz1kr297v34pl6zy70_2rl00000gn/T/ide-phpunit.php on line 49

When i looked into "ide-phpunit.php", i found that it tries to eval invalid code, because of invalid "substr" function usage.

So my question is, if someone managed to make PHPUnit 4.2.6 work with PHPStorm 8?

 Answers

46

PhpStorm generates special temporary "wrapping" to execute the tests and get the output in the form it understands better. In your case it's /private/var/folders/qh/xjz1kr297v34pl6zy70_2rl00000gn/T/ide-phpunit.php. Since the error says there is a syntax error, the first thing you should try is deleting it, on the next run the IDE will create the new one, hopefully without that problem.

If that doesn't help, as suggested in the comments, try downgrading the PHPUnit a few versions back, see if that helps. Alternatively try reinstalling the PhpStorm. If that doesn't work, you have better chances of finding an answer by reporting an issue to the dev team.

Tuesday, August 24, 2021
 
dream_variable
answered 4 Months ago
86

You should point to your vendor/autoload.php at Settings | PHP | PHPUnit when using PHPUnit via Composer.

This blog post has all the details (with pictures) to successfully configure IDE for such scenario: http://confluence.jetbrains.com/display/PhpStorm/PHPUnit+Installation+via+Composer+in+PhpStorm

Related usability ticket: http://youtrack.jetbrains.com/issue/WI-18388

P.S. The WI-18388 ticket is already fixed in v8.0

Wednesday, March 31, 2021
 
ojrac
answered 9 Months ago
42

Seems like your version installed globally does not meet minimal required version. Try to run

phpunit --version

I bet you will get some like 5.1. The php artisan dusk command uses different version which is located in vendor/bin/phpunit. So, you are also able to use this version instead. Just type:

vendor/bin/phpunit

instead of phpunit. You have to upgrade your global phpunit version if it works.

Wednesday, July 28, 2021
 
zIs
answered 5 Months ago
zIs
55

Youll notice its throwing the exception because its looking for a file named the same as the name you provided for your test suite. You need to actually write a test suite and then supply the name of that test suite to your config: http://www.phpunit.de/manual/3.2/en/organizing-test-suites.html

Monday, August 16, 2021
 
Alfred
answered 4 Months ago
59

In order to have PHAR archive indexed by IDE it has to have .phar extension (that's a requirement).

The easiest solution is to place phpunit.phar somewhere in your project (usually it would be PROJECT_ROOT/vendor/ folder).

If having local copy is not desired (for whatever reason; although composer and other similar kind of tools (bower/npm/etc) are primarily aimed at keeping dependency stuff/packages locally), you may use symbolic links: either create a symbolic link to that file locally (e.g. PROJECT_ROOT/phpunit.phar --> /usr/bin/phpunit) .. or place a full copy (or such symbolic link) in separate folder somewhere on your disk and then reference it via PhpStorm's Settings | PHP | Include Paths functionality.

Saturday, September 18, 2021
 
kensil
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share