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
http://www.phpunit.de/pocket_guide/index.en.php
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.
XAMPPLITE:
- Download here.
- Uzip to C:\xampplite (my suggestion it just makes it easier)
- run xampp-portcheck.exe to see if anything is using the required ports if so turn off the apps
- run xampp-control.exe – this gives you a nice gui app in your task bar to start and stop mysql and apache.
- 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
- open commandline Start->run->cmd
- type Path
- rightclick topleft corner of command window go to Edit -> select all
- repeat step 3 except choose copy
- Open notepad Start->run->notepad
- Paste
- delete everything BUT the folders listed
- turn off word wrap
- add “;C:\xampplite\php\” to the end of folder without quotes
- make sure everything is on one line
- go to beginning of line add “path ” without quotes and be sure to include the space
- copy that one line with everything on it. Should be LONG.
- paste in command line using step 3 with paste instead of select all
- 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.
- Right click my computer
- choose properties
- advanced tab
- Environment Variables button at the bottom
- Select Path in System Variables area
- hit edit
- add “;C:\xampplite\php\” to the end without quotes
- ok
- ok
- ok
- 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
- Start->run->cmd
- type “pear channel-discover pear.phpunit.de” without quotes
- hit enter
- type “pear install phpunit/PHPUnit” without quotes
- hit enter
Now you should have PHPUnit installed.
I just want to kind of sum up what we have done.
- Installed a portable way to start doing php development without installing anything that would be hard to remove.
- Added PHP folder to the path so we can install and run PHPUnit
- 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.