function SelectTest::testSimpleComment

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

Tests rudimentary SELECT statement with a COMMENT.

File

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

Class

SelectTest
Tests the Select query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testSimpleComment() : void {
  $query = $this->connection
    ->select('test')
    ->comment('Testing query comments');
  $query->addField('test', 'name');
  $query->addField('test', 'age', 'age');
  $result = $query->execute();
  $records = $result->fetchAll();
  $query = (string) $query;
  $expected = "/* Testing query comments */";
  $this->assertCount(4, $records, 'Returned the correct number of rows.');
  $this->assertStringContainsString($expected, $query, 'The flattened query contains the comment string.');
}

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