I'm trying to test my files in PHP but I keep getting this error message:
"/Users/Nakazai/XAMPP/bin/php" "/Applications/NetBeans/phpunit-old.phar" "--colors" "--log-junit" "/var/folders/ll/twrzpc8j77d3npwp2m_137mm0000gn/T/nb-phpunit-log.xml" "/Applications/NetBeans/NetBeans 8.0.2.app/Contents/Resources/NetBeans/php/phpunit/NetBeansSuite.php" "--run=/Applications/MAMP/htdocs/bank1/Tests"
PHPUnit 4.8.21 by Sebastian Bergmann and contributors.
unrecognized option --run
Done.
Appreciate your help, folks!
PHPUnit do not has command --run which you used in last argument. Check your NetBeans configuration, maybe your IDE try to run PHPUnit older than 4 (actually is version 5) and you have installed newer version.
Related
I'm trying to run unit tests using PHPUnit in a CI/CD setup. The problem is that I'm getting the following error:
PHPUnit testing framework version 6 or greater is required when running on PHP 7.0 or greater. Run the command 'composer run-script drupal-phpunit-upgrade' in order to fix this.
But I have the correct version of PHPUnit with PHP 7.2.14. I tried running the suggested command but nothing works.
vendor/bin/phpunit --version
PHPUnit 6.5.13 by Sebastian Bergmann and contributors.
Hope someone with experience has an idea.
Regards.
Probably version of PHP for cli and cgi could be different. As you are running phpunit from console, try also run php -v to find out which version is used for console.
Also, you error message suggest you:
Run the command 'composer run-script drupal-phpunit-upgrade' in order to fix this.
Probably that will fix your issue
I found out what the issue was... It seems that there was a previous installation of PHPUnit, with a version of 4.5, somewhere on the server outside my Drupal project. I manually updated that version to and now it works.
Within a Drupal 8 project I try to run PHPUnit tests with the following command:
cd htdocs/core
../../vendor/bin/phpunit --testsuite=unit
I get the following error:
PHPUnit testing framework version 6 or greater is required when running on PHP 7.2 or greater. Run the command 'composer run-script drupal-phpunit-upgrade' in order to fix this.
When I run the following command:
composer run-script drupal-phpunit-upgrade
I get the following error:
[InvalidArgumentException]
Script "drupal-phpunit-upgrade" is not defined in this package
run-script [--timeout TIMEOUT] [--dev] [--no-dev] [-l|--list] [--] [<script>] [<args>]...
I check my PHP version with php --version and get the following info:
PHP 7.2.6-1+ubuntu17.10.1+deb.sury.org+1 (cli)
I check my PHPUnit version with phpunit --version and get the following info:
PHPUnit 6.5.8 by Sebastian Bergmann and contributors.
My PHPUnit testing version meets the requirement on PHP 7.2 in my OS. I don't know why I get that error related to the PHPUnit testing version. And when I run the composer run-script as shown in the error, I get another error which is the dead end way for me. How can I fix this? or where should I focus on?
In older versions of phpunit you could turn off code coverage reporting with the flag: --no-coverage. This allowed our suite to run much faster on CI environments, etc. In the current stable version (5.4) I don't see this option in the docs. What's the current way to turn off code coverage?
The --no-coverage option might be missing from the documentation but it works for me.
It's still in PHPUnit's code as well, see Command.php:66 and Command.php:523.
I've created a tiny test project with 1 class and 1 test to try it out. I've enabled code coverage output (HTML) in the <logging> section of phpunit.xml.
Running phpunit without the option:
$ phpunit
PHPUnit 5.4.6 by Sebastian Bergmann and contributors.
[removed irrelevant output]
OK (1 test, 1 assertion)
Generating code coverage report in HTML format ... done
Code coverage is being generated and outputted.
Running phpunit with the option:
$ phpunit --no-coverage
PHPUnit 5.4.6 by Sebastian Bergmann and contributors.
[removed irrelevant output]
OK (1 test, 1 assertion)
No code coverage generation. (The command ran faster too.)
As given in https://phpunit.de/manual/current/en/installation.html#installation.phar.verification, the steps to globally install the PHAR are:
$ wget https://phar.phpunit.de/phpunit.phar
$ chmod +x phpunit.phar
$ sudo mv phpunit.phar /usr/local/bin/phpunit
$ phpunit --version
PHPUnit x.y.z by Sebastian Bergmann and contributors.
I followed the above, but with the URL for the older version, i.e. https://phar.phpunit.de/phpunit-old.phar (because our PHP version is older). I ran the following commands then -
$ chmod +x phpunit-old.phar
$ sudo mv phpunit-old.phar /usr/local/bin/phpunit
Note - My PHP version is 5.3.29. and the Old Stable Release section in phpunit.de says PHPUnit 4.8 is supported on PHP 5.3, PHP 5.4, PHP 5.5, and PHP 5.6.
Looks fine till here. But, running phpunit --version gives -
PHP Fatal error: require(): Cannot redeclare class phpunit_extensions_database_constraint_tableisequal in /usr/local/bin/phpunit on line 109
zend_mm_heap corrupted
So, instead of moving the .phar to /usr/local/bin/ (in the step 3), I was managing so far by running this -
$ php phpunit-old.phar –-version
I was also able to run my unit test cases in this way -
php /home/sandeepan/phpunit-old.phar /var/cake_1.2.0.6311-beta/app/webroot/openx/lib/ad_agencies/unittests/Admarvel_generic_network_test.php
But, now I need to integrate phpunit with phing. I would like to use the basic utilities provided by PHPUnitTask of phing. So, I guess it needs phpunit phar to be globally installed.
I tried my luck by writing the following -
<phpunit haltonfailure="true" haltonerror="true"
pharlocation="/home/sandeepan/phpunit-old">
<formatter type="plain" usefile="false" />
<batchtest>
<fileset dir="${dir.scratchpad}/${dir.subdir}/unittests">
<include name="**/*_test.php"/>
</fileset>
</batchtest>
</phpunit>
But I get this error -
BUILD FAILED
...
: PHPUnitTask requires PHPUnit to be installed
Update
With reference to stackoverflow.com/a/23410676/351903, I tried with this older version of Phpunit, i.e. PHPUnit-3.7.35. Now, phpunit --version command works. But I still have no success using the PHPUnitTask of Phing. Still getting PHPUnitTask requires PHPUnit to be installed error.
Update 2
The solution which worked for me was using PHPUnit 3.7.35. It seems there is some compatibility issue of phing with PHPUnit 4.8.
I have just downloaded the old PHPUnit file you provided from the phpunit.de website, and have applied succesfully the commands you wrote. Running phpunit worked like a charm in my case.
Perhaps there is an incompatibility between your PHP version and the PHPUnit version you downloaded?
I cannot reproduce the issue you describe:
$ wget https://phar.phpunit.de/phpunit-old.phar
--2016-04-07 09:47:35-- https://phar.phpunit.de/phpunit-old.phar
Resolving phar.phpunit.de (phar.phpunit.de)... 188.94.27.25
Connecting to phar.phpunit.de (phar.phpunit.de)|188.94.27.25|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://phar.phpunit.de/phpunit-4.8.24.phar [following]
--2016-04-07 09:47:35-- https://phar.phpunit.de/phpunit-4.8.24.phar
Reusing existing connection to phar.phpunit.de:443.
HTTP request sent, awaiting response... 200 OK
Length: 3086772 (2.9M) [application/octet-stream]
Saving to: ‘phpunit-old.phar’
phpunit-old.phar 100%[=====================================================================================================================================>] 2.94M 3.97MB/s in 0.7s
2016-04-07 09:47:36 (3.97 MB/s) - ‘phpunit-old.phar’ saved [3086772/3086772]
$ php phpunit-old.phar --version
PHPUnit 4.8.24 by Sebastian Bergmann and contributors.
The solution which worked for me was using PHPUnit 3.7.35. It seems there is some compatibility issue of phing with PHPUnit 4.8.
Source - Phing can't see PHPUnit
I'm trying PHPUnit to work on my Netbeans 8.0.2. I'm using Ubuntu 14.04 LTS.
I followed this documentation:
https://netbeans.org/kb/docs/php/phpunit.html
I've installed phpunit and it's skeleton generator, and followed through till step 5. But when I'm trying to test it, the test won't run. It always says "No tests executed." "Perhaps error ocurred, verify in Output Window."
I've checked the output window and it shows this:
"/usr/bin/php" "/usr/local/bin/phpunit" "--colors" "--log-junit" "/tmp/nb-phpunit-log.xml" "/usr/local/netbeans-8.0.2/php/phpunit/NetBeansSuite.php" "--run=/var/www/html/calculator/tests/calculatorTest.php"
PHPUnit 4.8.5 by Sebastian Bergmann and contributors.
unrecognized option --run
Done.
Do I miss something?
Go back to PHPUnit 4.7, if you can.
It seems that this is a problem in NetBeans 8.0.2. I found two bugs in their Bugzilla system related to the --run parameter.
Bug 254221
Bug 254276
It has been fixed, but is only available in the nightly builds, since 8.0.2 is the most current release.