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
Step 2 of #2304461: KernelTestBaseTNG™
\Drupal\simpletest\KernelTestBase
is marked as deprecated for removal before Drupal 8.2.x, which is right around the proverbial corner.
Proposed resolution
Create a single patch that has all the conversions. If that becomes problematic, split out those difficult tests to their own issue.
Remaining tasks
https://www.drupal.org/node/2489956 has some instructions on what to do during a conversion. For additional assistance, use #2678534: Convert editor.module's kernel tests to NG as an example of what things should look like.
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#80 | interdiff.txt | 2.19 KB | dawehner |
#80 | 2456477-80.patch | 55.12 KB | dawehner |
#77 | 2456477-77-interdiff.txt | 1.11 KB | Berdir |
#77 | 2456477-77.patch | 54.92 KB | Berdir |
#75 | 2456477-75.patch | 55.12 KB | Berdir |
Comments
Comment #1
dawehnerComment #2
jibranCan we have a change notice for that so that I can fix my contrib modules?
Comment #3
dawehnerJust learned how to write tables in HTML.
@Jibran
In this issue?
Comment #4
amateescu CreditAttribution: amateescu commentedThat's a very good skill to have! Wanna hear a story about divs? :D
Comment #5
jibranEither in this issue after the fix or we can have the steps to convert the tests from KernelTestBase to KernelTestBaseNG.
Comment #6
dawehnerNote: It should be just about extending from the other base class.
Comment #7
kim.pepperShould we have a child issue per module?
Comment #8
dawehnerWell, one giant one won't work, this is for sure. Remember that there has been test failures for some tests ... especially some more on sqlite.
Comment #9
martin107 CreditAttribution: martin107 commentedJust making notes - might as well do it in public.
There are classes of tests which extend KernelTestBase indirectly.
Practically speaking what this means is that when converting and testing it looks like all members of the subset are going to be done in one batch.
For example all the tests that extend core/modules/field/src/Tests/FieldUnitTestBase. -- which has 34 child tests
Anyways here is a list of 17 base classes in core.
grep -Rl 'TestBase extends KernelTestBase' *
core/modules/config/src/Tests/Storage/ConfigStorageTestBase.php ... 3 Child tests
core/modules/field/src/Tests/FieldUnitTestBase.php ... 34 Child tests
core/modules/file/src/Tests/FileManagedUnitTestBase.php
core/modules/hal/src/Tests/NormalizerTestBase.php
core/modules/language/src/Tests/LanguageTestBase.php
core/modules/migrate/src/Tests/MigrateTestBase.php
core/modules/quickedit/src/Tests/QuickEditTestBase.php
core/modules/serialization/src/Tests/NormalizerTestBase.php
core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php
core/modules/system/src/Tests/Database/DatabaseTestBase.php
core/modules/system/src/Tests/Entity/EntityUnitTestBase.php
core/modules/system/src/Tests/File/FileTestBase.php
core/modules/system/src/Tests/KeyValueStore/StorageTestBase.php
core/modules/system/src/Tests/Path/PathUnitTestBase.php
core/modules/system/src/Tests/Plugin/Discovery/DiscoveryTestBase.php
core/modules/system/src/Tests/Plugin/PluginTestBase.php ...20 child tests
core/modules/views/src/Tests/ViewUnitTestBase.php ... 65 child tests
Comment #10
martin107 CreditAttribution: martin107 commentedI think I have found a bug ....
when I started to convert the first of the class ConfigStorageTestBase ... and its 3 sub issues.
So I have just created a quick fix side issue - because I think it will be a blocker to many efforts here.
Comment #11
BerdirIs this really something that we should do in 8.0.x (or more specific, before 8.0.0). Not necessarily against it but it seems like something that we should clarify?
Also don't see why this needs a change record, we already have those afaik?
Comment #12
dawehner@martin107
Yeah to be clear, especially some of the config related tests failed for some reasons.
One reason why KTBTNG is better is because phpunit is in general more strict so we can find more bugs.
Comment #13
alexpottWe need to fix #2553533: KernelTestBaseTNG™ is not cleaning up after itself
Comment #14
martin107 CreditAttribution: martin107 commentedI want to answer #11 in a constructive way
My perspective is that we indirectly help contrib modules by advancing this issue.
I am thinking of "sock" like modules - dull uninspiring things that prove essential in life.
They have the following features
1) Provide little fields, widgets or whatever plugin that glues a site together.
2) Many module listed in their dependency definition
The new Kernel is going to be really useful in setting up test fixtures for these things.
PS I have started a little experimental issue to try and expose things we need to know early.
Comment #15
alexpott@martin107 the CR for the original issue clearly states:
The issue was only committed under that provision. Please do not make me regret that decision. It is great that you are experimenting with the new test infra and please continue but large scale conversion at this point is off the table.
Comment #16
martin107 CreditAttribution: martin107 commented@alexpott
No worries - I will take my foot off the accelerator :)
Comment #17
drunken monkeyAm I mistaken, or doesn't switching the base class from the old to the new
KernelTestBase
also necessitate moving the class to a different directory and namespace (namely fromsrc/Tests
totests/src
)?In that case, a straight move of any of the test base classes would be pretty bad for contrib, since modules would then have to choose exactly which version of Drupal they (or, at least, their test suite) should be compatible with. If this is really the case, I guess there should, for a time at least, be two base classes, one based off the old and one based off the new
KernelTestBase
class.Otherwise, what is the plan for contrib modules to migrate their tests? Should they just not use any of those base classes and start migrating to using the new
KernelTestBase
directly?(Also, please apologize if I have misunderstood the concept of the different Core minor versions – still not sure how they fit in with contrib compatibility.)
Comment #18
dawehnerDid you tried it out?
Just a general statement: Tests aren't an API, and core does NOT support tests in the same way as other APIs does. That said, though, we should probably keep the old base classes,
refactor those helper functions in there, into a generic trait, and reuse that in a new kernel test base class as well.
Comment #19
Wim LeersCreated child issues for the CKEditor & Text Editor kernel tests: #2678532: [PP-1] Convert ckeditor.module's kernel tests to NG + #2678534: Convert editor.module's kernel tests to NG.
Comment #20
dawehnerIt would be great to link to issues in the issue summary.
Comment #21
Wim LeersDo you want to have links for every single test, or do you want to reformat the table to have one row per module, for those tests that have per-module issues created for them?
Comment #22
dawehnerI think removing the entries from the table and replace them with one per module seems a good approach. What do you think?
Comment #23
Wim Leers+1.
Done.
Comment #24
heddnI converted the rest of the things to that same pattern. Any suggestions on system module? At 150+ test classes, is that too much?
Also, it would be good to hear from a committer if breaking things up by module is what they want. In the past, they've had feedback that too many little patches makes things harder for them. Although in this case, there's enough going on that a per module approach seems rational.
Comment #25
heddnComment #26
heddnOK, taking a different direction here. We're going to try to do this all in a single patch. If, and only if, things get a little harry using that approach, we can split out certain tests and modules as appropriate.
Comment #27
heddnComment #28
dawehnerNote: Skip views, because views will require its own custom base testclass, as introduced by #2649914: Enforce formatter dependencies on views fields
Comment #29
BerdirThere are other base classes too. For example, one of the most common ones is EntityUnitTestBase. There are 50 subclasses of that, in all kinds of modules.
We could either update them all together, but actually, especially considering the weird/wrong name there (UnitTestBase), we could also add a new EntityKernelTestBase, deprecate the old one and then gradually move over classes to the new one.
Comment #30
BerdirI don't think #26 is a good idea. I think doing it all in one single issue would be a huge patch, i wouldn't want to review that. It's not that trivial, you have to check that the classes are in the right namespace/folder for example, other they might be silently skipped by the testbot.
Comment #31
dawehner@Berdir
So do you think one issue per module for the easy converted ones and then one for each harder problem is something better?
Comment #32
heddnre #30: the idea in #26 was from the core committers. We can compare numbers of run tests before and after the patch to make sure we aren't silently missing anything. Let's try doing a massive patch first. If that just gets too hard, too quick, then we can try cutting it up a little.
Comment #33
heddnWell, that is going to be painful. Here's as far as I got. It is completed through the config module. 24 down, ~165 left.
To convert using an IDE, look for usages of 'Drupal\simpletest\KernelTestBase', then start shuffling files around and moving namespaces, etc.
Comment #34
BerdirMake sure you set up git diff correctly so it tracks those changes as moves. otherwise that is impossible to review.
I also doubt the count idea will work, AFAIK, simpletest and phpunit tests are counted differently..
Note that I started with #2679096: Convert Kernel Tests in Drupal\system\Tests\Entity to phpunit and that alone is quickly a non-trivial thing with unexpected test fails that requires changes outside of tests.
If you start at the beginning then you won't clash with my efforts there for a while.
Comment #36
heddnStarting at the beginning. And here's the better formatted diff.
Comment #38
Mile23A few updates. I had opened #2674474: Remove usages of @deprecated Drupal\simpletest\KernelTestBase but it's a duplicate of this issue.
I linked the existing change record to this issue.
Comment #39
Mile23Comment #40
BerdirI might pick this up when the following issues are in:
#2553655: Convert ViewKernelTestBase to use KernelTestBaseTNG
#2679096: Convert Kernel Tests in Drupal\system\Tests\Entity to phpunit
#2680105: Convert database kernel tests to phpunit
All convert a sizeable chunk of tests already and the first two also fix various problems in KernelTestBase that might cause the tests above to fail. Once those are in, it might be viable to convert the remaining ones together, at least those that aren't causing troubles.
Comment #41
Berdirthe config module is only the UI and we only had them in there so we didn't have to stuff them into system.module like many others.
Now that we can, i think we should move them to core/tests/Drupal/KernelTests/Config.
Comment #42
pguillard CreditAttribution: pguillard commentedJust a re-roll of #36 for 8.2.x-dev as it was not applying anymore.
Comment #43
dimaro CreditAttribution: dimaro at La Drupalera by Emergya commentedUpdate to run the test.
Comment #45
BerdirThis fixes the config tests for me.
Comment #47
BerdirMore tests converted and fixed.
Comment #48
Berdirrender() actually returns a full HTML page now in the base test class. I don't know what the old returned if this string was at the very beginning?
this used system.module functions which were always loaded before.
I think this hasn't been TRUE (see what I did there?) for a very long time, but our non-type safe assertions didn't fail. PhpUnit has some special cases where assertEquals() actually isn't a == check. Made it explicit now and fixed the test.
not exactly sure what to do with this. This tests the function, so I think using a global is fine as that function uses one?
file location changed.
this function was removed 1 year, 3 month ago in #2235901: Remove custom theme settings from *.info.yml
method was renamed.
$this->publicFilesDirectory no longer exists and the folder already exists.
vfs:// has no realpath), so we can't test this like this.
This was added in #2170117: CMI FileStorage fails with absolute paths but the fix there was actually incorrect and implemented in a different way. The old code could never have worked with vfs in the first place. So it kind of is tested now, and also well documented. The current implementation was added by #2304461: KernelTestBaseTNG™
This was missing and made a lot of config schema tests fail. I suppose we could make a trait, but it's not that much code.
I'm not sure if we need it to be this flexible. we could just support a single property and remove the method.
Comment #49
dawehnerCould you setup settings.php, so you know the path already?
What does the old kernel test base do?
Comment #50
BerdirMoar conversions.
The old kernel test base does exactly this. but as far as I see, nobody every used this feature (being able to add more) and I honestly don't really see why someone would want to? It just exists to be able to test invalid config schemas.
Comment #51
BerdirOn every morning, though shall convert some tests.
Skipping feld and migrate, will do them in separate issues I think.
Comment #52
dawehnerLet's get in #2605956: Port #2605684 to the new KernelTest instead
assertSame with TRUE can be replaced with assertTrue, see
\PHPUnit_Framework_Constraint_IsTrue
Why do we skip the mkdir part now?
Should we setup a test with an actual filesystem *non virtual here? I guess this is not worth it
Do we need this in every test?
Comment #53
dawehnerAdded #2684095: Convert field kernel tests to KernelTestBaseTNG
Comment #54
jhedstromI initially missed @dawehner's note above to skip views for the time being, and when I started converting them noticed what may be a big problem:
When failures occur, PHPUnit serializes the failing test object, then when it unserializes it in
\PHPUnit_Util_PHP::processChildResult()
, the various view objects and entity objects call their unserialize methods out of context (for instance, seeViewExecutable::unserialize()
). This leads to the following exception to be displayed, masking any indication of which test failed:Drupal\Core\DependencyInjection\ContainerNotInitializedException: \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.
Comment #55
dawehner@jhedstrom
Right, this is sort of fixed as part of #2553655: Convert ViewKernelTestBase to use KernelTestBaseTNG
Comment #56
BerdirOpened #2686207: Convert simpletest kernel tests in modules A-I to phpunit, for half of the modules. Have to split somehow.
Also continued with the full patch, attaching here for now. Most is converted except system and migrate tests, will have some test fails.
Comment #58
jhedstromI added #2687897: Convert system module's kernel tests to NG to focus on just the system module's tests, which as mentioned above have some failures in the direct conversion.
Comment #59
Wim LeersI reviewed the changes this patch makes to the
ckeditor
,editor
andquickedit
modules, for which I'm the maintainer. I've only got one tiny remark:This
use
statement should not be necessary, it lives in the same namespace.Thanks for this!
Comment #60
dawehnerComment #62
dawehnerFixed the remaining failures ...
Comment #64
dawehnerThere we go.
Comment #65
larowlanassuming bot agrees
Comment #66
alexpottMaybe we should consider not removing the old base tests and then we can commit this to 8.1.x as well with no fears of breaking anyone's tests till 8.2.x when the old KernelTestBase test will be removed.
R core/modules/system/src/Tests/System/TokenReplaceUnitTestBase.php -> core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTestBase.php
R core/modules/quickedit/src/Tests/QuickEditTestBase.php -> core/modules/quickedit/tests/src/Kernel/QuickEditTestBase.php
R core/modules/language/src/Tests/LanguageTestBase.php -> core/modules/language/tests/src/Kernel/LanguageTestBase.php
Comment #67
Berdir@file docblocks got removed...
Merged with "git merge -X theirs 8.1.x". worked fine :)
Comment #69
BerdirAh, I knew that was too easy. That also kept the wrong namespaces line. Should be fixed now.
Comment #70
dawehnerShould be green, totally
Comment #72
BerdirComment #73
BerdirFound some left-overs.
Comment #75
BerdirPatch didn't apply because it was on top of the other issue, I think.
Comment #77
BerdirFix the hopefully last fails.
Comment #78
dawehnerNice!
Comment #79
alexpottSo the point is that tests can override this? How come we had to add this here?
Comment #80
dawehnerWell, we added it, because it was already part of the old kernel test. We could provide an alternative way, see interdiff + patch, but I'm not sure its worth the hassle.
Actually I really like it now
Comment #81
alexpottI like the changes in #80 too... No base tests have changed... therefore I think this is eligible for 8.1.x as keeping all the tests aligned is more valuable than having different tests to maintain. Tests themselves are not API.
Committed 5b67fe0 and pushed to 8.1.x and 8.2.x. Thanks!
Comment #85
dawehnerHere is the last issue we would need: #2734423: Convert the remaining old kernel tests over