In Drupal 7 (and below), all test classes had to implement a public static getInfo() method in order to supply meta data about the test (for UI/listing purposes). In Drupal 8, the getInfo() method has been replaced with native PHPDoc documentation on the test class itself, following PHPUnit's lead:
-
The fully-qualified test class name is the (reported) test
'name'now. -
The PHPDoc summary line is consumed as the
'description'now.Every test class MUST have a PHPDoc summary line. Only PHPUnit tests MAY skip the PHPDoc summary line if their PHPDoc specifies a
@coversDefaultClass. -
The
@groupPHPDoc annotation replaces the'group'.Every test class MUST specify at least one (first)
@groupthat matches the originating module name (or Drupal core component name).For example, the former human-readable
'group' => 'Views UI'turns into the module name@group views_ui -
The
@requires module $namePHPDoc annotation replaces the'dependencies'.This PHPDoc annotation construct follows the generic pattern of PHPUnit @requires annotations. Note that Simpletest tests only support exactly this requirement at this point; additional options will be made available by #1273478: Implement @requires and @dependencies within TestBase, mark tests as skipped
PHPUnit tests no longer need to implement getInfo() — which implicitly means that PHPUnit tests no longer have to extend from Drupal\Tests\UnitTestCase instead of \PHPUnit_Framework_TestCase (if unnecessary).
Example: IceCreamTest class of ice_cream.module
Drupal 7
/**
* Tests generation of ice cream.
*/
class IceCreamTest extends DrupalWebTestCase {
public function getInfo() {
return array(
'name' => 'Make ice cream',
'description' => 'Tests generation of ice cream.',
'group' => 'Ice Cream', // Note: Capitalization.
);
}
}
Drupal 8
Drupal tests
/**
* Tests generation of ice cream.
*
* @group ice_cream
*
* Note: This ^^ primary group is the internal name of the originating module.
*/
class IceCreamTest extends WebTestBase {
}
PHPUnit tests
(only applies if there is a @coversDefaultClass; otherwise see above.)
/**
* @coversDefaultClass \Drupal\ice_cream\IceCream
* @group ice_cream
*/
class IceCreamTest extends UnitTestCase {
}