I have this method that I would like to unit test. Since it's creating the Sql object inside the method, I can't mock it.
Initially I thought about making Sql be an instance property except that I'd have to reset it every time I use it in other methods and this will most likely lead to hard to debug errors (I don't want the possibility to get a "dirty" Sql object on other subsequent calls to its getter if at all avoidable).
What's the common pattern for testing these kinds of methods?
public function getConfigFromDb()
{
if (!is_null($this->configInDb)) {
return $this->configInDb;
}
$sql = new Sql($this->getSlaveDbAdapter());
$select = $sql->select()
->from('mytable');
$statement = $sql->prepareStatementForSqlObject($select);
$results = $statement->execute();
$results->buffer();
$this->configInDb = $return;
return $results;
}