class RowCountExceptionTest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Database/RowCountExceptionTest.php \Drupal\Tests\Core\Database\RowCountExceptionTest
  2. 10 core/tests/Drupal/Tests/Core/Database/RowCountExceptionTest.php \Drupal\Tests\Core\Database\RowCountExceptionTest

@coversDefaultClass \Drupal\Core\Database\RowCountException

@group Database

Hierarchy

Expanded class hierarchy of RowCountExceptionTest

File

core/tests/Drupal/Tests/Core/Database/RowCountExceptionTest.php, line 13

Namespace

Drupal\Tests\Core\Database
View source
class RowCountExceptionTest extends UnitTestCase {
  
  /**
   * The default exception message.
   */
  private const DEFAULT_EXCEPTION_MESSAGE = "rowCount() is supported for DELETE, INSERT, or UPDATE statements performed with structured query builders only, since they would not be portable across database engines otherwise. If the query builders are not sufficient, use a prepareStatement() with an \$allow_row_count argument set to TRUE, execute() the Statement and get the number of matched rows via rowCount().";
  
  /**
   * Data provider for ::testExceptionMessage()
   *
   * @return array
   */
  public function providerTestExceptionMessage() {
    return [
      [
        static::DEFAULT_EXCEPTION_MESSAGE,
        '',
      ],
      [
        'test',
        'test',
      ],
    ];
  }
  
  /**
   * @covers ::__construct
   * @dataProvider providerTestExceptionMessage()
   */
  public function testExceptionMessage($expected, $message) {
    $e = new RowCountException($message);
    $this->assertSame($expected, $e->getMessage());
  }
  
  /**
   * @covers ::__construct
   * @group legacy
   */
  public function testExceptionMessageNull() {
    $e = new RowCountException(NULL);
    $this->assertSame(static::DEFAULT_EXCEPTION_MESSAGE, $e->getMessage());
  }

}

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