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.
Reasons:
- Scanning filesystem instead of using a hook is un-drupalish. (DX)
- Instantiating all test cases just to call getInfo() is incorrect code usage.
- Blocker for #323477: Increase simpletest speed by running on a simplified profile
Changes:
- Create a hook_test() to provide the information getInfo() does.
- Update core tests to reflect it
- Implement in SimpleTest runner and run-test.sh.
Comment | File | Size | Author |
---|---|---|---|
#41 | hook_test.patch | 79.78 KB | boombatower |
#39 | hook_test.patch | 79.93 KB | boombatower |
#37 | hook_test.patch | 77.82 KB | boombatower |
#36 | hook_test.patch | 3.28 KB | boombatower |
#34 | hook_test.patch | 147.81 KB | boombatower |
Comments
Comment #1
Dave ReidThis is a good idea. Subscribing to see how it might affect #343502: Allow tests to require and test existance of contrib modules.
Comment #2
boombatower CreditAttribution: boombatower commentedInitial hook design. I'm think about removing file_path and just assuming that if you set file key then the file path should be /path/to/module/tests. Thoughts?
Current hook API:
Comment #3
boombatower CreditAttribution: boombatower commentedRedesigned per my previous idea.
Comment #4
chx CreditAttribution: chx commentedVery nice. that getInfo business was really ick, agreed totaly on the original post and the suggested hook.
Comment #5
boombatower CreditAttribution: boombatower commentedsimpletest_get_all_tests() is much cleaner now!
I would like to do further cleanup of the simpletest.module so that run-tests.sh isn't as independent.
This should work for the simpletest.test only. I would like to confirm the implementation before I take the time to convert all the other getInfo() implementations to hook_test().
Comment #6
boombatower CreditAttribution: boombatower commentedComment #7
chx CreditAttribution: chx commentedif (isset($test_classes) && is_array($test_classes))
simplify toif ($test_classes)
. In simpletest_load_test move(isset($info['file']) ? 'tests/' . $info['file'] : $info['module'])
into a variable (like $basename), 'cos it's hard to read. Finally, in your new file, do not hesitate to use double quotes to be able to use unescaped single quotes. Escaped single quotes are ugly.Comment #8
boombatower CreditAttribution: boombatower commentedThe first item is copied directly out of menu.inc :) [will change]
Second [will change]
The escaping was there before I just copied it out of getInfo(), but I can change it. [will change]
Comment #9
boombatower CreditAttribution: boombatower commentedPer #7.
What I need now is help rewriting all the getInfo() as hooks :)
Comment #10
boombatower CreditAttribution: boombatower commentedWay more test cases then I was thinking (suppose I could go out to t.d.o and see that)...Got a bunch...but by no means done...I have to work on something else...and d.o will be done shortly...I'll see if I can't come up with a script.
EDIT: This patch file was overridden...this is equal to #14.
Comment #11
boombatower CreditAttribution: boombatower commentedMade script to do most of the work for me...then painstakingly double checked everything.
Comment #13
boombatower CreditAttribution: boombatower commentedNote: during the bugged file upload state this file overrode the previous one. So the comments and the test results may not make a lot of sense. What test results you see will be for the file above. (another bug I can't edit the text of #12)
Comment #14
boombatower CreditAttribution: boombatower commentedCorrecting issue...updating patch, with overriding file from last night.
Comment #15
boombatower CreditAttribution: boombatower commentedPrevious patch used module_implements() which ignores modules that are disabled. So the following tests did not run. New patch uses module_rebuild_cache() instead.
Comment #16
boombatower CreditAttribution: boombatower commentedDue to weird bug last night...results for #15 are displayed on #10.
Comment #17
boombatower CreditAttribution: boombatower commentedchx recommended not use module_invoke.
Comment #18
boombatower CreditAttribution: boombatower commentedAfter talking in IRC we decided to move the hook_test() to the .test files for several reasons:
The previous version didn't work because SimpleTest didn't locate it's hook in a standard file and thus caused the problem with the removal of module_invoke() which lead us to realize that the problem was worse for disabled modules.
Comment #19
chx CreditAttribution: chx commentedMy "dead code" remark was referring to putting hook_test in .module files as these are not needed for normal module work. Also, furthering the original argument, Instantiating all test cases just to call getInfo() is incorrect code usage. -- indeed, calling the constructor for two, enitirely different reasons is simply wrong. A constructor should be able to set up something for all of its test cases, finally providing a meaningful answer to the question, which test functions belong to one class?
Comment #21
Damien Tournoud CreditAttribution: Damien Tournoud commentedBuilding above #393068: Make the registry class hierarchy, interface and docblock aware, this patch implement direct parsing of docblocks. I'm really against creating yet-another-registry-hook. Plus, this removes the "dead code" concern.
Note: only two tests were converted to the new info docblock yet.
Comment #22
Damien Tournoud CreditAttribution: Damien Tournoud commentedBased on the patch above, I believe it will be relatively easy to implement a fully clean environment (based on the idea of implementing a separate test-runner.php in the root directory, and bootstrapping the target environment from that... that whole idea requiring us to now which file a given test class is defined in, which is impossible both in the current situation).
Comment #24
XanoThe registry allows hook_test() implementations to be put in any file, so it will never be loaded unless it is actually needed.
Comment #25
boombatower CreditAttribution: boombatower commentedThe reason this issue has died was after extensive discussion in IRC, I will try to explain all the possibilities and reasons.
Possible solutions
Comment #26
boombatower CreditAttribution: boombatower commented#21: I think that is the best solution, great idea!
+1
Comment #27
boombatower CreditAttribution: boombatower commentedTo see kinda how we are using the php doc block look at Java's annotations. You can see they made it a language construct (modifier).
Theoretically this type of registry could be used to do some cool stuff (also simplify API modules job :)).
Anywhere you just want to register function as being some sort of hook/callback and with some meta data these can be used.
I think in SimpleTest's case and the ones DamZ mentioned in the other issue it is the best solution. Heres a before and over of what it will look like.
Before
After
The advantages being:
Comment #28
webchickI'm pretty -4000 to embedding important registration info in docblock properties from a DX perspective:
a) Everywhere else I want to "register" something with Drupal, I implement a hook (hook_perm, hook_menu, hook_theme, etc.). This is deviating from the standard that, for better or worse, currently exists.
b) While writing Doxygen comments is /highly recommended/ it is not /required/. Moving to this model would make it required, and also introduce a special Drupal-only syntax for it.
We can discuss this more in #393068: Make the registry class hierarchy, interface and docblock aware about whether or not it's worth moving all registry hooks to this model, but IMO it's a bad idea to hitch the future of this patch on that one.
Implementing hook_test() in the .test file (so that it can be scanned even in disabled modules) seems like the only way forward here.
Comment #29
boombatower CreditAttribution: boombatower commentedAfter our discuss in IRC I updated the script (attached), ran it and manually scanned the changes, and merged the simpletest.module portion of the patch.
Need to compare total assertion count from testbot to ensure we got all tests picked up.
Comment #30
boombatower CreditAttribution: boombatower commentedForgot changes to runtests.sh and simpletest.api documentation.
Comment #32
boombatower CreditAttribution: boombatower commentedCommit of #259368: Allow Inline CSS in drupal_add_css caused failure to apply.
Reroll.
Comment #33
Damien Tournoud CreditAttribution: Damien Tournoud commentedI'm pretty -4000 in hook_test_info() from a DX perspective:
- you already have created your test class, extended DrupalWebTestCase, you gave it a name, there should be nothing more required from you
- in particular, you don't want to declare your intention twice (first by creating the class, then by registering the class in hook_test_info())
- the system could be smart enough to deal with empty title, description and group: by default, take the name of the class as the title, an empty description, and assign the test to the "Other" group.
So -4000 for yet-another-registry-we-don't-need:
- we already have a registry of classes and interfaces
- as I demonstrated in #393068: Make the registry class hierarchy, interface and docblock aware, it's easy enough to extend it so that it also read meta-data about those
- this method is used elsewhere, most notably in Java / J2EE under the name of 'annotations', so it's not at all a "Drupalism", even if the keywords we will implement are obviously specific
Comment #34
boombatower CreditAttribution: boombatower commentedAs I've stated in #27 I agree that annotations are not new, but:
If we are going to make the system auto detect and use test classes then wouldn't it make sense to do the same with hook_theme(), hook_menu(), etc, which is a major shift which was the idea behind discussing that in the related issue. My impression was that this wasn't a "no", but more "we need more people to look this over and update core to make it consistent if we decide to do it".
From that standpoint if we make this a hook that solves our problem now and if we so choose to make the shift then hook_test() can change along side the others.
NOTE: I found a one line change that needed to be made to the above patch. I'd like it to be tested and the results reported back, can we leave the issue as needs review so the results will be recorded. The previous patch results look like it worked properly, but the way PIFT functions they are ignored when issue isn't a valid status.
Comment #35
boombatower CreditAttribution: boombatower commentedInterestingly enough the PHP documentation was incorrect (or at least what I read) and you can infact invoke a static method using a dynamic class name. (thanks Damien) I remember to try it anyway and ignore documentation next time.
I am working on a patch right now.
Comment #36
boombatower CreditAttribution: boombatower commentedHere is the updated script used.
Comment #37
boombatower CreditAttribution: boombatower commentedSomehow patch didn't get the individual test changes.
Comment #39
boombatower CreditAttribution: boombatower commentedSince the inner workings of run-tests.sh and the web runner do not share common API elements (I want to fix, but at the moment I am focusing on PIFT/PIFR) I forgot to update the script.
Comment #40
boombatower CreditAttribution: boombatower commentedComment #41
boombatower CreditAttribution: boombatower commentedChanged:
to:
Comment #42
chx CreditAttribution: chx commentedthat's a pretty workable solution. Although it needs the test files but at least we do not instance the classes needlessly. This is really a staple case for static methods -- getting static data out of the class -- so static it's constant :) Nice job.
Comment #43
Dave ReidDid some devel.module memory profiling for admin/build/testing and confirmed some basic testing I had done.
Before patch:
Memory used at: devel_boot()=1.22 MB, devel_shutdown()=21.44 MB, PHP peak usage=23.25 MB.
After patch:
Memory used at: devel_boot()=1.22 MB, devel_shutdown()=20.98 MB, PHP peak usage=22.75 MB.
Yay! :)
Comment #44
boombatower CreditAttribution: boombatower commentedWith the improvements I have planned I might be able to get that down a bit more, mainly focused on code cleanup though.
Comment #45
webchickGreat. :) Committed to HEAD!
Needs to be reflected in the SimpleTest docs and the upgrade documentation.
Comment #46
boombatower CreditAttribution: boombatower commentedUpgrade documentation? Simpletest 6.x-2.x should be where people are coming from and I backport core regularly so it should have this soon.
Thanks for the time you spent discussing this.
Comment #47
webchickYikes! You shift the API under contrib developers' feet like that?! :) Ok, your perogative...
But we at least need it updated in places like http://drupal.org/node/325974 and http://drupal.org/node/30021 and so on. Everything under http://drupal.org/simpletest could probably use a quick pass.
Comment #48
boombatower CreditAttribution: boombatower commentedWell the idea is they can keep up with core improvements...obviously if they don't want to they stick with a previous version, but especially for people coming onto the scene it is nice.
Also I don't develop SimpleTest 6.x-2.x at all, if people have feature requests I move them to core. It doesn't make a lot of sense to maintain two separate pieces of code. Majority of the backports haven't messed with API, only added to it or corrected it.
Comment #49
boombatower CreditAttribution: boombatower commentedChecked all pages and updated