class TruncateTest

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

Tests the PostgreSQL implementation of truncate queries.

Attributes

#[Group('Database')] #[RunTestsInSeparateProcesses]

Hierarchy

Expanded class hierarchy of TruncateTest

File

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

Namespace

Drupal\Tests\pgsql\Kernel\pgsql
View source
class TruncateTest extends DriverSpecificDatabaseTestBase {
  
  /**
   * 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.
   */
  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.