#2866894: Component tests should not use Drupal\Tests\UnitTestCase but PHPUnit\Framework\TestCase Made use of UnitTestCase outside of Core test invalid but didn't explicitly move UnitTestCase into the Core namespace where it effectively lives.

Proposed resolution

While its completely OK for contrib to use UnitTestCase we can help Core along by making its location more explicit and move it into the core namespace. We might even be able to get rid of the listener because the Core namespace will already be invalid.

Provide deprecated shell testcase for contrib BC.

Remaining tasks

Decide on where removal happens. 9?
Review approach

User interface changes


API changes

Deprecates \Drupal\Tests\UnitTestCase

Data model changes


Members fund testing for the Drupal project. Drupal Association Learn more


neclimdul created an issue. See original summary.

neclimdul’s picture

neclimdul’s picture

Status: Active » Needs review

bah, my comment got eaten. Patch for review and discussion.

Mile23’s picture

Title: Move UnitTestCase to Core namespace » Move UnitTestCase to Core namespace, deprecate old
Status: Needs review » Needs work
Issue tags: +phpunit initiative

+1 on normalizing test base classes to where they really belong. We should have a similar issue for BrowserTestBase.

We should do a deprecation process, though, so that we leave the deprecated stub and add a new class in one issue and then do replacements in another.

neclimdul’s picture

Right on.

There where a lot of changes in this, more then I expected, so I left BrowserCase for its own issue. It could be rolled in here it will just make rerolls a bit more unweidly until its committed.

Definitely on the stub. Its actually in the patch and it is marked @deprecated. Missing though is the required message pending the remaining task from IS of deciding when it gets removed so that definitely needs to work.

dawehner’s picture

I think @Mile23 is talking about @trigger_error, see

neclimdul’s picture

Status: Needs work » Needs review
741 bytes
291.13 KB

Made assumptions we'll deprecate in 8.5.x and remove in 9 and put trigger and deprecated message in. Thoughts?

dawehner’s picture

Do you mind creating a change notice and link it inside the code?

borisson_’s picture

Issue tags: +Needs change record
dawehner’s picture

+++ b/core/tests/Drupal/Tests/UnitTestCase.php
@@ -2,274 +2,14 @@
+@trigger_error('The '. __NAMESPACE__ . '\UnitTestCase is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\Core\UnitTestCase', E_USER_DEPRECATED);

The most recent discussion in #2607260: [meta] Core deprecation message introduction, contrib testing etc. seems to suggest that we should introduce this @trigger_error later, or at least add it to the exclusion list.

neclimdul’s picture

Not sure I understand. 1) is it deprecated or not. 2) are we not targeting dev with this?

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.