我试图将一个对象作为“with”的参数与我的模拟对象进行比较。当我比较var_dump
预期和实际时,它们看起来是等效的。->with
我的预感是我在参数中做错了什么。提前致谢
我的测试代码
public function testAddEntry()
{
$expected = new Entry();
var_dump($expected);
$dbRef = $this->getMock('EntriesDAO');
$dbRef->expects($this->once())->method('insert')
->with($expected);
$actual = EntryHelper::addEntry($dbRef, $req);
要测试的功能代码
static function addEntry($iDao, $req)
{
$actual = new Entry();
var_dump($actual);
$actual->newId = $iDao->insert($actual);
控制台输出
class Entry#212 (4) {
public $id =>
NULL
public $content =>
string(0) ""
public $date =>
string(0) ""
public $userId =>
NULL
}
class Entry#209 (4) {
public $id =>
NULL
public $content =>
string(0) ""
public $date =>
string(0) ""
public $userId =>
NULL
}
Time: 0 seconds, Memory: 2.75Mb
There was 1 failure:
1) EntryHelperTest::testAddEntry
Expectation failed for method name is equal to <string:insert> when invoked 1 time(s).
Parameter 0 for invocation EntriesDAO::insert(Entry Object (...)) does not match expected value.
Failed asserting that two objects are equal.