Stub out the global craft() object for PHPUnit tests As best I can tell, the 'mockBuilder' function is exactly what I want, and based on other examples, should work.  

Am I missing something?
How can I stub out the global craft() object?

under test:

&lt;?php

namespace Craft;


class JobsVariable
{

     // Grab all Jobss
     public function jobs()
      {
            return craft();
      }
 }


test file:

    &lt;?php

    namespace Craft;

    require_once 'www/craftcms/plugins/jobs/variables/JobsVariable.php';


    class JobsVariableTest extends \PHPUnit_Framework_TestCase
    {



        public function testJobs()
        {


            $craft = $this-&gt;getMockBuilder('\\Craft')
                -&gt;disableOriginalConstructor()
                -&gt;setMethods(array('craft'))
                -&gt;getMock();


            $craft-&gt;method('craft')-&gt;willReturn('xxx');


            $jobs = new \Craft\JobsVariable();
            $this-&gt;assertEquals('xxx', $jobs-&gt;jobs());

        }
    }


output:

PHP Fatal error:  Call to undefined function Craft\craft()
Whew...this seems to do the trick!
Hopefully this is an appropriate way to handle things.

I created a new Craft class file in the 'tests' dir.  There I can stub out any \Craft\craft() methods the class under test depends on.

stub class \tests\Craft

&lt;?php

class Craft {

    public function __construct()
    {
    }

    public function jobs()
    {
        return 'xxx';
    }
    public function getJobs()
    {
        return 'xxx';
    }

    public function craft()
    {
        return $this;
    }
}


in the test class

&lt;?php

namespace Craft;

require_once '/www/craftcms/plugins/jobs/variables/JobsVariable.php';
require_once '/www/craftcms/tests/Craft.php';


class JobsVariableTest extends \PHPUnit_Framework_TestCase
{

    public function testJobs()
    {
        $jobs = new \Craft\JobsVariable();
        $this-&gt;assertEquals('xxx', $jobs-&gt;jobs());

    }
}
function craft()
{
    return new \Craft;
}


allows me to test this function...

public function jobs()
{
    return craft()-&gt;jobs();
}