Testing a procedure script...

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Testing a procedure script...

Post by nielsene »

I have a rather short, procedural script. I've been bad and wrote it without using TDD, but I'm not really sure how to test a pure procedure script.

This is the very front-end of my Front Controller. It needs to be a top level script for legacy reasons.

Code: Select all

require_once('classes/controllers/FrontDispatcher.inc');

$dispatcher= new FrontDispatcher();
$dispatcher->addModule("SlidingDoorsAdmin","|register/[-A-Za-z0-9_]*/admin|");
$view = $dispatcher->dispatch($_SERVER["REQUEST_URI"]);
if (0!=$view) {
  echo $view;
  exit;
  }
/** Fall back to the legacy, pure scripts */
require_once($_SERVER["REQUEST_URI"]);
exit;
Its simple, so I can almost say "I don't need no unit-tests" and trust that it'll get well exercised via the integration/web-tests. But that feels a little bit like laziness/lack of creativity. And its problably still buggy as it hasn't been written with TDD and it hasn't been hooked up to the webserver for ithose integration tests....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

could use output buffering and include(), or file_get_contents() (if agent headers aren't important), or curl if headers are important.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

d'oh. Why didn't I think of that. Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I over complicate ideas at times too. :) It happens far too often.. :lol:
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Re: Testing a procedure script...

Post by McGruff »

nielsene wrote:Its simple, so I can almost say "I don't need no unit-tests" and trust that it'll get well exercised via the integration/web-tests. But that feels a little bit like laziness/lack of creativity.
I think you could indeed just leave it to the web test. There's very little to go wrong there.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Re: Testing a procedure script...

Post by nielsene »

McGruff wrote:
nielsene wrote:Its simple, so I can almost say "I don't need no unit-tests" and trust that it'll get well exercised via the integration/web-tests. But that feels a little bit like laziness/lack of creativity.
I think you could indeed just leave it to the web test. There's very little to go wrong there.
OK, I think I will then. Especially as I couldn't get the output buffering to work (because unless I can mock the dispatcher it just turns into an integration test anyways as it has to run through the whole system.)
Post Reply