PHP and TDD Environment

As many of you know I am taking a dive into doing TDD. Well since I have a side job doing php development I am going to try and do TDD with php using PHPUnit. To do that we need to set up our development environment to even do that.

First, I want to show you to a PHPUnit e-book (UPDATE: I Haven’t found a good enough replacement for this)

Now there is a lot of good information in there, but frankly I find it a pain to figure out what they saying sometimes so I will give kind of excerpts of what to do in more layman’s terms.

Lets get started setting up the environment. Since I am a proponent of portable development, basically I don’t have a server running all the time and I can turn off sql and the web server when I am not using
it. I suggest using XAMPPLITE. So here is a bit of how to use and install it.


  1. Download here.
  2. Uzip to C:\xampplite (my suggestion it just makes it easier)
  3. run xampp-portcheck.exe to see if anything is using the required ports if so turn off the apps
  4. run xampp-control.exe – this gives you a nice gui app in your task bar to start and stop mysql and apache.
  5. all source code for web development goes in the C:\xampplite\htdocs\

You should now have XAMPPLITE installed and ready to go. Our next step is to add the php folder to our path. I’ll tell you how to do it my way, BUT I want to stress if you do it MY way you can hurt your system and it is not my fault.

Add php folder to path (way 1) – note don’t need to do this unless you want to install and use PHPUnit for TDD

  1. open commandline Start->run->cmd
  2. type Path
  3. rightclick topleft corner of command window go to Edit -> select all
  4. repeat step 3 except choose copy
  5. Open notepad Start->run->notepad
  6. Paste
  7. delete everything BUT the folders listed
  8. turn off word wrap
  9. add “;C:\xampplite\php\” to the end of folder without quotes
  10. make sure everything is on one line
  11. go to beginning of line add “path ” without quotes and be sure to include the space
  12. copy that one line with everything on it. Should be LONG.
  13. paste in command line using step 3 with paste instead of select all
  14. hit enter

Now that should work it is how I usually do it. I’ll give you another “safer” way. Just remember I am not responsible if you mess up your computer.

Add php folder to path (way 2) – This is the safer method I recommend this one to everyone.

  1. Right click my computer
  2. choose properties
  3. advanced tab
  4. Environment Variables button at the bottom
  5. Select Path in System Variables area
  6. hit edit
  7. add “;C:\xampplite\php\” to the end without quotes
  8. ok
  9. ok
  10. ok
  11. now reboot computer

Now that you have the folder added next we need to install PHPUnit. This is much easier. Basically is just to command line commands. Find out more here.

Install PHPUnit

  1. Start->run->cmd
  2. type “pear channel-discover” without quotes
  3. hit enter
  4. type “pear install phpunit/PHPUnit” without quotes
  5. hit enter

Now you should have PHPUnit installed.

I just want to kind of sum up what we have done.

  1. Installed a portable way to start doing php development without installing anything that would be hard to remove.
  2. Added PHP folder to the path so we can install and run PHPUnit
  3. Installed PHPUnit

The greatest part about all this is no extra process are running when you aren’t using them. Later I will go over actually writing tests with php and using php unit. This was just a lets get started type thing so you can do at least PHP development. Later I’ll come back and go over more of what TDD is and when how and why you want to use it.

Related Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>