My question is about unit testing. Suppose we have the following class:
class X
{
public function p1(){
$a = $this->p2();
}
public function p2(){
}
}
When writing the unit test method for p1, should I mock the p2 method?
I think that the test written for method p1 should only run and test method p1, not p2. But in order to understand that I have to make fun of class X and call the p1 method on this mock instance, as shown below.
$xMock = $this->getMockBuilder('\X')
->setMethods(array('p2'))
->getMock();
$xMock->expects($this->any())
->method('p2')
->will($this->returnValue($value));
$resultTobeAsserted = $xMock->p1();
, . , , SUT ( ).
, SUT, , SUT, , , , . , SUT, , .
? ?