Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
+++ b/core/tests/Drupal/Tests/KernelTestBase.php
@@ -0,0 +1,1124 @@
+ /**
+ * Returns the modules to enable for this test.
+ *
+ * @param string $class
+ * The fully-qualified class name of this test.
+ *
+ * @return array
+ */
+ private static function getModulesToEnable($class) {
+ $modules = array();
+ while ($class) {
+ if (property_exists($class, 'modules')) {
+ // Only add the modules, if the $modules property was not inherited.
+ $rp = new \ReflectionProperty($class, 'modules');
+ if ($rp->class == $class) {
+ $modules[$class] = $class::$modules;
+ }
+ }
+ $class = get_parent_class($class);
+ }
+ // Modules have been collected in reverse class hierarchy order; modules
+ // defined by base classes should be sorted first. Then, merge the results
+ // together.
+ $modules = array_reverse($modules);
+ return call_user_func_array('array_merge_recursive', $modules);
+ }
This code is duplicated within FunctionalTestSetupTrait::installModulesFromClassProperty()
.
Proposed resolution
Potentially add another trait which knows how to gather the list of modules. Use this trait to compose a DRY way to get the list of modules for both functional and kernel tests.
Comments
Comment #7
Mile23Comment #8
Mile23