【发布时间】:2014-04-01 11:57:06
【问题描述】:
我想编写一个测试用例来确保函数调用设置一个数组;但是,我找不到比较两个数组以确保两个空数组不相等的方法。
// 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并检查是否相等。
标签: php arrays testing tdd phpunit