function DatabaseFetchTestCase::testQueryFetchClass
Confirm that we can fetch a record into a new instance of a custom class.
See also
File
-
modules/
simpletest/ tests/ database_test.test, line 440
Class
- DatabaseFetchTestCase
- Test fetch actions, part 1.
Code
function testQueryFetchClass() {
$records = array();
$result = db_query('SELECT name FROM {test} WHERE age = :age', array(
':age' => 25,
), array(
'fetch' => 'FakeRecord',
));
foreach ($result as $record) {
$records[] = $record;
if ($this->assertTrue($record instanceof FakeRecord, 'Record is an object of class FakeRecord.')) {
$this->assertIdentical($record->name, 'John', '25 year old is John.');
}
}
$this->assertIdentical(count($records), 1, 'There is only one record.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.