Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I package PHPUnit as a phar?

Tags:

php

phpunit

phar

I would like to package PHPUnit and various other test dependencies into a phar and put that into svn. This way I can run phpunit on any client machine without needing pear. Can this be done?

like image 799
james Avatar asked Sep 06 '11 17:09

james


People also ask

How do I know if PHPUnit is installed on Windows?

To verify PHPUnit has been installed type phpunit --version in command prompt. You should get something like PHPUnit x.y.z by Sebastian Bergmann and contributors .

What is the use of PHPUnit?

PHPUnit is a unit testing framework for the PHP programming language. It is an instance of the xUnit architecture for unit testing frameworks that originated with SUnit and became popular with JUnit.


2 Answers

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 :)

like image 70
edorian Avatar answered Sep 22 '22 10:09

edorian


From the new PHPUnit page:

We distribute a PHP Archive (PHAR) that contains everything you need in order to use PHPUnit. Simply download it from here, make it executable, and put it into your $PATH, for instance......

like image 35
Pacerier Avatar answered Sep 19 '22 10:09

Pacerier