You are here

public function ModuleTestBase::assertTableCount in Drupal 8

Same name in this branch
  1. 8 core/modules/system/src/Tests/Module/ModuleTestBase.php \Drupal\system\Tests\Module\ModuleTestBase::assertTableCount()
  2. 8 core/modules/system/tests/src/Functional/Module/ModuleTestBase.php \Drupal\Tests\system\Functional\Module\ModuleTestBase::assertTableCount()

Assert there are tables that begin with the specified base table name.

Parameters

$base_table: Beginning of table name to look for.

$count: (optional) Whether or not to assert that there are tables that match the specified base table. Defaults to TRUE.

File

core/modules/system/src/Tests/Module/ModuleTestBase.php, line 49

Class

ModuleTestBase
Helper class for module test cases.

Namespace

Drupal\system\Tests\Module

Code

public function assertTableCount($base_table, $count = TRUE) {
  $connection = Database::getConnection();
  $tables = $connection
    ->schema()
    ->findTables($connection
    ->prefixTables('{' . $base_table . '}') . '%');
  if ($count) {
    return $this
      ->assertTrue($tables, new FormattableMarkup('Tables matching "@base_table" found.', [
      '@base_table' => $base_table,
    ]));
  }
  return $this
    ->assertFalse($tables, new FormattableMarkup('Tables matching "@base_table" not found.', [
    '@base_table' => $base_table,
  ]));
}