Problem/Motivation

Apparently we are missing a test to confirm a table can be truncated while a transaction is open. At least, i could not find one.

Proposed resolution

Add one.

Remaining tasks

Review patch.

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Status: Active » Needs review
FileSize
1.4 KB
mondrake’s picture

Status: Needs review » Needs work

Let's also test that truncate is still OK after closing the transaction, and add a test where the transaction is rolled back.

mondrake’s picture

Status: Needs work » Needs review
FileSize
3.23 KB
2.51 KB

Status: Needs review » Needs work

The last submitted patch, 4: 2868273-4.patch, failed testing.

mondrake’s picture

Status: Needs work » Needs review
FileSize
1.77 KB
3.38 KB

This should be better...

Status: Needs review » Needs work

The last submitted patch, 6: 2868273-5.patch, failed testing.

mondrake’s picture

Status: Needs work » Needs review
FileSize
3.38 KB
799 bytes

Oops

mondrake’s picture

FileSize
1.44 KB
3.82 KB

Marking the tests skipped if the db driver does not support transactions.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

borisson_’s picture

Status: Needs review » Needs work

This test is great, it adds coverage that we are missing.

+++ b/core/tests/Drupal/KernelTests/Core/Database/DeleteTruncateTest.php
@@ -67,6 +69,86 @@ public function testTruncate() {
+    db_truncate('test')->execute();

db_truncate is deprecated, so instead of testing db_truncate, we should test \Drupal\Core\Database\Connection::truncate() instead.

mondrake’s picture

Status: Needs work » Needs review
FileSize
4.49 KB
5.94 KB

Thanks for review @borisson_!

Actually, all db_* functions are deprecated, so let's at least avoid introducing new usages. Also, as a db abstraction fan, I prefer to avoid usage of Connection::query on behalf of Connection::select as much as possible.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Looks solid. Yay for more tests!

mondrake’s picture

+++ b/core/tests/Drupal/KernelTests/Core/Database/DeleteTruncateTest.php
@@ -2,6 +2,8 @@
+use Drupal\Core\Database\Database;
+
 /**
  * Tests delete and truncate queries.
  *
@@ -17,6 +19,21 @@

@@ -17,6 +19,21 @@
  */
 class DeleteTruncateTest extends DatabaseTestBase {
 
+  /**
+   * The database connection for testing.
+   *
+   * @var \Drupal\Core\Database\Connection
+   */
+  protected $connection;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+    $this->connection = Database::getConnection();
+  }
+
   /**

It might be worthwhile to move this hunk to the DatabaseTestBase parent class, so that all the test subclasses could replace calls to db_* function with $this->connection->*() calls instead of the \Drupal::database()->* calls that I see are being suggested in the issues that are removing usage of deprecated db_* functions. Some core committer feedback would help, this could also be a followup if deemed relevant.

alexpott’s picture

Adding credit to @borisson_ for spotting the deprecated usage.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed b23ee08a0d to 8.6.x and 826573683f to 8.5.x. Thanks!

Backported to 8.5.x since this is test coverage only.

  • alexpott committed b23ee08 on 8.6.x
    Issue #2868273 by mondrake, borisson_: Missing a test for table TRUNCATE...

  • alexpott committed 8265736 on 8.5.x
    Issue #2868273 by mondrake, borisson_: Missing a test for table TRUNCATE...
mondrake’s picture

Thanks @alexpott, any comment re. #15?

alexpott’s picture

@mondrake makes sense +1

mondrake’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.