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
After fixing #1446366: [meta] Multiple web test classes mislabeled as unit tests. simpletest ([Web|Unit|DrupalUnit]TestBase) more might creep back in.
Proposed resolution
Add a test to prevent that from happening.
Remaining tasks
Discuss and get a good proposal for resolution.
User interface changes
No UI changes.
API changes
No API changes.
Comments
Comment #1
YesCT CreditAttribution: YesCT commentedBased on irc conversation between @tim.plunkett and @jhodgdon
can we add a test to Drupal 8.x that checks whether all class-containing files are named correctly (class name + .php)?
The problem that tests were refactored and neither the test name nor the file name was changed.
We could theoretically parse each class name, and check which class it extends, but it could possibly have to go up several levels...
UnitTestBase, WebTestBase, and DrupalUnitTestBase all extend TestBase anyway.
reflection stuff in PHP might be relevant.
In java you could do something like $foo is 'className'
foreach ($classname) {
$foo = new $className
well you don't need an instance to do it
if !foo is whatever_it should_be
is_subclass_of
If it's important that the class names are correct, then make a test that enforces it. :)
then this test will fail if anyone refactors without renaming.
Comment #2
jhodgdonThe idea here is to use
http://php.net/manual/en/function.is-subclass-of.php
So you can do for instance
is_subclass_of('TestClass1Name', 'DrupalUnitTestBase'))
vs. checking that 'TestClass1Name' ends in 'UnitTest'
And the test pseudocode would be:
a) Find all classes that subclass TestBase.
b) Verify that all classes in (a) that are subclasses of UnitTestBase have names ending in UnitTest.
c) Verify that all classes in (a) that are subclasses of DrupalWebTestBase do not have Unit in their names.
right?
Comment #3
xjmHm, this test would have enormous overhead to enforce a naming convention only for tests. I think this is not worthwhile except in eventual coding standards automated testing. I would suggest postponing it on that meta (which is also postponed to 8.1.x at this point).
Comment #4
xjmPostponing on coding standards checking, #1518116: [meta] Make Core pass Coder Review, and 8.1.x.