我的问题是方法,我需要列出每次调用模拟对象,因为我需要检查他们。在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不具备这个功能,我可以创造出我们实现接口我自己模仿的对象,我就可以了。)