Problem/Motivation

DrupalUnitTestBase is deprecated and code comments suggest that it can be globally replaced with KernelTestBase. Let's do that in this issue.

Proposed resolution

  1. Change all occurrences of DrupalUnitTestBase to KernelTestBase.
  2. Remove DrupalUnitTestBase.
  3. Add change notice.

Remaining tasks

Remove DrupalUnitTestBase in this followup #2388043: Remove DrupalUnitTestBase

User interface changes

API changes

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Unfrozen changes This change is unfrozen because it improves the API of automated tests.
Prioritized changes This change is prioritized because it makes a deprecated change.

Comments

cosmicdreams’s picture

StatusFileSize
new781 bytes

Here's an example of the change we would have to make, seeing if this passes the tests.

cs_shadow’s picture

Status: Active » Needs review

@cosmicdreams probably wanted to mark it for review so that the testbot could run.

cs_shadow’s picture

StatusFileSize
new64.96 KB

Attached is a patch that replaces all occurrences of DrupalUnitTestBase with KernelTestBase. It should pass the tests and once it does, we can remove the DrupalUnitTestBase class altogether as a follow-up.

daffie’s picture

StatusFileSize
new56.08 KB

Just a reroll.

-use Drupal\simpletest\DrupalUnitTestBase;
+use Drupal\simpletest\KernelTestBase;

and

-class SomeTest extends DrupalUnitTestBase {
+class SomeTest extends KernelTestBase {

I did not add interdiff, because it would not be helpfull.

The class DrupalUnitTestBase is not deleted. Need a followup for that.

mile23’s picture

Issue summary: View changes
Status: Needs review » Needs work

I think this issue should also remove DrupalUnitTestBase, otherwise we will get false positives for tests which were misses. Also, the testbot itself might need fixing, though I'm pretty sure that's not the case.

The way to evaluate a given patch here is to send two patches to the testbot: One which only makes a minor irrelevant change (such as a comment), and one with the real patch. Then we compare the number of results.

For instance, here's the result count for #4, visible by clicking [view] next to the patch:

PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 81,826 pass(es).

If the number of passes match, things are good.

It might be that we could just compare the number of tests against branch, but that would leave us without a record.

mile23’s picture

Issue summary: View changes

Will need a change notice.

mile23’s picture

StatusFileSize
new580 bytes
new56.35 KB

Talked with @daffie in IRC and so here's a couple of patches.

One does nothing but add a comment.

The other changes all occurrences of DrupalUnitTestBase to KernelTestBase and also deletes DrupalUnitTestBase.

How to do this in NetBeans (and probably other IDEs):

  1. Refactor KernelTestBase to change its name, and all useages. I renamed it to KernelTestBaseReal.
  2. Refactor DrupalUnitTestBase to change its name to KernelTestBase.
  3. Delete the file KernelTestBase.php (which used to be DrupalUnitTestBase.php).
  4. Refactor KernelTestBaseReal to be KernelTestBase.
  5. Done.

Using a process like this is probably more productive than trying to do a re-roll.

mile23’s picture

Status: Needs work » Needs review

The last submitted patch, 7: 2347999_7_no_change.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 7: 2347999_7.patch, failed testing.

mile23’s picture

Hmm. Worked locally.

daffie’s picture

Status: Needs work » Needs review

daffie queued 7: 2347999_7.patch for re-testing.

daffie queued 7: 2347999_7_no_change.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 7: 2347999_7.patch, failed testing.

daffie’s picture

Status: Needs work » Needs review
StatusFileSize
new56.75 KB
new232 bytes

With my patch files then.

The last submitted patch, 16: 2347999-16.patch, failed testing.

daffie queued 16: 2347999-empty.patch for re-testing.

daffie queued 16: 2347999-16.patch for re-testing.

daffie queued 7: 2347999_7.patch for re-testing.

daffie queued 7: 2347999_7_no_change.patch for re-testing.

mile23’s picture

Hmm. Both sets of tests have a discrepancy between the baseline and the changed number. #7 is off by 10, and #16 is off by 4.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

I have posted patches for this issue because there were problems with the testbot. To be clear: I am reviewing the patch from comment #7 that was created by Mile23.

The patch replaces all instances of DrupalUnitTestBase with KernelTestBase and deletes the file with the DrupalUnitTestBase class.
The gets the green light from the testbot.
It all looks good to me, So it gets a RTBC from me.

Followup after commit: I think that the testbot needs to remove some code, so that it does looks for test classes of the type DrupalUnitTestBase.

For the commiter: The patch that I reviewed is 2347999_7.patch.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/serialization/src/Tests/SerializationTest.php
@@ -15,7 +15,7 @@
diff --git a/core/modules/simpletest/src/DrupalUnitTestBase.php b/core/modules/simpletest/src/DrupalUnitTestBase.php

diff --git a/core/modules/simpletest/src/DrupalUnitTestBase.php b/core/modules/simpletest/src/DrupalUnitTestBase.php
deleted file mode 100644

deleted file mode 100644
index 21c53d9..0000000

index 21c53d9..0000000
--- a/core/modules/simpletest/src/DrupalUnitTestBase.php

--- a/core/modules/simpletest/src/DrupalUnitTestBase.php
+++ /dev/null

+++ /dev/null
+++ /dev/null
@@ -1,17 +0,0 @@

@@ -1,17 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\simpletest\DrupalUnitTestBase.
- */
-
-namespace Drupal\simpletest;
-
-/**
- * Base class for integration tests.
- *
- * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
- *   Use \Drupal\simpletest\KernelTestBase.
- */
-abstract class DrupalUnitTestBase extends KernelTestBase {
-}

Can we actually remove this is a separate issue. Just in case a patch gets committed with using DrupalUnitTestBase. If we do it that way we have simpler reverting options.

daffie’s picture

@Mile23: Can you do a new patch. I shall do the review.

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new55.78 KB
new56.37 KB

OK.

So here are two patches. One does the refactor only, and the other does the refactor and deletes DrupalUnitTestBase.

I included a patch with the deletion so the testbot can confirm it all worked.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

The patch replaces all instances of DrupalUnitTestBase with KernelTestBase.
The DrupalUnitTestBase class does not get deleted.
The gets the green light from the testbot.
It all looks good to me, So it gets a RTBC from me.

For the commiter: The patch that I reviewed is 2347999_26_refactor_only.patch.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 0bb57ed and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation for to the issue summary.

There was a code comment that needed updating.

diff --git a/core/modules/system/src/Tests/DrupalKernel/DrupalKernelSiteTest.php b/core/modules/system/src/Tests/DrupalKernel/DrupalKernelSiteTest.php
index b65fb1b..59ee3f3 100644
--- a/core/modules/system/src/Tests/DrupalKernel/DrupalKernelSiteTest.php
+++ b/core/modules/system/src/Tests/DrupalKernel/DrupalKernelSiteTest.php
@@ -22,8 +22,8 @@ class DrupalKernelSiteTest extends KernelTestBase {
   public function testServicesYml() {
     $this->assertFalse($this->container->has('site.service.yml'));
     // A service provider class always has precedence over services.yml files.
-    // DrupalUnitTestBase::buildContainer() swaps out many services with
-    // in-memory implementations already, so those cannot be tested.
+    // KernelTestBase::buildContainer() swaps out many services with in-memory
+    // implementations already, so those cannot be tested.
     $this->assertIdentical(get_class($this->container->get('cache.backend.database')), 'Drupal\Core\Cache\DatabaseBackendFactory');
 
     $class = __CLASS__;

Fixed on commit.

  • alexpott committed 0bb57ed on 8.0.x
    Issue #2347999 by Mile23, daffie, cs_shadow, cosmicdreams:...
mile23’s picture

Updated change notice here: https://www.drupal.org/node/2271271

Ugh. Jumped the gun.

mile23’s picture

mile23’s picture

Issue summary: View changes
Related issues: +#2388043: Remove DrupalUnitTestBase

The last submitted patch, 16: 2347999-empty.patch, failed testing.

Status: Fixed » Closed (fixed)

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