PHPUnit mock function? : <p>I have an interesting scenario in that I need a function to be defined in order to make tests for another function. The function I want to test looks something like this:</p>

<pre><code>if (function_exists('foo') &amp;&amp; ! function_exists('baz')) {
    /**
     * Baz function
     * 
     * @param integer $n
     * @return integer
     */
    function baz($n)
    {
        return foo() + $n;
    }
}
</code></pre>

<p>The reason I am checking for the existence of <code>foo</code> is because it may or may not be defined in a developer's project and the function <code>baz</code> relies on <code>foo</code>. Because of this, I only want <code>baz</code> to be defined if it can call <code>foo</code>. </p>

<p>The only problem is that so far it has been impossible to write tests for. I tried creating a bootstrap script in the PHPUnit configuration that would define a fake <code>foo</code> function and then require the Composer autoloader, but my main script still thinks <code>foo</code> is not defined. <code>foo</code> is not a Composer package and can not otherwise be required by my project. Obviously Mockery will not work for this either. My question is if anyone more experienced with PHPUnit has come across this issue and found a solution.</p>

<p>Thanks!</p>
