look at test directory of zendframe source code. by the way , why not put all those code into your model? i mean developing your own model, so when do unit testing, just testing those model.
controller is just a place to call model and view, testing controller pretty much make no sense. unless your are author of ZF. regards. Don Dwiggins-2 wrote: > > Hello, I've just subscribed to the group, and am fairly new to PHP and > ZF (although I have a long history in software development on various > platforms). > > I'm in the middle of setting myself up to do TDD on a ZF-based app. > I've got Model testing in pretty good shape, but I've found myself a bit > stalled on testing my action controllers, and haven't found much via > Googling. > > I've come up with an approach that I think will work, but I thought I'd > run it by the knowledgeable folks here first. Also, my apologies if > there's a better place to post this -- redirection gratefully accepted. > > Here's my analysis of the situation (I'm using Smarty, but this could > apply to other rendering engines): > > The basic task of an action controller's action method (generic, > simplistic): > - Validate its inputs, if any (top-level, context-free validation) > - If any invalid, render an appropriate page with a helpful error > message > - Instantiate the model, pass inputs to the appropriate method, get > the result of the method > - If invalid, render an appropriate page with a helpful error message > - If valid, set view variables and render the appropriate page > (Note that all 3 "render" actions have the same form: set some variables > and render a template. I'd guess that this could be extended in the > same vein for more sophisticated rendering situations.) > > For unit testing, we don't really want to deal with the results of > rendering; we're testing the controller, not the view, and certainly not > the rendering engine. What we really want is to test the logic as > outlined above. > > Thus, here's a pattern for a "testable action method": > - For each action, pull out the "guts" into a separate method, which > returns a pair (template name, array of view variables) > - The action method just calls the guts method, sets the variables into > the view, and renders the template > - This allows a unit test to just call the guts method and make > assertions on the returned template and variables. > > Any good words appreciated, > -- > Don Dwiggins > Advanced Publishing Technology > > > -- View this message in context: http://www.nabble.com/Unit-testing-action-controllers-tp14287475s16154p14375846.html Sent from the Zend Framework mailing list archive at Nabble.com.
