Skip to content
Snippets Groups Projects
Commit e7836c2d authored by Dries Buytaert's avatar Dries Buytaert
Browse files

Issue #338403 by klausi, jhodgdon, grisendo, YesCT, drewish: Use {@inheritdoc}...

Issue #338403 by klausi, jhodgdon, grisendo, YesCT, drewish: Use {@inheritdoc} on all class methods (including tests).
parent 49689cf0
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -195,6 +195,30 @@ public function __construct($test_id = NULL) { ...@@ -195,6 +195,30 @@ public function __construct($test_id = NULL) {
$this->testId = $test_id; $this->testId = $test_id;
} }
/**
* Provides meta information about this test case, such as test name.
*
* @return array
* An array of untranslated strings with the following keys:
* - name: An overview of what is tested by the class; for example, "User
* access rules".
* - description: One sentence describing the test, starting with a verb.
* - group: The human-readable name of the module ("Node", "Statistics"), or
* the human-readable name of the Drupal facility tested (e.g. "Form API"
* or "XML-RPC").
*/
public static function getInfo() {
// PHP does not allow us to declare this method as abstract public static,
// so we simply throw an exception here if this has not been implemented by
// a child class.
throw new \RuntimeException("Sub-class must implement the getInfo method!");
}
/**
* Performs setup tasks before each individual test method is run.
*/
abstract protected function setUp();
/** /**
* Checks the matching requirements for Test. * Checks the matching requirements for Test.
* *
...@@ -1018,6 +1042,8 @@ protected function rebuildContainer() { ...@@ -1018,6 +1042,8 @@ protected function rebuildContainer() {
} }
/** /**
* Performs cleanup tasks after each individual test method has been run.
*
* Deletes created files, database tables, and reverts environment changes. * Deletes created files, database tables, and reverts environment changes.
* *
* This method needs to be invoked for both unit and integration tests. * This method needs to be invoked for both unit and integration tests.
......
...@@ -480,8 +480,23 @@ function simpletest_test_get_all() { ...@@ -480,8 +480,23 @@ function simpletest_test_get_all() {
foreach ($classes as $class) { foreach ($classes as $class) {
// Test classes need to implement getInfo() to be valid. // Test classes need to implement getInfo() to be valid.
if (class_exists($class) && method_exists($class, 'getInfo')) { if (class_exists($class) && method_exists($class, 'getInfo')) {
$info = call_user_func(array($class, 'getInfo')); $reflectionClass = new ReflectionClass($class);
// Skip abstract classes and interfaces.
if ($reflectionClass->isInstantiable()) {
$reflectionMethod = new ReflectionMethod($class, 'getInfo');
$declaringClass = $reflectionMethod->getDeclaringClass()->getName();
// Avoid testing intermediate classes which do not implement the
// method.
if ($class == $declaringClass) {
$info = call_user_func(array($class, 'getInfo'));
}
else {
continue;
}
}
else {
continue;
}
// If this test class requires a non-existing module, skip it. // If this test class requires a non-existing module, skip it.
if (!empty($info['dependencies'])) { if (!empty($info['dependencies'])) {
foreach ($info['dependencies'] as $module) { foreach ($info['dependencies'] as $module) {
......
...@@ -22,22 +22,21 @@ abstract class UnitTestCase extends \PHPUnit_Framework_TestCase { ...@@ -22,22 +22,21 @@ abstract class UnitTestCase extends \PHPUnit_Framework_TestCase {
protected $randomGenerator; protected $randomGenerator;
/** /**
* This method exists to support the simpletest UI runner. * Provides meta information about this test case, such as test name.
*
* It should eventually be replaced with something native to phpunit.
*
* Also, this method is empty because you can't have an abstract static
* method. Sub-classes should always override it.
* *
* @return array * @return array
* An array describing the test like so: * An array of untranslated strings with the following keys:
* array( * - name: An overview of what is tested by the class; for example, "User
* 'name' => 'Something Test', * access rules".
* 'description' => 'Tests Something', * - description: One sentence describing the test, starting with a verb.
* 'group' => 'Something', * - group: The human-readable name of the module ("Node", "Statistics"), or
* ) * the human-readable name of the Drupal facility tested (e.g. "Form API"
* or "XML-RPC").
*/ */
public static function getInfo() { public static function getInfo() {
// PHP does not allow us to declare this method as abstract public static,
// so we simply throw an exception here if this has not been implemented by
// a child class.
throw new \RuntimeException("Sub-class must implement the getInfo method!"); throw new \RuntimeException("Sub-class must implement the getInfo method!");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment