diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php index add76e05fbceeabc0e968966041242a9a8ea9c32..8244069575d931e007cdbaa382045b6b8f4806f2 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php +++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php @@ -10,6 +10,7 @@ use Drupal\user\Entity\Role; use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\visitor\vfsStreamStructureVisitor; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use Psr\Http\Client\ClientExceptionInterface; /** @@ -255,6 +256,13 @@ public function testLocalTimeZone(): void { $this->assertEquals('Australia/Sydney', date_default_timezone_get()); } + /** + * Tests that ::tearDown() does not perform assertions. + */ + #[DoesNotPerformAssertions] + public function testTearDown(): void { + } + /** * {@inheritdoc} */ @@ -266,18 +274,20 @@ protected function tearDown(): void { // the tables. $connection = Database::getConnection(); if ($connection->databaseType() === 'sqlite') { - $result = $connection->query("SELECT name FROM " . $this->databasePrefix . + $tables = $connection->query("SELECT name FROM " . $this->databasePrefix . ".sqlite_master WHERE type = :type AND name LIKE :table_name AND name NOT LIKE :pattern", [ ':type' => 'table', ':table_name' => '%', ':pattern' => 'sqlite_%', ] )->fetchAllKeyed(0, 0); - $this->assertEmpty($result, 'All test tables have been removed.'); } else { $tables = $connection->schema()->findTables($this->databasePrefix . '%'); - $this->assertEmpty($tables, 'All test tables have been removed.'); + } + + if (!empty($tables)) { + throw new \RuntimeException("Not all test tables were removed"); } }