function TruncateTest::testTruncateSqlStatement

Same name and namespace in other branches
  1. 11.x core/modules/pgsql/tests/src/Kernel/pgsql/TruncateTest.php \Drupal\Tests\pgsql\Kernel\pgsql\TruncateTest::testTruncateSqlStatement()

Tests that the SQL is a TRUNCATE statement, also inside a transaction.

TRUNCATE is transactional on PostgreSQL, so unlike the parent implementation there is no fallback to a DELETE statement when the query runs inside a transaction.

File

core/modules/pgsql/tests/src/Kernel/pgsql/TruncateTest.php, line 25

Class

TruncateTest
Tests the PostgreSQL implementation of truncate queries.

Namespace

Drupal\Tests\pgsql\Kernel\pgsql

Code

public function testTruncateSqlStatement() : void {
  $this->assertFalse($this->connection
    ->inTransaction());
  $this->assertStringContainsString('TRUNCATE {test}', (string) $this->connection
    ->truncate('test'));
  $transaction = $this->connection
    ->startTransaction();
  $this->assertTrue($this->connection
    ->inTransaction());
  $sql = (string) $this->connection
    ->truncate('test');
  $this->assertStringContainsString('TRUNCATE {test}', $sql);
  $this->assertStringNotContainsString('DELETE', $sql);
  $transaction->rollBack();
}

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