PHP and TDD environment

by percent20 6/22/2007 1:11:00 PM

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:

  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 pear.phpunit.de” 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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

PHP | TDD | Programming

More on TDD "so much code"

by percent20 6/16/2007 1:09:00 PM

As you may know I have been trying to learn Test Driven Development. One thing that has always bugged me is how much code you write just to test something. To me it seems like you should spend most of your time writing your application not writing tests.

Well believe it or not writing a lot of test code is great.  As I am working through examples I have realized the more tests you write the stronger your code is. Reason I say this is because say in 2 years when you come back to your code and add or change something and 20 tests break, that you will probably never notice, you know that hey there is a potential bug.  When you fix that hey you have good code because all your tests pass and you are testing every part of your app not just a small bit of it.

So in the end I realize now that writing a A LOT of test code is a good thing because it leads to a better final product.

Currently rated 4.0 by 2 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

TDD | Programming

TDD (Test Driven Development) for beginners

by percent20 6/13/2007 1:07:00 PM

I have been wanting to learn TDD for a long time now and finally took the plunge and bought a book over it.  It is “Test Driven Development in Microsoft .NET.” I have only started the book, but already I understand TDD a little more than what I did before and most of that has to do with a few steps it laid out quite simply.  It is basically the process you go through when writing your code.

  1. Write the Test Code

  2. Compile the Test code (It should fail since you haven’t implemented anything yet)

  3. Implement just enough to compile

  4. Run the Test to see it fail

  5. Implement just enough to make it pass

  6. Run test to see it pass

  7. Refactor for clarity and eliminate duplication

  8. Repeat from top

For me I understood this, even though it was till hard to figure out, but what I didn’t “get” that was ok to have happen was step 2 which is in bold. It is ok for your compiled test to not compile.  The great thing about TDD is that it is one of those things you can do in almost any language I mean heck you can do TDD with PHP. PHPunit.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

TDD | Programming

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen


My Flare

AddThis Feed Button

National Blog Posting Month

Eagle Scout

I'm Test Driven

[Reserved for MVP status I want to earn]

View Buddy Lindsey's profile on LinkedIn

Twitter



Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in