function DeleteTruncateTest::testTruncate

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Database/DeleteTruncateTest.php \Drupal\KernelTests\Core\Database\DeleteTruncateTest::testTruncate()
  2. 10 core/tests/Drupal/KernelTests/Core/Database/DeleteTruncateTest.php \Drupal\KernelTests\Core\Database\DeleteTruncateTest::testTruncate()
  3. 11.x core/tests/Drupal/KernelTests/Core/Database/DeleteTruncateTest.php \Drupal\KernelTests\Core\Database\DeleteTruncateTest::testTruncate()

Confirms that we can truncate a whole table successfully.

File

core/tests/Drupal/KernelTests/Core/Database/DeleteTruncateTest.php, line 61

Class

DeleteTruncateTest
Tests delete and truncate queries.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testTruncate() {
    $num_records_before = $this->connection
        ->query("SELECT COUNT(*) FROM {test}")
        ->fetchField();
    $this->assertNotEmpty($num_records_before);
    $this->connection
        ->truncate('test')
        ->execute();
    $num_records_after = $this->connection
        ->query("SELECT COUNT(*) FROM {test}")
        ->fetchField();
    $this->assertEquals(0, $num_records_after, 'Truncate really deletes everything.');
}

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