I think the getData method should be part of a different class, separating data from logic. You could then pass a mock of that class to the TestClass instance as a dependency:
class TestClass
{
protected $repository;
public function __construct(TestRepository $repository) {
$this->repository = $repository;
}
public function getStuff()
{
$data = $this->repository->getData('Here');
$data2 = $this->repository->getData('There');
return $data . ' ' . $data2;
}
}
$repository = new TestRepositoryMock();
$testclass = new TestClass($repository);
The mock would have to implement a TestRepository interface. This is called dependency injection. E.g.:
interface TestRepository {
public function getData($whatever);
}
class TestRepositoryMock implements TestRepository {
public function getData($whatever) {
return "foo";
}
}
The advantage of using an interface and enforcing it in the TestClass constructor method is that an interface guarantees presence of certain methods that you define, like getData() above - whatever the implementation is, the method must be there.