function FetchTest::testQueryFetchObject

Confirms that we can fetch a record to an object explicitly.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Database/FetchTest.php, line 47
Definition of Drupal\system\Tests\Database\FetchTest.

Class

FetchTest
Tests fetch actions.

Namespace

Drupal\system\Tests\Database

Code

function testQueryFetchObject() {
  $records = array();
  $result = db_query('SELECT name FROM {test} WHERE age = :age', array(
    ':age' => 25,
  ), array(
    'fetch' => PDO::FETCH_OBJ,
  ));
  foreach ($result as $record) {
    $records[] = $record;
    $this
      ->assertTrue(is_object($record), 'Record is an object.');
    $this
      ->assertIdentical($record->name, 'John', '25 year old is John.');
  }
  $this
    ->assertIdentical(count($records), 1, 'There is only one record.');
}