function SelectTest::testSimpleSelectAllFields

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/SelectTest.php \Drupal\KernelTests\Core\Database\SelectTest::testSimpleSelectAllFields()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Database/SelectTest.php \Drupal\KernelTests\Core\Database\SelectTest::testSimpleSelectAllFields()
  3. 10 core/tests/Drupal/KernelTests/Core/Database/SelectTest.php \Drupal\KernelTests\Core\Database\SelectTest::testSimpleSelectAllFields()

Tests adding all fields from a given table to a SELECT statement.

File

core/tests/Drupal/KernelTests/Core/Database/SelectTest.php, line 194

Class

SelectTest
Tests the Select query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testSimpleSelectAllFields() : void {
  $record = $this->connection
    ->select('test')
    ->fields('test')
    ->condition('age', 27)
    ->execute()
    ->fetchObject();
  // Check that all fields we asked for are present.
  $this->assertNotNull($record->id, 'ID field is present.');
  $this->assertNotNull($record->name, 'Name field is present.');
  $this->assertNotNull($record->age, 'Age field is present.');
  $this->assertNotNull($record->job, 'Job field is present.');
  // Ensure that we got the right record.
  // Check that all fields we asked for are present.
  $this->assertEquals(2, $record->id, 'ID field has the correct value.');
  $this->assertEquals('George', $record->name, 'Name field has the correct value.');
  $this->assertEquals(27, $record->age, 'Age field has the correct value.');
  $this->assertEquals('Singer', $record->job, 'Job field has the correct value.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.