PHP Testing?

Discussion in 'OT Technology' started by Sexual Vanilla, Apr 12, 2007.

  1. Sexual Vanilla

    Sexual Vanilla New Member

    Joined:
    May 23, 2005
    Messages:
    6,305
    Likes Received:
    0
    Location:
    South Carolina
    So I'm wrapping up a web programming project in PHP/MySQL when my professor comes to me and tells me that I need to have some sort of "external" form testing for all input being sent to my scripts. I'm assuming she means something similar to JUnit as seen in Java. I have like 4 days to do this, but I have no clue where to start.

    I've looked at PHPUnit as well as PHPSimpleTest, but it appears these are more for hardcore programming projects, not simple testing for invalid characters, null, etc in HTML forms. Any advice?
     
  2. gnp

    gnp New Member

    Joined:
    Mar 11, 2007
    Messages:
    280
    Likes Received:
    0
    no, Unit Testing is part of test driven development. You write tests, use something like JUnit to run the tests (in my case i use NUnit), then when the tests fail you write just enough code to make them pass and no more...the tests become the internal (programmer facing specs for the project). This is one of the facets of xp.

    what she is asking you to do is some validation on the incoming data, etc. Prevent sql injection, data type mismatches and shit like that.

    edit (helps when i read the entire post)

    ok, so basically send all data through a validation script...thats all she wants, although you should try to validate with js on the client side and again on the server.
     
  3. Sexual Vanilla

    Sexual Vanilla New Member

    Joined:
    May 23, 2005
    Messages:
    6,305
    Likes Received:
    0
    Location:
    South Carolina
    That's what I figured...I had hoped I wouldn't have to learn and implement PHPUnit or SimpleTest as time is running short. So basically you're saying I can create a script that will accept all input from the user and validate (or invalidate) it from that?
     
  4. gnp

    gnp New Member

    Joined:
    Mar 11, 2007
    Messages:
    280
    Likes Received:
    0
    idk what you are working on and i don't work in php but...

    create an abstract interface with a single method like "validateFormData" and have it accept a form or http context object (whatever the php equiv is), possibly returning a bool. Then create a concrete class that implements the interface and provides implementation. Next have all your scripts that will be processing form data create an instance of IValidator and pass it the current form; continue if the validation succeeds and if not idk show goatse.

    that would be a start, you can make it fancier or extend it by creating several classes of validators that all implement the IValidator interface, then use a factory method to create the right one based on whatever logic you see fit.
     

Share This Page