我想编写一个测试用例以确保函数调用设置了一个数组;然而,我没有找到一种方法来比较两个数组,以确保两个空数组不相等。在PHP中比较(空)数组
// code to be tested (simplified)
$foo = null;
function setFoo($input) {
global $foo;
$foo = array(); // BUG!!! The correct line would be: $foo = $input;
}
// test code
// given
$input = array();
// when
setFoo($input);
// then
if ($foo !== $input) {
// this block is not executed because "array() === array()" => true
throw new Exception('you have a bug');
}
因此:什么是比较两个PHP数组并确保它们是不同的实例(不管内容是否相同)的正确方法?
我不知道如何检查两个数组是否是相同的实例,但一个选项可能是后来更改'$ input'并检查是否相等。 – Jim