TDD (test driven development) is the method …

… so I’d better install phpunit before writing any more lines of code now ;)
Better get used to do at home what I try do at work. Guess one can get used
to first write tests and then the implementation in the long term.
It’s not that bad an idea after all, just takes some getting used to.

For my part, I prefer to install phpunit inside of a project, so I can
move the whole project someplace else without bothering about setting up
phpunit again. All stuff again runs ins my VirtualBox Ubuntu VM on a Macbook Pro,
see earlier posts.

First install git with sudo apt-get install git
(Also a nice one: sudo apt-get install tree, shows directory structures.)

Create a new directory, cd in there and then check out phpunit like described
by

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
git clone git://github.com/sebastianbergmann/phpunit-story.git
git clone git://github.com/sebastianbergmann/php-invoker.git

Of all the stuff I got, I moved the folder named phpunit into my project’s library path,
had a look at what the phpunit autoloader likes to see

require_once ‘File/Iterator/Autoload.php’;
require_once ‘PHP/CodeCoverage/Autoload.php’;
require_once ‘PHP/Timer/Autoload.php’;
require_once ‘PHPUnit/Framework/MockObject/Autoload.php’;
require_once ‘Text/Template/Autoload.php’;

and copied the needed directories and files into my phpunit directory.

Then I wrote a shell script that currently only calls a php file called myunit.php that
includes my own autoloader and the standard phpunit.php.
script
mytest

As for tests, all my tests will extend a base test class that extends PHPUnit_Framework_TestCase, so I’ll have a common basis for all my tests. Comes in handy when e.g. adding custom assert functionality.

Here we go, calling

it works
confirms phpunit is now up and ready.

This entry was posted in howto, unit test strategies and tagged , , , , , . Bookmark the permalink.

Comments are closed.