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
BrowserTestBase
tests have dependencies on simpletest module from traits living in simpletest to test files/fixtures and, probably, others. As BTB is a core component it cannot depend on a module. Viceversa works: Simpletest can rely on core traits, files, fixtures to achieve its mission.
BrowserTestBase
uses these traits from simpletest:
use Drupal\simpletest\AssertHelperTrait;
use Drupal\simpletest\ContentTypeCreationTrait;
use Drupal\simpletest\BlockCreationTrait;
use Drupal\simpletest\NodeCreationTrait;
use Drupal\simpletest\UserCreationTrait;
Only AssertHelperTrait
doesn't have a dependency on a fixture Drupal site, either as the container or the kernel.
Proposed resolution
- Break this dependency by moving the traits somewhere under
core/tests
. - Ensure that we don't have a class loading problem within simpletest, as per #2745123: Simpletest module crashes on cleanup, uninstall
- Ensure BC for existing simpletest-based tests.
Remaining tasks
User interface changes
None.
API changes
Location of traits might change.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#49 | interdiff.txt | 2.43 KB | Mile23 |
#49 | 2803621_49.patch | 23.49 KB | Mile23 |
#43 | interdiff.txt | 22.26 KB | Mile23 |
#43 | 2803621_43.patch | 23.25 KB | Mile23 |
#40 | interdiff.txt | 3.02 KB | Mile23 |
Comments
Comment #2
claudiu.cristeaComment #3
dawehnerWell, we cannot remove simpletest until Drupal 9. I think this is for sure. One thing though we have to ensure is that BrowserTestBase is better, in every sense.
If its better people will switch, as it gives them advantages.
Regarding the dependency breaking. I think this in general a good idea, but we ideally do that in small portions, as we do already, like introducing new traits, etc.
Do you think we should mark this particular issue more as a plan?
Comment #4
klausiWe can deprecate the traits in simpletest module, copy them to core tests somewhere and then empty the originals and make them extend the moved ones. Right?
Comment #5
dawehnerCouldn't even the simpletest base just extend the existing traits?
Comment #6
klausiChanged title for gender neutral language. I thought subclasses are daughters? :-P
Comment #7
claudiu.cristeaI agree, but this is just to make a core functionality not depend on a module (even it's a core module). Then the simpletest removal is another discussion, not in this issue but if that will be accepted this is a prerequisite.
Comment #8
Mile23Updated issue summary with some stuff. Feel free to disagree. :-)
I also want to point out that it works both ways: Simpletest sometimes needs classes in
core/tests
but doesn't have them loaded. See #2745123: Simpletest module crashes on cleanup, uninstall+1 on the solution in #4. Move the traits and have simpletest extend them with empty deprecated traits.
Comment #9
Mile23See also: #2672762: Move core/modules/simpletest/src/RouteProvider.php to the Drupal\Tests namespace/folder
Comment #11
Mile23Here's a tentative first step to untangle the traits. Presented to see what the testbot finds that I didn't.
This patch moves
Drupal\simpletest\AssertHelperTrait
toDrupal\Tests\AssertHelperTrait
, and leaves a deprecated stub trait in simpletest.We should follow a deprecate/remove usage pattern. This issue should deprecate the traits and then other issues can convert usages, either all in one go or per-trait.
Comment #13
claudiu.cristeaThe original scope was not only about traits but also about test files (or any other dependencies). I propose that the title would reflect this.
Comment #14
klausi@Mile23: Looks like you forgot to add the new file for your patch?
Comment #15
Mile23Patch -> depends on -> coffee.
Comment #16
Mile23Here's some wider scope: #2863044: [plan] Remove simpletest dependencies from PHPUnit-based tests
Comment #17
klausiwe need @trigger_error() here now for deprecation notices.
Should we also copy AssertHelperTraitTest? We probably just have to extend the class and change the namespace?
unrelated change, should be removed.
Comment #18
Mile23This patch deals with the issues in #17.
This gives us a deprecation for
AssertHelperTrait
but not the others.It also leaves these usages which we'll have to deal with in a follow-up:
Comment #19
Mile23Hmmm... So
RunCronTrait
is inDrupal\Tests\Traits\Core\RunCronTrait
which I think is a good idea.Or at least to normalize on
Drupal\Tests\Traits
as a place to put all these traits.Comment #20
dawehnerMoving those is a good step! Thank you for creating the patch!
Comment #21
Mile23Moved the rest.
Comment #22
dawehnerI am not convinced that node related stuff belongs into the generic testing framework. what are your thoughts about that?
Comment #23
Mile23In the case of
BlockCreationTrait
, Block is an entity inCore\
and not dependent on a module such as node.If we want these traits to be more explicitly dependent on modules, such as
ContentTypeCreationTrait
needing node, then we should put the trait incore/modules/node/tests/src/Traits
, because that's the only place they can autoload from. Then onlyBrowserTestBase
(and the javascript subclass) can use it, andKernelTestBase
if node module is enabled.Also, a bunch of tests re-declare that they use some of these traits, presumably so they can call for instance
ContentTypeCreationTrait::createContentType()
instead of the aliased method atdrupalCreateContentType()
. SeeDrupal\Tests\big_pipe\FunctionalJavascript\BigPipeRegressionTest
for an example.Comment #24
jibran+1 to that.
I think we added the ablity to use
drupalCreateContentType()
to keep the BC. We should deprecate the use ofdrupalCreateContentType()
in KTB, BTB and JTB. We should also create an issue to replace thedrupalCreateContentType()
withcreateContentType()
.Comment #25
Mile23Traits moved to:
Updated
use
statements inBrowserTestBase
.Comment #26
dawehneris fine I guess? It just won't do anything if the namespaces aren't available, right?
Comment #27
Mile23The
Drupal\Tests\[module]\Traits\
namespace is the only thing that's always autoloadable for all the different testsuites, after #2499239: Use test suite classes to discover different test types under phpunit, allow contrib harmony with run-testsComment #28
Mile23This doesn't remove usages, and deprecates the
Drupal\simpletest\
namespaced traits that are in use by BTB.This leads to lovely deprecation notices which do mention the trait, but fail to mention the class which uses them. Unfortunately we can't use
__TRAIT__
or__CLASS__
to deliver such a message because the trait hasn't been named yet when execution gets to@trigger_error()
and the class is still being parsed at that point, too.However, we can still say for example
BaseAssertHelperTrait::class
in the error message, which might help us if we move things around again. :-) This resolves to the actual trait name (without Base), so all is well.Comment #30
Mile23The fail in #28 shows us that a) the symfony phpunit bridge works... and b) that we won't be removing usages in a follow-up. :-)
This patch changes all usages to the new traits from the deprecated ones. It will still fail because this doesn't make the changes that will be handled in #2876145: ConfigTranslationViewListUiTest is a WTB test in the Functional namespace
Update... OK, maybe it won't fail. Still, there are similar changes in #2876145: ConfigTranslationViewListUiTest is a WTB test in the Functional namespace
Comment #31
Mile23Retesting #28 now that #2878248: DrupalStandardsListener improper handling of @trigger_error() deprecation is in, because we want to avoid removing usages in the deprecation issue.
Comment #34
dawehnerNice work @Mile23!
Comment #35
Mile23Assuming you mean #30. I guess we can bypass the normal deprecation process of deprecating before changing usage. It seems like that's how it will have to work now with
@trigger_error()
.Comment #36
catchPatch looks fine I think, but do we want a change record for this one?
Comment #37
Mile23Added change record: https://www.drupal.org/node/2884454
Needed a re-roll, too.
Comment #39
Mile23Sweeping up the deprecations after #2870453: Convert web tests to browser tests for node module and maybe others.
So here's something to keep in mind:
When we commit this, we haven't simply marked all those traits as deprecated. All tests which access the deprecated traits will always fail, which is OK if that's the desired outcome. I'm not sure how many patches this will effect, but a maintainer can answer whether rerolls are acceptable.
While kernel, functional, and functionalJavscript tests won't fail when they should for other types of deprecation (due to the way isolated tests work... see #2870194-31: Ensure that process-isolated tests can use Symfony's PHPunit bridge to catch usages of deprecated code) these trait deprecations are triggered during discovery, during
include
. That's why that last set of failures were splashed by the autoloader, like this:Also, this means that
@group legacy
won't exclude tests from fails for test which touch these traits in any way. In fact, the only way to turn off such deprecation fails is to remove the listener fromphpunit.xml.dist
.But, that just means we're getting rid of simpletest sooner, rather than later.
Comment #40
Mile23The patch. :-)
Comment #41
naveenvalechaComment #43
Mile23Let's split this issue up so it's not a nightmare to review, and so we don't have the consistency problems outlined in #39.
We'll deprecate the old traits, but we won't @trigger_error().
A follow-up will add the @trigger_error() and make the tests pass.
Comment #44
Mile23Comment #45
naveenvalechaThanks, @Mile23 for the patch.
We have a separate issue for adding @trigger_error to the deprecated classes. #2886547: Add trigger_error to deprecated TestBase base classes/traits that have none, reference CR We could specify about traits in that issue.
#43,
I like the idea of having BTB its own traits and deprecating WTB traits.However, Asserts method could not be the same b/c accessing the value in WTB is different from BTB NodeElement. I don't have the use case for now but anyhow we're copying the files so we could overwrite it later.
This change should pass the cache tests pass #2863318: Cache: Convert system functional tests to phpunit
Comment #46
Mile23I feel pretty certain that we'd want to add @trigger_error() for these different testing systems at different times. Also, it's not entirely clear whether @trigger_error() really works for a lot of our use-cases. See the comment I left over there: #2886547-22: Add trigger_error to deprecated TestBase base classes/traits that have none, reference CR
That's not what's happening here. We are isolating BTB from any dependency on the simpletest module or any simpletest namespace. WTB traits are only deprecated in that they now stub out to other traits in a different namespace.
Yes, def figure out a follow-up for that.
Also,
@coversDefaultClass
only helps in a coverage report, and shouldn't change the behavior of the test.Comment #47
Mile23Comment #48
LendudeThis looks ready to go, one little question,
Since we have a CR, should we not add a 'See https://www.drupal.org/node/2884454.' to all the deprecation messages?
Comment #49
Mile23Good call. Updated with @see linking to the CR.
I'm calling this the follow-up: #2886547: Add trigger_error to deprecated TestBase base classes/traits that have none, reference CR See especially comment #22: #2886547-22: Add trigger_error to deprecated TestBase base classes/traits that have none, reference CR
Comment #50
LendudeThis looks ready to me, CR looks up to date, IS looks up to date.
Comment #52
Mile23Would have been nice to get this in 8.4.x, but it seems disruptive enough to need to go in 8.5.x.
If anyone has a different opinion please speak up. :-)
Re-testing against 8.5.x.
Comment #53
dawehnerPersonally I'm cool with it to be 8.5.x only .. for me its all about progress, but not necessarily in which version.
Comment #56
larowlanCommitted 5f77cf7 and pushed to 8.5.x
Published the change record.
Have asked other committers thoughts on backport.
Comment #58
larowlandiscussed with @catch and agreed to backport
cherry picked as 71e5829 and pushed to 8.4.x
updated change record
Comment #59
xjmYeah it seems like a good idea for this to be backported. Correcting the branch to reflect the backport.
This might also be worth mentioning in a "testing improvements" section in the release notes?
Comment #60
Mile23You know, it's funny that a room full of smart people don't realize they need this follow up: #2907169: Break KernelTestBase dependency on Simpletest, deprecate stub BC traits
(That's self-deprecating humor in case you didn't realize.)
Comment #61
xjmDoh. :)
Comment #63
Mile23Clean up here: #2922371: Numerous deprecation messages for test traits do not reference the correct replacement