Phpunit showing difft version when run - phpunit

when I run /usr/bin/phpunit testfile.php, the first line it outputs says PHPUnit 4.7.7. However, when I run /usr/bin/phpunit --version, it outputs PHPUnit 4.5.0. Why is phpunit giving me different versions? which one is correct? How do I find out what's going on here?

Related

Why is phpunit still masking test output?

I have some tests that are passing locally but failing in CI. I'm trying to troubleshoot using the command php ./vendor/bin/phpunit -d memory_limit=512m --debug --verbose however no amount of var_dump(), throwing exceptions or anything will give me any debug output. I know it's the output buffer hiding the output. I've looked at phpunit's --help and don't see anymore flags I could possibly add that will show me the output. Looking at the TestCase source code I'm not seeing a clear way to turn off this buffering. I'm also confused why locally I do see the debug output...

phpunit coverage-unit doesn't generate reports

Hi everybody,
i have some problem with phpunit coverage html component.
I installed correctly components and launch command:
vendor/bin/phpunit --coverage-html tests
Tests works correctly, but no html reports generated. Attached the terminal result.
The classic "Generating code coverage report in HTML format ... done" doesn't appear.
Can you help me?
Thanks
The error message reads "No code coverage driver is available". Your PHP environment is missing Xdebug or PCOV.

PHPStorm 8 + PHPUnit 4.2.6 Error

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?
Here is how to "unhack" the IDE to run with phpnunit.phar (4x+) nicely on windows and linux!
Download phpunit.phar under php, set your phar location from the IDE -> settings -> phpunit and phar location. THEN CLOSE IDE
Find where your plugin files are, for php on windows this would be :\Program Files (x86)\JetBrains\PhpStorm 8.0.3\plugins\php\lib.
Open php.jar with winrar and open scripts/phpunit.php.
Comment out all PHPUnit/… require statements, so autoloader can do its job instead of using hardcoded values.
Go to public static function init() method.
Find the if section with a comment at the end says “awful hack”, screenshot.
Remove all the amateur hacky stuff and replace it with this, screenshot.
Save the file, Winrar will prompt you to save the archive, SAVE that one too.
Run IDE And Run your tests, coverage. Enjoy!
Hope this helps some of you out there. I will post the information to their forums as well.
I got the exact same error, and fixed it like this:
Installed phpunit using: composer global require phpunit/phpunit
Goto phpstorm settings: PHPUnit
Select "Use custom autoloader"
On Windows: C:\Users\[username]\AppData\Roaming\Composer\vendor\autoload.php
On Linux: /home/[username]/.composer/vendor/autoload.php
Or point it to the autoloader of your composer project
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.

PHPStorm & PHPUnit - Unable to attach test reporter to test framework

When running "Debug" in phpstorm on my project, for some reason it's started having this weird problem where phpstorm doesn't really pick up the test results, even though phpunit is not throwing an error.
Phpunit will generate a report in the phpstorm console that looks something like this:
[37;41m[2KFAILURES!
[0m[37;41m[2KTests: 3, Assertions: 6, Failures: 1.
[0m[2KGenerating code coverage report in Clover XML format ... done
Process finished with exit code 1
I'm guessing phpstorm can't interpret these results? It was working before and it would be nice to have full integration again.
Any help would be great
It looks like phpunit colorizes its output. Could that be the problem? Make sure not to run it with --colors

How to run PHPUnit Test from another directory

I have a very straightforward PHPUnit test in c:\kim\test\HelloTest.php on a Windows PC. I can execute it from within the c:\kim\test directory with the command:
phpunit HelloTest
The problem is that I can't execute it from any other directory.
As far as I know I should be able to execute this from the c:\kim directory with:
phpunit test
Also, I would have thought the following syntax would work too:
phpunit c:\kim\test
But I don't get any response from the command. Simply a blank line and then I am returned to the cursor.
I am trying to get unit tests working properly with Netbeans and I think I need to solve this problem first. Perhaps it has something to do with paths? Any ideas?
I spent quite a while trying to sort this out, per the comments above. Also tried reinstalling PHPUnit. In the end I ran up a new server, installed XAMPP, and all works fine.
If any help.
I am using makegood extension for eclipse which handle phpunit test execution with one click.
Maybe you can find similar extension for Netbeans or switch to eclipse

Resources