0
我有以下的受測試:PHPUnit的模擬期望失敗的方法名是等於
class ReportTable_Renderer_Html_Decorator_AddRecord extends ReportTable_Renderer_Html_Decorator_CallParent
{
public function renderAddItem(ReportTable $table)
{
$newRow = array();
$masterIDColumn = $this->getMasterIDColumn();
if (!empty($masterIDColumn)) {
$newRow[$masterIDColumn] = $this->getOwner()->getMasterID();
}
foreach ($table->getColumns() as $name => $column) {
$newRow[$name] = '';
}
$newRow['id'] = '0';
if (!empty($newRow[$masterIDColumn])) $newRow['id'] .= '_' . $newRow[$masterIDColumn];
$newRow[$this->getColumn()] = $this->getText();
$this->getRowStyle()->getGroupStyles()->add('do_not_print grey');
return $this->getParent()->renderRowContent($table, $newRow);
}
而且這(間接)父類,其功能我需要存根測試
class ReportTable_Renderer_Html_Decorator_Base extends ReportTable_Renderer_Html
{
public function renderRowContent(ReportTable $table, array $row) {}
public function renderRowSetFooter(ReportTable $table) {}
}
我的測試:
public function testRenderRowSetFooter()
{
$table = new ReportTable('a','b');
$table->addColumn(new ReportTable_Column('one', 'one'));
$table->addColumn(new ReportTable_Column('two', 'two'));
$table->addColumn(new ReportTable_Column('three', 'three'));
$testText = 'test text';
$parentFooterText = 'parent.parent';
$groupID = 234;
$addText = 'Add me. Add me now!';
$newRow = array('one' => $addText, 'two' => $groupID, 'three' => '', 'id' => 0);
$parent = $this->getMock('ReportTable_Renderer_Html_Base', array('renderRowContent', 'renderRowSetFooter'));
$parent->expects($this->any())->method('renderRowContent')->with($table, $newRow)->will($this->returnValue($testText));
$parent->expects($this->any())->method('renderRowSetFooter')->with($table)->will($this->returnValue($parentFooterText));
$subject = $this->getSubject($parent, array('text' => $addText, 'column' => 'one', 'masterIDColumn' => 'two'));
$subject->getOwner()->setMasterID($groupID);
$this->assertEquals($parentFooterText . $testText, $subject->renderRowSetFooter($table));
}
我堅持用這恰好兩個嘲笑功能此錯誤消息:
PHPUnit_Framework_ExpectationFailedException : Expectation failed for method name is equal to <string:renderRowContent> when invoked zero or more times
Parameter 1 for invocation Herkt_ReportTable_Renderer_Html_Base::renderRowContent(Herkt_ReportTable Object (...), Array (...)) does not match expected value.
Failed asserting that two arrays are equal.
其中一個數組顯示$ newRow,另一個顯然是該函數的resut。但是我沒有爲這些數組添加一個assertEquals?這是怎麼產生的?我該如何解決我的測試問題?