Page 1 of 1

[SOLVED]Testing without a return value?

Posted: Mon Feb 19, 2007 6:07 am
by Jenk
Sorry if this is old topic; searching proved uneventful.

I have this method:

Code: Select all

public function execute ($route = null)
{
    do
    {
        $route = $this->getRouter()->execute($route);
    } while (!is_null($route));
}
Which, if not obvious, is part of my Front Controller (inspired by Zend..)
How would one test that with SimpleTest?
I've got a mock (actor) object for the router, as that's not yet implemented, with the below spec:

Code: Select all

Mock::generate('Router');
$router = new MockRouter;
$router->setReturnValueAt(0, 'execute', $router);
$router->setReturnValueAt(1, 'execute', null);
FrontController::setRouter($route);
Should I mock the FrontController::execute() method to include a return value or even an assert/expect?

(p.s. the calls you see in my examples and text are not static, merely demonstrated as such for illustrative purposes)

Posted: Mon Feb 19, 2007 10:36 am
by Jenk
Sorted :)

Code: Select all

public function TestExecute ()
    {
        $this->_mockRoute = new MockRouter();
        $this->_mockRoute->setReturnValueAt(0, 'execute', new MockRouter);
        $this->_mockRoute->setReturnValueAt(1, 'execute', null);
        $this->_mockRoute->expectAt(0, 'execute', array(null));
        $this->_mockRoute->expectAt(1, 'execute', array(new MockRouter));
        $this->_mockRoute->expectCallCount('execute', 2);
        $this->_front->setRouter($this->_mockRoute);
        $this->_front->execute();
    }