Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Over in #1182290: Add boilerplate upgrade path tests @chx introduced the usage of gzip'd files in tests, we can't always count on systems to have zlib installed so the attached patch enables tests to declare a 'requirements' property in getInfo() which would contain an array of function names to pass through function_exists() before the test is run.
So for #1182290: Add boilerplate upgrade path tests, the following would be added to the getInfo() method:
+ 'requirements' => array('gzopen'),
Comment | File | Size | Author |
---|---|---|---|
#9 | 1271060_9.patch | 1.23 KB | BTMash |
#8 | 1271060_8.patch | 1.25 KB | BTMash |
#1 | test_declare_requirements-1271060-1.patch | 682 bytes | matason |
Comments
Comment #1
matason CreditAttribution: matason commentedAttaching the patch...
Comment #2
catchThis should be added as phpdoc for getInfo() as well.
Otherwise looks great.
API addition so needs a change notification once it's in.
Comment #3
Dave ReidWhy not just wrap the test class itself in
function_exists('gzopen') { // Class definition }
?Comment #4
Dave ReidComment #5
matason CreditAttribution: matason commentedI am just wondering whether 'requirements' is right and perhaps even whether there's a clean way of incorporating these function_exist() checks into 'dependencies' as this is what we're really talking about.
Comment #6
catchAlso what about returning a flag from getInfo() rather than array of function names. I could see checks for ini_get, classes and other stuff that's not functions being useful here.
Comment #7
Dave ReidLet's just make an access static function for tests that gets called and returns a TRUE/FALSE value.
This or give a way for tests to stop executing in setUp() gracefully.
Comment #8
BTMash CreditAttribution: BTMash commentedI like the suggestion from #7 since adding in the check is actually quite easy (it can be added to DrupalTestCase so then any other type of tests that are subclasses of DrupalTestCase can also get checked for access) and any test that requires any additional requirements can implement their check fairly easily. I tested this out and got tests to appear/disappear as necessary. Attaching patch.
Comment #9
BTMash CreditAttribution: BTMash commentedAck...whitespace. Attaching new patch.
Comment #10
chx CreditAttribution: chx commentedWe dont want this apparently.
Comment #11
matason CreditAttribution: matason commentedTo elaborate on why we don't want this: It was decided by discussion on IRC (@webchick, @chx, @davereid, @xjm) that it would be better to have tests fail with a message about unmet requirements such as zlib than have tests silently not run at all.
Comment #12
xjmComment #13
Mile23Followup that never got linked from here: #1273478: Implement @requires and @dependencies within TestBase, mark tests as skipped