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

Tests that we can not pass a scalar value when an array is expected.

File

core/tests/Drupal/KernelTests/Core/Database/QueryTest.php, line 31

Class

QueryTest
Tests Drupal's extended prepared statement syntax..

Namespace

Drupal\KernelTests\Core\Database

Code

public function testScalarSubstitution() {
  try {
    $names = $this->connection
      ->query('SELECT [name] FROM {test} WHERE [age] IN ( :ages[] ) ORDER BY [age]', [
      ':ages[]' => 25,
    ])
      ->fetchAll();
    $this
      ->fail('Array placeholder with scalar argument should result in an exception.');
  } catch (\Exception $e) {
    $this
      ->assertInstanceOf(\InvalidArgumentException::class, $e);
  }
}