function InsertDefaultsTest::testDefaultEmptyInsert

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

Tests that no action will be preformed if no fields are specified.

File

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

Class

InsertDefaultsTest
Tests the Insert query builder with default values.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testDefaultEmptyInsert() : void {
  $num_records_before = (int) $this->connection
    ->query('SELECT COUNT(*) FROM {test}')
    ->fetchField();
  try {
    $this->connection
      ->insert('test')
      ->execute();
    // This is only executed if no exception has been thrown.
    $this->fail('Expected exception NoFieldsException has not been thrown.');
  } catch (NoFieldsException $e) {
    // Expected exception; just continue testing.
  }
  $num_records_after = (int) $this->connection
    ->query('SELECT COUNT(*) FROM {test}')
    ->fetchField();
  $this->assertSame($num_records_before, $num_records_after, 'Do nothing as no fields are specified.');
}

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