+1  A: 

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
Thanks!How should this class be written when we had created the test first?
Skelton
@Skelton In any way that does not hardcode the dependency. That would be something along the lines of Option 1 or 2 then
Gordon
Thx! I did added the complete solution to my post.
Skelton