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.
Related
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.
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
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.
I need to install PHPUnit for a web dev project on my Ubuntu box, but am having serious issues. Using suggestions from various sources, I've installed via pear and tried the following:
Currently, phpunit --version returns
PHPUnit 3.7.20 by Sebastian Bergman
when in /usr/share but throws errors everywhere else.
My include path is
include_path = ".:/usr/share/php:/usr/share/php/PEAR:/usr/share/php/File/Iterator"
I've tried different variations ranging from simple /usr/share/php to the full string above. PEAR is in all caps since that is the folder it is in.
Executing with a test case results in
PHP Warning: require_once(File/Iterator/Autoload.php): failed to open stream:
No such file or directory in /usr/share/php/PHPUnit/Autoload.php on line 64
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpunit:0
PHP 2. require() /usr/bin/phpunit:43
PHP Fatal error: require_once(): Failed opening required
'File/Iterator/Autoload.php'(include_path='/usr/share/php/libzend-framework-php')
in /usr/share/php/PHPUnit/Autoload.php on line 64
pear list -c phpunit returns
Installed packages, channel pear.phpunit.de:
============================================
Package Version State
File_Iterator 1.3.3 stable
PHPUnit 3.7.20 stable
PHPUnit_MockObject 1.2.3 stable
PHP_CodeCoverage 1.2.10 stable
PHP_Invoker 1.1.2 stable
PHP_Timer 1.0.3 stable
PHP_TokenStream 1.1.5 stable
Text_Template 1.1.2 stable
I've confirmed that Autoload.php exist at both php/PHPUnit/ and php/File/Iterator/
My loaded php.ini file is at `/etc/php5/cli.php.ini1 as verified by
php --info | grep "onfiguration"
Any other suggestions would be appreciated.
Search for a file on your computer that is called Autoload.php and is in a file structure like this:
../File/Iterator/Autoload.php
Now open the file that throws the error (/usr/share/php/PHPUnit/Autoload.php in your case) and include a set_include_path statement that points to the absolute path of that file.
You seem to have a very similar problem to what I experienced on Mac OSX. For more information look at this very similar question. If all of this doesn't help, try to install with Composer, which I have heard doesn't have this issue.
For recent projects, I'm using Composer to install PHPUnit and the other related tools. It's quite easy:
## ... rest of the composer.json file
# "php -f composer.phar update --dev" to install
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
I also then have a shell script to actually run the PHPUnit command-line tool from the ./vendor/bin/ directory where a link to the locally installed script is installed.
Like Alister's answer, relying on Composer,
but I prefer to deploy the updated PHPUnit globally across my projects with:
composer.phar global require "phpunit/phpunit=dev-master"
That way, when I am at the root dir of my Symfony project, I can just run
~/.composer/vendor/bin/phpunit -c app/ -v --filter testFireNotifications |tee phpunit.log
That last bit with --filter was to run something selectively (actually, more for fast web automation via crontab, than testing...)
Even on a current Ubuntu 14.04.2 server, the repo is stuck with an outdated PHPUnit 3.7.28 "stable", so I sidestep the OS-provided one with this custom install that won't conflict (I haven't put ~/.composer/vendor/bin in my PATH).
When trying to create a build using propel-gen (propel v 1.4) I get:
[phing] Error reading project file
[wrapped: Unable to open
/path/to/project/build-propel.xml for
reading: ]
I can't find a reference to this file in the propel documentation.
Definitely a problem with the latest phing.
You should try :
$ pear uninstall -n phing/phing
$ pear install phing/phing-2.3.3
I realised that it was looking for files which are located in the propel/generator directory, but was using the current working directory as the base directory (I have propel-gen symlinked to /usr/bin so I can run it from anywhere).
The (kind of crappy) solution is just to cd into the propel/generator directory and run the build from there, so it uses that directory as the base path.
What version of Phing are your using? (Run phing -v to find out). Phing 2.4.x, the latest version, seems to break backwards compatibility, but it works with Phing 2.3.x, so try to downgrade to that version for now.