You are here

function FetchTest::testQueryFetchDefault in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/Database/FetchTest.php \Drupal\system\Tests\Database\FetchTest::testQueryFetchDefault()

Confirms that we can fetch a record properly in default object mode.

File

core/modules/system/src/Tests/Database/FetchTest.php, line 25
Contains \Drupal\system\Tests\Database\FetchTest.

Class

FetchTest
Tests the Database system's various fetch capabilities.

Namespace

Drupal\system\Tests\Database

Code

function testQueryFetchDefault() {
  $records = array();
  $result = db_query('SELECT name FROM {test} WHERE age = :age', array(
    ':age' => 25,
  ));
  $this
    ->assertTrue($result instanceof StatementInterface, 'Result set is a Drupal statement object.');
  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.');
}