Suppose there are several public methods in the class under test:
class Sample { function method1() { return [1,2,3]; } function method2($id) { return (in_array($id, $this->method1())); } } method2 depends on the results of method1 .
I create tests for the first method, in which I drive it with different sets of initial values. Then I take the tests for the second method, in which I emulate the results of the first:
$mock = $this->getMockBuilder(Sample::class) ->disableOriginalConstructor() ->setMethods(['method1']) ->getMock(); $mock->method('method1')->willReturn([1,2,3]); $this->assertTrue($mock->method2(1)); And now the question:
Sometime in the distant future, as a result of refactoring, I decide that the result of the first method should be displayed as [1=>true,2=>true,3=>true] . With the tests of the first method, everything is in order, they will not pass, and I will immediately solve this problem. But the tests of the second receive the emulated source data, which is no longer relevant.
What is the opportunity / strategy to protect yourself from this situation?