Short answer: you cant, because you hardcoded the dependency into the method.
There is three workarounds for this:
1) Make the used classname configurable, so you can do something like:
$className = $this->userModelClassName;
$userModel = new $className();
or 2) Add a third param to the method signature that allows passing in the dependency
public function isValid($email, $context = NULL, $userModel = NULL)
{
if($userModel === NULL)
{
$userModel = new Application_Model_User();
}
// ...
}
or 3) use set_new_overload()
as described in
Gordon
2010-08-27 08:19:41