McGruff's points in the OOP vs. Procedural threads finally convinced me to try TDD. I think I'm addicted to seeing that green bar now. I don't know how I lived without TDD... but anyway.
I believe I've done a relatively good job keeping tasks seperate, in their own objects, writing tests, and then code to pass the tests, but I'm stuck on my front controller on my Lyrics website project (which I've been working on for several weeks now... I didn't steal your idea, vchris.
That it's procedural is one problem, but also that I'm not sure how I could test the page itself is another. I plan to write tests for all of the components in the page before writing the cpmponents themselves.
An example URL which would be passed into this script is example.com/artist_name/album_name/song_name/. My OrganizeResourcesRequest uses several classes for validating / formatting... so $request->artist() would return 'artist name'. Then my RetrieveArtist object would "SELECT ... WHERE LOWER(name) = $name". Makes for nice URLs.
Code: Select all
<?PHP
# Lyrics / includes / assembler.php
# Nathaniel Jones
# September 25th, 2005
include('common.php');
$request =& new OrganizeResourcesRequest($_GET['url']); //unit tested, works great
$overall =& new TemplateFile('overall.html');
$failure =& new TemplateFile('404.html'); // will be an extended class which sets 404 header...
// AssembleArtist, AssembleAlbum, AssembleSong extend AssembleModule
if ( $request->albumRequested() == false )
{
$artist = new AssembleArtist($request->artist());
$artist->moduleFailureRecovery($failure);
$overall->assign('titles', $artist->assembledTitles());
$overall->assign('content', $artist->assembledContent());
}
else if ( $request->songRequested() == false )
{
$album = new AssembleAlbum($request->artist(), $request->album());
$album->moduleFailureRecovery($failure);
$overall->assign('titles', $album->assembledTitles());
$overall->assign('content', $album->assembledContent());
}
else
{
$song = new AssembleSong($request->artist(), $request->album(), $request->song());
$song->moduleFailureRecovery($failure);
$overall->assign('titles', $song->assembledTitles());
$overall->assign('content', $song->assembledContent());
}
$overall->display();
exit;
?>- Nathaniel