Debugging Tests...
Posted: Sun Jul 31, 2005 2:36 pm
So I'm trying to run a few more Mock-based tests and am running into Fatal errors, reported in the simpletest code. I'm 99% sure its because I'm not using the Mocks right, but I'm not sure how to proceed.
Here's the test:
Here's the production code, with my current debugging print_r's
I receive a
line 20 of the production code is run, line 21 is where the error appears to be triggered. The print_r's show that the db is the configured MockDB.
Here's the test:
Code: Select all
function TestOneEntry() {
$registry=&Registry::instance();
$db = new MockDB();
$db->setReturnValue('query','The Phrase',array());
$db->expectOnce('query',array('The Phrase'));
$registry->register("Competition Database",$db);
$pb= new MockPhraseBook();
$pb->setReturnValue('getPhrase','The Phrase',array("Event Registrations"));
$pb->expectOnce('getPhrase',array('Event Registrations'));
$registry->register("Export Phrase Book",$pb);
$mockedList = "[Mock EventEntryFormatter Output]";
$eventEntryFormatter = new MockEventEntryListFormatter();
$eventEntryFormatter->setReturnValue('formatAsTabbed',$mockedList);
$expectedOutput=<<<END_OUTPUT
$this->listName
{$this->row1[1]}. {$this->row1[2]}
$mockedList
END_OUTPUT;
$this->assertEqual($expectedOutput,
$this->formatter->formatAsTabbed($this->oneItemResult,
$eventEntryFormmatter));
}Code: Select all
function formatAsTabbed($qr,$nestedFormatter) {
$str = "LIST OF EVENTS\n";
$numRows=$qr->numRows();
if (0==$numRows)
$str.="No Events\n";
else {
for ($i=0;$i<$numRows;$i++) {
list($eventID,$progNum,$eventName) = $qr->getRowAt($i);
$str.="$progNum.$eventName\n";
$registry = Registry::instance();
echo "<pre>";
print_r($registry);
$pb = $registry->getResource("Export Phrase Book");
print_r($pb);
$db = $registry->getResource("Competition Database");
print_r($db);
$query = $pb->getQuery("Event Registrations",
array("eventid"=>$eventID));
echo "123";
$subResult = $db->query($query);
echo "4";
$str.= $nestedFormatter->formatAsTabbed($subResult);
echo "5";
echo "</pre>";
$str.="\n";
}
}
return $str;
}Code: Select all
Fatal error: Call to a member function on a non-object in /usr/local/CIB/simpletest/mock_objects.php on line 914