[英]SimpleTest: assertEquals and PHP types
考慮以下代碼:
<?php
class Foo extends UnitTestCase {
public function testFoo() {
$foo = new Foo();
$this->assertEqual('2, 3', $foo->bar(3));
}
}
?>
<?php
class Foo {
public function bar() {
return 2;
}
}
?>
'2,3'== $ foo-> bar(2),因為PHP允許這樣做。 此測試通過! 但這在某些情況下是錯誤的('2,3'字符串不同於2整數。
EqualExpectation類的SimpleTest測試方法:
function test($compare) {
return (($this->value == $compare) && ($compare == $this->value));
}
有沒有一種方法可以在SimpleTest中進行測試? 代替==,使用===的方法...謝謝。
assertIdentical($x, $y) Fail if $x == $y is false or a type mismatch
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.