Hey there,
So I downloaded the source package for this and started to try to understand it. The best way for me to do this was to go through the execution path of the Hangman example cleaning up the source and writing tests for each class that I came across.
So far everything makes a lot of sense, unfortunately I have gotten hopelessly bogged down in trying to test the ApplicationController::execute method. The problem is that I am trying to Mock as much as possible of the things that I have already written tests for. That way I can skip a lot of their internals and more importantly use them as auditors.
The real issue boils down to the static use of the Handle::resolve method. This function takes a Handle object and an array of arguments for the class contructor. The problem is that I cannot mock the Handle object so that I can apply a setReturnValue to the resolve method. Since I can't do that, then there is no way for me to mock/audit State objects that are managed by the Application Controller. The whole point of the Application Controller being that when I pass in a certain set of parameters I get a definite state object that I run the execute method on.
Here is the offending code block from the Input Controller:
PHP Code:
/**
* @access public
* @param Locator $locator
* @return boolean
* @todo Handle::isHandle check (~ln 158) is redundant, performed again by resolve method
*/
public function execute($locator) {
$locator->set('Controller', $this);
foreach (array_keys($this->Handlers) as $key) {
$MethodName = 'execute';
$CurrentHandler = $this->Handlers[$key];
if (Handle::isHandle($CurrentHandler)) {
if (strlen($CurrentHandler->getMethodName()) > 0)
$MethodName = $CurrentHandler->getMethodName();
$Handler = Handle::resolve($CurrentHandler, array(0=>$locator));
} else {
$Handler = $CurrentHandler;
} // end if
$Handler->$MethodName($locator);
} // end foreach
return $this->Error;
} // end execute
Was there a reason to design the Handler that way? It is hard to find anything about it in the thread. To be honest, the Handle object itself feels unweildy and took me a while to even figure out what the point of it was.
Later,
Matthew.
Bookmarks