我的問題是方法,我需要列出每次調用模擬對象,因爲我需要檢查他們。在SimpleTest文檔中我沒有發現任何有關此功能的信息。 :SPHP - SimpleTest的 - 列出每次調用模擬對象
也許還有另一種方式來測試我的代碼:
class Clean_Collection_Tree_NestedArrayParser {
protected $path = array();
protected $depth = -1;
/** @var Clean_Collection_Tree_MapTreeInterface */
protected $tree;
public function setBasePath(array $path) {
$this->path = $path;
}
public function setTree(Clean_Collection_Tree_MapTreeInterface $tree) {
$this->tree = $tree;
}
public function parse($subject) {
$this->parseArray($subject);
}
public function parseArray(array $array) {
++$this->depth;
foreach ($array as $key => $value) {
$this->path[$this->depth] = $key;
if (is_array($value)) {
$this->tree->put($this->path, new Clean_Collection_Map_Map());
$this->parseArray($value);
} else
$this->tree->put($this->path, $value);
}
if (!empty($array))
array_pop($this->path);
--$this->depth;
}
}
這是等待一個嵌套的數組從我打算創造一個Map對象樹解析器。我注入實際的樹setTree(Clean_Collection_Tree_MapTreeInterface $樹)和地圖樹界面:
interface Clean_Collection_Tree_MapTreeInterface extends Clean_Collection_CollectionInterface {
public function putAll(array $array);
public function put(array $path, $value);
public function get(array $path);
public function getAll(array $pathes);
public function removeAll(array $pathes);
public function remove(array $path);
public function contains(array $path);
}
解析器只使用認沽(數組$路徑,$值)方法。因此,列出每個調用的put方法都會告訴我解析器中出了什麼問題。 (如果SimpleMock不具備這個功能,我可以創造出我們實現接口我自己模仿的對象,我就可以了。)