1 database_test.test public DatabaseFetchTestCase::testQueryFetchClassCustomConstructorArgs()

Test passing custom constructor_args for a FETCH_CLASS.

See also

FakeRecordWithConstructor

File

core/modules/simpletest/tests/database_test.test, line 427
Database tests.

Class

DatabaseFetchTestCase
Test fetch actions, part 1.

Code

public function testQueryFetchClassCustomConstructorArgs() {
  $records = array();
  $result = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25));
  // @see EntityPlusController::query (in the contrib entity_plus module).
  $result->setFetchMode(PDO::FETCH_CLASS, 'FakeRecordWithConstructor', array('foo'));
  foreach ($result as $record) {
    $records[] = $record;
    if ($this->assertTrue($record instanceof FakeRecordWithConstructor, 'Record is an object of class FakeRecordWithConstructor.')) {
      $this->assertIdentical($record->name, 'John', '25 year old is John.');
    }
  }

  $this->assertIdentical(count($records), 1, 'There is only one record.');
}