Possible Duplicate:
PHPUnit Mock Objects and Static Methods
unit testing and Static methods
I'm using PHPUnit 3.6.10 and I can't seem to find a good example of mocking static methods in the documentation. Specifically, I have a class A with method a() -- call it A->a() -- which calls B::b() which I need to mock the return value of.
class A {
function a() {
return B::b();
}
}
class B {
static function b() {
return 5;
}
}
The test function for a() should look like below:
class A_Test {
function test_a() {
// what should the code look like here?
}
}
Since we're purely testing that A->a() returns B::b(), we're not concerned with how B::b() works, so we can mock the return value of B::b() (say, to return 'foo') and check that 'foo' is returned when we call A->a(). How can this be done?