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
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?
I followed the instructions on the official PHPUnit page to install PHPUnit 6.
composer require --dev phpunit/phpunit ^6.0
However, If I go to the project folder and execute phpunit --version then I get PHPUnit 3.7.21 by Sebastian Bergmann..
Why is PHPUnit 3.7.21 installed instead of PHPUnit 6?
I suppose you have xampp installed? It comes with PHPUnit 3.x.x preinstalled with PEAR which strangely can not be uninstalled with pear uninstall. And since its config is in php root folder, that 3-ish version has priority when running phpunit command (even if you have phpunit installed globally) in CMD or PS. How to fix:
Go to xampp/php folder and delete two files phpunit (with no extension) and phpunit.bat. Usually it's enough to prevent older PHPUnit version from being run but let's be on the safer side:
Go to xampp/php/PEAR dir and delete two folders PHPUnit and PHPUnit2.
Go to Control Panel, then navigate System and Security->System and click "Advanced system settings" link on the left. This will open Advanced tab in System Properties window. Click "Environment Variables" button, then under System Variables select "Path" variable and click "Edit..." button. In the new window, click "New" button and type your path to vendor/bin folder (if you already installed PHPUnit for your project there will be phpunit.bat file). By default for xamp it looks like this: C:\xampp\htdocs\yourprojectname\vendor\bin.
Restart your Command Prompt (or PowerShell) window, then type phpunit --version to see the that it's PHPUnit 6.x.x now.
P.S. (If you want latest PHPUnit do not use ^6.0 in require string, since it will install v6.0.0, write it in composer.lock file that will never update PHPunit to the latest e.g. 6.2.1 version atm). Just use
composer require --dev phpunit/phpunit
to install the latest stable version for your project.
You run your global PHPUnit version which is installed in another folder. To get the installed version you have to go to the vendor/bin folder.
vendor/bin/phpunit --version
PHPUnit 6.0.8 by Sebastian Bergmann and contributors.
In newer versions you can run it with bin/phpunit there should be the executable. When you need another PHP-Version then define it before php74 bin/phpunit.
If you use XAMPP, why don't you update XAMPP version of global PHPUnit to desired.
1.
Read this post, which quickly explains what to do:
StackOverflow post
2.
You can get phar file for version you need here:
proper PHPUnit phar file
3.
Which version of PHPUnit you need depends on your PHP version and you can identify it here:
which phar file version you need
Just click on links: PHPUnit 9 - PHPUnit 8 - PHPUnit 7 - PHPUnit 6 - PHPUnit 5 - PHPUnit 4 and read description explaining which PHP version it works with.
I'm trying to setup a new Continuous Integration server that utilizes Phing and PHPUnit for automatically running test cases.
I've installed Phing with Pear:
pear channel-discover pear.phing.info
pear install phing/phing
I've installed PHPUnit using the new PHAR method:
wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit
Then I go to the directory where my build.xml file is located, rung phing and it looks like Phing has no idea where PHPUnit is.
[jenkins#leroy workspace]$ phing
Buildfile: /home/jenkins/.jenkins/jobs/Framework/workspace/build.xml
Framework > test:
[echo] Running Tests
Execution of target "test" failed for the following reason: /home/jenkins/.jenkins/jobs/Framework/workspace/build.xml:9:37: /home/jenkins/.jenkins/jobs/Framework/workspace/build.xml:9:37: PHPUnitTask requires PHPUnit to be installed
BUILD FAILED
/home/jenkins/.jenkins/jobs/Framework/workspace/build.xml:9:37:
/home/jenkins/.jenkins/jobs/Framework/workspace/build.xml:9:37: PHPUnitTask requires PHPUnit to be installed
Total time: 0.0764 seconds
[jenkins#leroy workspace]$
Checked the location of Phing and PHPUnit:
[jenkins#leroy workspace]$ which phing
/usr/bin/phing
[jenkins#leroy workspace]$ which phpunit
/usr/local/bin/phpunit
And, making sure PHP is new enough:
[jenkins#leroy workspace]$ php -v
PHP 5.3.3 (cli) (built: Dec 11 2013 03:29:57)
I'm doing all of this because we're replacing an older Jenkins server with this new one. Trying to use the newest software, but I can't figure out how to tell Phing where to find PHPUnit.
Thanks in advance for any help!
David
Seems like adding the pharlocation attribute to the phpunit task element, pointing to your local phpunit executable, does the job:
<phpunit haltonfailure="true" haltonerror="true"
bootstrap="./fw_init.php"
pharlocation="/usr/local/bin/phpunit">
<formatter type="plain" usefile="false" />
...
</phpunit>
It looks like there are some actual issues with phing and the latest 4.x versions of PHPUnit: http://www.phing.info/trac/ticket/1091.
So to fix the issue, I removed PHPUnit 4 and specified an older version:
pear install phpunit/PHPUnit-3.7.35
Phing and PHPUnit worked immediately at this point.
Here is a guy with exactly the same problem: How do I tell Phing where PHPUnit is installed?
His theory is that:
PHP version on this machine could be too old and not be able to handle PHAR archives
I can't comment if he is right or not, but that question received no replies from anyone other than the author
Maybe a silly remark, but do you have /usr/local/bin/phpunit in your PHP include path?
I get the same error when I remove the location of phpunit.phar from my include path.
Both Phing and PHPUnit were installed from pear on ubuntu 12.04.
PHPUnit is located at /usr/bin/phpunit and /usr/bin is on the unix path and also on the include_path in PHP.INI
How do I tell Phing where PHPUnit is installed?
webroot#gm3:~/med1/pub$ phing utest
Buildfile: /home/webroot/med1/pub/build.xml
myproject > utest:
[echo] Unittests PHPUnit...
Execution of target "utest" failed for the following reason: /home/webroot/med1/pub/build.xml:8:40: /home/webroot/med1/pub/build.xml:8:40: PHPUnitTask requires PHPUnit to be installed
BUILD FAILED
/home/webroot/med1/pub/build.xml:8:40: /home/webroot/med1/pub/build.xml:8:40: PHPUnitTask requires PHPUnit to be installed
Total time: 0.1148 seconds
Answering my own question, I think the PHP version on this machine could be too old and not be able to handle PHAR archives. Or maybe the PHAR configuration is broken. PHPUnit is installed as PHAR on this machine via PEAR.
A workaround for me was to not use <phpunit> but <exec> in the target, which worked:
<target name="test">
<exec command="phpunit --bootstrap tests/bootstrap.php --configuration tests/phpunit.xml">
...
I am not fixing this for now and I am expecting on newer machines it will work out of the box.