PHP - Is There a Portable Version of PHPunit

PHP - Is there a portable version of PHPUnit?

Portable phpunit (taken from https://github.com/sebastianbergmann/phpunit "Using PHPUnit From a Git Checkout" )

For phpunit 3.5:

git clone git://github.com/sebastianbergmann/phpunit.git
git clone git://github.com/sebastianbergmann/dbunit.git
git clone git://github.com/sebastianbergmann/php-file-iterator.git
git clone git://github.com/sebastianbergmann/php-text-template.git
git clone git://github.com/sebastianbergmann/php-code-coverage.git
git clone git://github.com/sebastianbergmann/php-token-stream.git
git clone git://github.com/sebastianbergmann/php-timer.git
git clone git://github.com/sebastianbergmann/phpunit-mock-objects.git
git clone git://github.com/sebastianbergmann/phpunit-selenium.git

cd phpunit && git checkout 3.5 && cd ..
cd dbunit && git checkout 1.0 && cd ..
cd php-file-iterator && git checkout 1.2 && cd ..
cd php-code-coverage && git checkout 1.0 && cd ..
cd php-token-stream && git checkout 1.0 && cd ..
cd phpunit-mock-objects && git checkout 1.0 && cd ..
cd phpunit-selenium && git checkout 1.0 && cd ..

and then put every single of those folders into your include path.

It will not work if you leave out any one of those packages.

If you don't want to always have them in the include path here is a phpunit.sh executable

phpunit.sh

x='./checkoutDir/';

php -d include_path=".:$x/phpunit/:$x/dbunit/:$x/php-code-coverage/:$x/php-file-iterator/:$x/php-text-template/:$x/php-timer/:$x/php-token-stream/:$x/phpunit-mock-objects/:$x/phpunit-selenium/:$x/phpunit-story/:/usr/share/php/" $x/phpunit/phpunit.php $*

How can I make a portable PHPUnit?

This question's accepted answer would be a perfect solution for you especially if you are using GIT, if you are using something else, it shouldn't be too hard to modify....

Rkulla's answer is good except quite a few comments for the blog post does state that Sebastian does not address the dependency issue for the required modules

PHPUNIT without installation

The readme on PHPUnit's github repository has instructions for this. Scroll down to Using PHPUnit From a Git Checkout for a list of commands you can copy-n-paste into your shell.

One thing to make clear to your coworkers is that while writing tests in addition to your regular code may seem like more work up front, well-written tests will save you time over the long run as you fix bugs and add features. They also give you the confidence to make more drastic changes as necessary whereas you might normally consider rewriting the project from scratch.

Can I package PHPUnit as a phar?

Current status:

Work on a phpunit.phar has started in the phpunit repo but the generated phar is not stable and not feature complete.

If it gets there there will be official releases



Original answer:

If you can I'll give you 500 rep, a 100 Bucks and my first born.. well no.. just the first two.

To be serious:

I've nagged the creator of PHPUnit about this topic on at least 3 conferences now and well.. it doesn't seem like it's possible.

There are a couple of issues with that. First off PHPUnit spawns new php processes for test isolation. The problem with this is that a phar can't tell which php executable called it. So if you start phpunit with a custom compiled version it would use the "default" php installed to spawn the isolated tests.

Secondly as far as i know and have been told it's not possible to put static files like images and css in a phar. Which makes generating code coverage a lot harder. That would require some work on that part.

There are other issues i can't recall exactly recall right having to do with xDebug being able to provide code coverage for phars (and phpunit relying on not generating overage for it's own code and so) and others things.

There once was a phar but from my understanding that just doesn't work out with the current state of phpunit and never really worked completly.


I'm not saying it can't be done just that various people already have given up on creating a phpunit.phar including the guy how develops it. (That is just my impression, i of course can't speak for Sebastian here and might be completely wrong, take this as a little disclaimer)

Putting PHPUnit into SVN

You don't have to build a .phar to do so!

For my company I maintain a svnd version of PHPUnit. It's not the recommended way of using it but it works without much issues!

Follow the "using from a git checkout" instructions on the phpunit github site. You then need to put those files into your php include path and it works.

My suggestion would be to create a custom phpunit.sh that modifies the include path and then calls the original phpunit.sh passing along all arguments. It's a little bit of work but it works quite well and it is a hell of a lot easier than creating a phar archive :)

NetBeans + multiple php versions + phpUnit without PEAR

I managed to install phpunit after 1.5 year, so this is the up to date answer now.

I simply used composer with these settings: PHPUnit via Composer and PhpStorm, and it worked!

I use phpstorm now instead of netbeans, in that I can configure different php interpreter and phpunit settings for each project. I did not follow the changes in netbeans, maybe in the new versions it's capable of that too, but version 7.1 was not enough for that.

SimpleTest vs PHPunit

This question is quite dated but as it is still getting traffic and answers I though I state my point here again even so I already did it on some other (newer) questions.

I'm really really baffled that SimpleTest still is considered an alternative to phpunit. Maybe i'm just misinformed but as far as I've seen:

  • PHPUnit is the standard; most frameworks use it (like Zend Framework (1&2), Cake, Agavi, even Symfony is dropping their own Framework in Symfony 2 for phpunit).
  • PHPUnit is integrated in every PHP IDE (Eclipse, Netbeans, Zend Stuide, PHPStorm) and works nicely.
  • Simpletest has an eclipse extension for PHP 5.1 (a.k.a. old) and nothing else.
  • PHPUnit works fine with every continuous integration server since it outputs all standard log files for code coverage and test reports.
  • Simpletest does not. While this is not a big problem to start with it will bite you big time once you stop "just testing" and start developing software (Yes that statement is provocative :) Don't take it too seriously).
  • PHPUnit is actively maintained, stable and works great for every codebase, every scenario and every way you want to write your tests.
  • (Subjective) PHPUnit provides much nicer code coverage reports than Simpletest
  • With PHPUnit you also get these reports inside your IDE (Netbeans, Eclipse, ...)
  • Also there are a couple of suggestings for a web interface to phpunit tests.

I've yet to see any argument in favor of SimpleTest. It's not even simpler to install since PHPUnit is available via pear:

pear channel-discover pear.phpunit.de
pear install phpunit/PHPUnit

and the "first test" looks pretty much the same.

As of PHPUnit 3.7 it's even easier to install it by just using the PHAR Archive

wget http://pear.phpunit.de/get/phpunit.phar
chmod +x phpunit-3.7.6.phar

or for windows just downloading the phar and running:

php phpunit-.phar

or when using the supported composer install ways like

"require-dev": {
"phpunit/phpunit": "3.7.*"
}

to your composer.json.


For everything you want to test PHPUnit will have a solution and you will be able to find help pretty much anywhere (SO, #phpunit irc channel on freenode, pretty much every php developer ;) )

Please correct me if I've stated something wrong or forgot something :)

Overview of PHP Testing tools

Video: http://conference.phpnw.org.uk/phpnw11/schedule/sebastian-bergmann/

Slides: http://www.slideshare.net/sebastian_bergmann/the-php-testers-toolbox-osi-days-2011

It mentions stuff like Atoum which calls its self: "A simple, modern and intuitive unit testing framework for PHP!"



Full disclosure

I've originally written this answer Jan. 2011 where I had no affiliation with any PHP Testing project. Since then I became a contributor to PHPUnit.

What ever happened to PHPUnit's Database Extension?

I solved this by installing db unit manually. I downloaded it from here. Then I replaced the incomplete Extensions/Database folder with the one from the download.

Cannot find PHPUnit in include path phpstorm

Just encountered this problem myself.

I'm unsure why it is unable to find PHPUnit in the include path (despite the fact that it is there, albeit in all lowercase).

I got around this by changing my IntelliJ Preferences for PHPUnit (under PHP --> PHPUnit). I changed the PHPUnit library settings to Use custom loader and then specified the path to the phpunit executable. On my mac, that was /usr/local/Cellar/php54/5.4.26/bin/phpunit.

UPDATE:

I just discovered that pear now installs PHPUnit as a phar named phpunit. It previously installed the PHPUnit source, which was really nice for reference and code completion in PHPStorm. I think that this is the reason things aren't working any longer with PHPStorm, because it's expecting a php executable and not a php archive.

So, I'm moving away from using pear to install PHPUnit, and I'm using composer instead. This bundles PHPUnit directly as a dependency of my project, which makes it more portable than a system dependency. You'll need to add vendor/phpunit/phpunit as a PHP include path in your PHPStorm preferences. This will serve two purposes:

  1. PHPStorm can find the phpunit executable now
  2. PHPStorm will index all the PHPUnit classes now, so you'll get auto-complete. Yay!

To do this, go to Languages and Frameworks in the PhpStorm settings.
If you click on PHP, on the right you have your include paths



Related Topics



Leave a reply



Submit