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.
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.
I have PHP v 7.1.8 / PHPUnit v 6.4.4 successfully installed on my machine.
I dowloaded Nearsoft/php-selenium-client (https://github.com/Nearsoft/php-selenium-client).
After I started selenium standalone server, I tried to run demo Nearsoft Demo test phpunit Demo1.php, but it shows:
"Failed opening required '/var/www/html/sel/demo/../bootstrap.php'"
Not sure why, because it works just fine on my other machine that uses PHPUnit v 4+ amd PHP 5.6
I don't think you can run those demos with PHPUnit v6.4.4, since v6.0 PHPUnit has changed its Class names. Try running it with PHPUnit v5.7.
Take a look at the Release Notes for PHPUnit v6.0.
A quick look at demo1.php at line 10 exposes the "old" naming schema for PHPUnit.
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 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.
I have installed Netbeans together with PHPUnit and phpunit-skeleton-generator from homebrew. I can generate a testfile from the terminal by running phpunit-skelgen --test -- "UrlDecoder" classes/UrlDecoder.class.php, however Netbeans refuses when I right-click the file, select tools > Create tests.
This is the error I get:
And this is the output from the log:
"/usr/local/opt/php55/bin/php" "/usr/local/bin/phpunit-skelgen" "--ansi" "generate-test" "--bootstrap=/Users/paulp/Sites/fortv/tests/bootstrap.php" "UrlDecoder" "/Users/paulp/Sites/fortv/classes/UrlDecoder.class.php" "UrlDecoderTest" "/Users/paulp/Sites/fortv/tests/classes/UrlDecoder.classTest.php"
/usr/bin/env php -d allow_url_fopen=On -d detect_unicode=Off /usr/local/Cellar/phpunit-skeleton-generator/1.2.1/libexec/phpunit-skelgen-1.2.1.phar $*
Done.
Most tutorials and help I find online are for Netbeans 7.x, which makes things harder. I have tried with different bootstrap files and xml files, but no different result. The Output tells me nothing, and nothing happens.
I have googled this for a bit, but found nothing similar to my problem.
The only thing I notice is the --ansi part, which the skeleton generator documentation doesn't seem to offer.
My question: How can I get Netbeans to generate tests using phpunit skeleton generator?
I've installed phpunit on my Mac manually following the manual's instructions (it is pretty easy so you don't need brew script).
Then in Netbeans (8.0.2) preferences (PHP->Frameworks&Tools->PHPUnit) I have set up paths to sctipts.
In the project properties phpunit should be switched on (I know that's obvious). And then Tools->Create tests works just out-of-the-box. :)
However my first experience with phpunit installation was not so funny. So I can understand that users could be frustrated at the begining. It was because I have expected full automation through plugin installation and such things which not worked. That's why I describe full process (phpunit+netbeans on osx)on my [blog][1].