有没有办法测试实例化方法中其他对象的类方法?
例如如下:
我想在不到达数据库的情况下进行测试,所以我想模仿它。
有没有办法在下面调用myDataStoreDB
静态方法之前模拟getCompetitionList
,以便我的测试可以通过?
public static function getCompetitionList($TipperID)
{
return self::getCompList($TipperID);
}
private static function getCompList($TipperID, $cache=false)
{
$cacheOps = Array('use' => $cache, 'expire' => 3600);
$view = 'dbo.getGroupsForTipper @TipperID = ?';
$parameters = Array(
0 => Array('value' => $TipperID, 'count' => 1, 'type' => myMsSql::PARAM_INT)
);
$ds = new myDataStoreDB('db', 'footy');
$rows = $ds->get($view, $parameters, $cacheOps);
$result = array();
$result[] = "--Select a Competition--";
foreach($rows as $row)
{
$result[$row['TippingGroupID']]['competitionName'] = $row['GroupName'];
$result[$row['TippingGroupID']]['competitionPassword'] = $row['TGPassword'];
$result[$row['TippingGroupID']]['competitionSportsName'] = $row['SportName'];
}
return $result;
}