By sun on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
Previously, the namespace of PHPUnit tests of modules was ambiguous with the module's regular runtime namespace. In addition, the file organization did not allow for different test suites.
The namespace for PHPUnit tests of modules has been changed into Drupal\Tests\$module\Unit:
Type Classname Location ----------------- ------------------------------ ---------------------------- Simpletest Drupal\foo\Tests\*Test ./src/Tests/*Test.php PHPUnit Unit Drupal\Tests\foo\Unit\*Test ./tests/src/Unit/*Test.php
In other words:
Type Base class Location ----------------- ------------------------------ ---------------------------- Simpletest Drupal\simpletest\WebTestBase ./src/Tests/*Test.php PHPUnit Unit Drupal\Tests\UnitTestCase ./tests/src/Unit/*Test.php
API change
-
All PHPUnit unit test files in modules are moved into a
Unitsubdirectory.-./tests/src/ +./tests/src/Unit/ -
The namespace is changed from
Drupal\mymodule\TeststoDrupal\Tests\mymodule:-Drupal\mymodule\Tests\FooTest +Drupal\Tests\mymodule\Unit\FooTest
Example
--- a/core/modules/system/tests/src/Controller/SystemControllerTest.php
+++ b/core/modules/system/tests/src/Unit/Controller/SystemControllerTest.php
@@ -2,10 +2,10 @@
/**
* @file
- * Contains \Drupal\system\Tests\Controller\SystemControllerTest.
+ * Contains \Drupal\Tests\system\Unit\Controller\SystemControllerTest.
*/
-namespace Drupal\system\Tests\Controller;
+namespace Drupal\Tests\system\Unit\Controller;
Impacts:
Module developers