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
InstallTest
makes no HTTP requests but is a functional test
Proposed resolution
Convert InstallTest
into a Kernel test
Remaining tasks
10.1.x version of the patch is needed.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
N/A
Comment | File | Size | Author |
---|---|---|---|
#58 | 2664292-58.patch | 8.51 KB | Spokje |
|
Comments
Comment #2
xjmDiff detected it as a copy, but here are the methods that are now in
InstallKernelTest
:assertIdentical()
. (If the value were not present in config at all, it'd returnNULL
.Attached adds an assertion to prove #2 as well.
Comment #3
xjmComment #4
xjmderp. Removed from attached.
Comment #5
dawehnerIt is always nice to improve the speed of our tests!
What is the reason that we are converting to a deprecated test class? I just tried it out quickly, and it turns out, that the no problem using the modern alternative. I literally just changed the usestatement on top of the class.
Additionally this class is now really just about testing the module installer, so what about naming it
ModuleInstallerKernelTest
You can get them running by using the following lines:
If we want to test the installation process of modules, so of user and module_test we should use the module installer instead of the kernel test fake installing of modules.
Comment #7
harings_rob CreditAttribution: harings_rob commentedOk, attached an attempt on resolving the remaining remarks. Don't know if the interdiff makes sense here but added it anyway.
Comment #8
dawehnerIsn't that one also possible as kernel test?
Comment #9
harings_rob CreditAttribution: harings_rob commentedI moved all the tests to use the kerneltestbase
Comment #10
harings_rob CreditAttribution: harings_rob commentedSorry, it should use the database inside the container.
Comment #11
harings_rob CreditAttribution: harings_rob commentedLast time.. had an unused use statement.
Comment #12
dawehnerLovely, just lovely.
Note: The Namespace should be \Drupal\Tests\system\Kernel\Module and the path system/tests/src/Kernel/Module ...
Comment #13
harings_rob CreditAttribution: harings_rob commentedMoved the test's location.
Comment #14
harings_rob CreditAttribution: harings_rob commentedComment #15
harings_rob CreditAttribution: harings_rob commentedComment #16
dawehnerI love those changes :)
IMHO this should be splitted up into two test methods using
$this->setExceptedException
Comment #17
bircherI had opened this issue in my browser some time ago to review it and now did before refreshing the; page silly me!
To review the diff easier I reshuffled the methods to their original order and used `git diff -M40%` to detect the renaming of the file.
Then I also addressed @dawehners comment in 16, since that allows to remove the need for FormattableMarkup.
I would mark it as RTBC if it wasn't for having changed the last method.
Comment #18
claudiu.cristeaGreat patch! This is a review for #14.
Please add also an interdiff.txt on each patch, regardless of how small is the change, so the reviewers can understand better what was changed since the last patch.
@todo following lines need to be indented.
Hm. I see we are using module_installer service in 5 times, in this class. Wouldn't it be better if we add it as a protected property and we set it in setUp()?
Usually in PHPUnite tests we are putting the expectation as first argument, even the result is the same. I would invert the order of arguments.
Consider using $this->setExpectedException() instead of try {...} catch() {...} workaround. See https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writ...
With phpunit we have a dedicated assertion to be used for testing array subsets:
Note: Unfortunately we don't have the same negation assertion.
Use $this->assertGreaterThan() instead. You can drop the message.
s/Verify/Verifies
Comment #19
dawehnerLet's make it even a bit better :)
Could be
assertGreaterThan
What about using
$this->assertContains
?Note: https://thephp.cc/news/2016/02/questioning-phpunit-best-practices
Comment #20
claudiu.cristea@dawehner cross-review :)
Comment #21
dawehner@claudiu.cristea
That's kind of a luxury problem to have :P
Comment #22
dawehnerJust updating the status now.
Comment #23
dawehnerOh yeah one thing, IMHO the tests could now live inside core/tests instead of core/modules/system as well.
Comment #24
harings_rob CreditAttribution: harings_rob commentedAttached the updates. I hope I created the diffs correctly.
Comment #25
harings_rob CreditAttribution: harings_rob commentedNamespacing...
Comment #27
dawehnerCan't you use
assertContains
to be more explicit here?that method is a bit unclear, what about using testModuleNameLengthWithDependencyCheck?
Comment #28
claudiu.cristeaGreat, we're almost done. Few nits yet to be fixed:
Remove $moduleInstaller. In properties docs we only put:
@var type-hint
.This should be 'protected' not 'private'. Private blocks an hypothetical extension class that wants to change the definition (e.g. wants to add a default value).
Yepp, @dawehner idea from #19.2 is better than mine because
assertContains()
has also anassertNotContains()
counter assertion. Please fix all the assertTrue(in_array()) and assertFalse(in_array()) occurrences.Let's use @dawehner's recommendation from #19. Read https://thephp.cc/news/2016/02/questioning-phpunit-best-practices. Sorry to confuse you in #18. So,
expectException()
seems the best practice in asserting exceptions.Comment #29
claudiu.cristeaWow, a second cross-review in the same issue :)
Comment #30
harings_rob CreditAttribution: harings_rob commentedUpdated the patches. I keep using setExpectedException as expectException is only available after phpUnit 5.2.
Comment #31
harings_rob CreditAttribution: harings_rob commentedComment #32
claudiu.cristeaNice!
Comment #33
xjmAs a testing improvement for an individual test, this is an rc eligible change per: https://www.drupal.org/core/d8-allowed-changes#rc
Comment #34
dawehnerNitpick: we don't use semicolons in comments :)
Comment #36
alexpottI would have expected some methods to be removed from this class.
This test should just rely on system module rather than doing this include.
Comment #41
Mile23Comment #42
claudiu.cristeaReworked as the patch doesn't apply anymore (the web test has moved as functional), so no interdiff. This patch decreases the locally test run from 27.6 to 11.61 seconds.
Replying to #36.2:
@alexpott. no, we cannot rely on system module. The test, specifically ::testRequiredModuleSchemaVersions(), needs the system.module to be installed using the
module_installer
service. So, we'll have to use the service rather than adding the system.module in the protected static$module
array. So we'll have to explicitly include the module main file.Comment #43
claudiu.cristeaComment #44
alexpottLet's get #2926068: Deprecate system_rebuild_module_data() and remove usages in core done first and then the problem is moot.
Comment #45
claudiu.cristea@alexpott, ok, but #2926068: Deprecate system_rebuild_module_data() and remove usages in core waits for #3024461: Adopt consistent deprecation format for core and contrib deprecation messages which waits for #2908391: Add a rule for expected format of @deprecated and @trigger_error() text. And I don't think #2926068: Deprecate system_rebuild_module_data() and remove usages in core should wait for #3024461: Adopt consistent deprecation format for core and contrib deprecation messages as that policy is not yet approved.
Comment #46
claudiu.cristeaBlocking on #2926068: Deprecate system_rebuild_module_data() and remove usages in core.
Comment #47
claudiu.cristeaFixed #44. I've created the patch with
git diff --cached -M10%
, there's no interdiff.Comment #48
klausiWe should keep this @see reference.
This just repeats the name of the previous test function, so they have the same doc block. What is the difference?
I think this name is wrong, should this be "testModuleNameLengthWithoutDependencyCheck()"? Which is a bit long, maybe you can come with something better?
Comment #53
Spokje- Rerolled against
9.4.x-dev
- Merged latest commits
- Tried to address 1., 2. and 3. in #48
Interdiff isn't too useful, I fear, since it won't detect the renaming of the test class.
Back to NR.
Comment #56
smustgrave CreditAttribution: smustgrave at Mobomo commentedFor a reroll into 10.1.x please.
Will do a review after that
Comment #57
xjmComment #58
SpokjeComment #59
_pratik_ CreditAttribution: _pratik_ as a volunteer and at Specbee for Drupal India Association commentedRerolled for 10.1.x
Comment #60
_pratik_ CreditAttribution: _pratik_ as a volunteer and at Specbee for Drupal India Association commentedMy bad @Spokje, forgot to reload page.
Comment #61
SpokjeRerolled.
Looking at the average comment rate in this issue, I'll be back in about one year to reroll for 10.4/10.5 😈
Comment #63
Spokjeknown random JS test failure, ordered retest.
Comment #64
smustgrave CreditAttribution: smustgrave at Mobomo commented@_pratik_ the patch before #58 was for 10.1 already
Reviewing #58
Looks good for me thanks!
Comment #67
alexpottCommitted and pushed 8a2f6514b7 to 10.1.x and 02268796de to 10.0.x. Thanks!
Backported to 10.0.x because this is a test-only change. Property typehinting makes this unsuitable for 9.5.x