mercredi 26 juillet 2017

"Resource access layer" below REST

I have some legacy code a RESTful web application - it happens to be in the php SLIM framework - where the routes are typcially written in this form:

$app->get('/timesheet/edit/:timesheetid', function($timesheetId) use($app)   {
    // route implementation
    // .
    // .
    // .
    $app->render('template.html', array('obj' => stuff));
});

I am preparing the code for testing with phpunit/dbunit, and I want to test the routes: but I don't want to test by firing the SLIM route itself, I want to wrap the route implementations into functions whose job it is to convert the array of GET or POST parameters into another object or objects for rendering and then I will assert the the objects against literal objects in the test cases, or data from XML files or whatever works best in each case.

Why not test the routes as shown here Test a REST get request? Because I don't want to test the whole response which as I understand will contain all the HTML, I just want to assertEquals the 'stuff' array.

My question is this: how should such functions be organized - not just global functions, because they are discouraged, but are they a good fit for objects? Is there such a thing as a resource layer? I wanted to ask the collective before I go and re-invent the wheel - I have a feeling that there is a pseudo-design-pattern to cover this situation!

Aucun commentaire:

Enregistrer un commentaire