Page 1 of 1

Testing a procedure script...

Posted: Sun Aug 28, 2005 10:58 pm
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....

Posted: Sun Aug 28, 2005 11:07 pm
by feyd
could use output buffering and include(), or file_get_contents() (if agent headers aren't important), or curl if headers are important.

Posted: Sun Aug 28, 2005 11:10 pm
by nielsene
d'oh. Why didn't I think of that. Thanks.

Posted: Sun Aug 28, 2005 11:23 pm
by feyd
I over complicate ideas at times too. :) It happens far too often.. :lol:

Re: Testing a procedure script...

Posted: Mon Aug 29, 2005 5:12 am
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.

Re: Testing a procedure script...

Posted: Mon Aug 29, 2005 8:59 am
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.)