As best I can tell, the 'mockBuilder' function is exactly what I want, and based on other examples, should work.
HowAm I missing something? How can I stub out the global craft() object?
###under test: <?php
namespace Craft;
class JobsVariable
{
// Grab all Jobss
public function jobs()
{
return craft();
}
}
###test file: <?php
namespace Craft;
require_once '/home/stephen/Projects/EllationWebsite/www'www/craftcms/plugins/jobs/variables/JobsVariable.php';
class JobsVariableTest extends \PHPUnit_Framework_TestCase
{
public function testJobs()
{
$craft = $this->getMockBuilder('\\Craft')
->disableOriginalConstructor()
->setMethods(array('craft'))
->getMock();
$craft->method('craft')->willReturn('xxx');
$jobs = new \Craft\JobsVariable();
$this->assertEquals('xxx', $jobs->jobs());
}
}
###output: PHP Fatal error: Call to undefined function Craft\craft()