When trying to extend the DrupalWebTestCase, setUp could only be called by the class extending, and arguments from inherited classes are ignored.
In may case I'm extending DrupalWebTestCase to create DrupaServiceTestCase, being responsible of configuring the services module to test the implmentation modules: node_service, system_service, and so..
So DrupalServiceTestCase will enable modules: services, xmlrpc_server, services_keyauth, user_service and system_service, all required to do service requests. Later on, each test file will only enable the implementaion module: parent::setUp('comment_service') to perform the tests.
As setUp() only accept arguments (they are later collected using func_get_args) there is no way for DrupalServiceTestCase (in this example) to include modules from the test cases when calling the parent::setUp from the test cases. Actually, it's possible, but only 1 module can be included. I foreseen that when creating the views_service test case, view_service and views modules should have to be enabled, and this is currently impossible.
| Comment | File | Size | Author |
|---|---|---|---|
| #38 | setup_array_too-610072-38.patch | 3.66 KB | yched |
| #35 | setup_array_too-610072-34.patch | 3.54 KB | yched |
| #32 | setup_array_too-610072-32.patch | 3.53 KB | effulgentsia |
| #30 | setup_array_too-610072-30.patch | 3.62 KB | effulgentsia |
| #27 | setup_array_too_V2.patch | 2.69 KB | aspilicious |
Comments
Comment #1
ilo commentedI'm creating the issue after an IRC conversation with boombatower
Comment #2
boombatower commentedTested on blog modules by changing its argument to an array and it worked fine, bot will test if more common syntax still works.
Comment #3
ilo commentedThanks for taking this so fast, boombatower..
Note: There is a typo in the comment
* arguments containing the modules to enabl enable for the duration of the
Comment #4
boombatower commentedGood call.
Comment #5
damien tournoud commentedIf you really want to change the signature, just make setUp() accept only one $modules arguments.
Anyway, regarding the original issue: calling
call_user_func_array(array($this, 'parent::setUp'), $modules)should work.Comment #6
ilo commentedI tried using call_user_func_array that but didn't work (probably my fault). Will try again (thanks for recalling me on this).
I guess using only an array as argument is the best solution, and for sure will break currently existing tests.
Comment #7
boombatower commentedThe reason I didn't switch it...was due to the fact that we are past API changes...so not sure if that will get in since it will require all tests to be changed.
Comment #8
boombatower commentedLets go the full way and do just array.
Comment #9
boombatower commentedComment #10
boombatower commentedCommitted.
Comment #11
boombatower commentedWill need to followup by changing tests.
Comment #12
ilo commentedThank you very much for the work!
Comment #13
yched commentedI'm not sure of the exact meaning of Simpletest contrib 7.x branch as opposed to D7 core, but I'd really support the change. The current
setUp($module_1, $module_2, ...)syntax forces convoluted code to build helper classes extending DrupalWebTestCase while allowing subclasses to enable their own custom set of modules.from field.test:
class FieldTestCase extends DrupalWebTestCase {
function setUp() {
// Call parent::setUp().
$args = func_get_args();
call_user_func_array(array('parent', 'setUp'), $args);
// do stuff...
}
}
Comment #15
yched commentedCrosslinking to #644628: FieldAttachTestCase cannot be reused
Comment #16
damien tournoud commentedLet's reconsider this for core.
Comment #17
boombatower commentedIf we do we can use PGP to make a quick script to update all tests.
I will be providing a merge patch between simpletest 2.x and HEAD once I get browser integration complete. Doesn't directly related to this issue, but since it was moved back from 2.x just to keep everyone informed.
Comment #18
chx commentedThis is surprisingly simple and per http://drupal.org/node/644628#comment-2578850 makes a lot of testcases unusable.
Comment #19
robloachComment #20
webchickLet's get rid of that ugly-assed workaround in FieldTestCase::setUp() while we're at it.
Comment #21
chx commentedComment #22
yched commentedYay.
Comment #24
chx commentedComment #25
boombatower commentedComment #26
scor commented#24 does not apply any longer. Also, the EOL whitespace below needs to be removed:
Comment #27
aspilicious commentedJust a reroll, don't ask me to explain this...
Comment #28
aspilicious commentedComment #29
boombatower commentedShall we?
Comment #30
effulgentsia commentedSorry. Couldn't help doing a little cleanup. Minor code change from #27, but still a code change, so back to "needs review".
Comment #31
yched commentedThis will run module_enable($modules) even if $modules is an empty array ? Not sure this is a big deal though.
Other than that, looks good to me.
Powered by Dreditor.
Comment #32
effulgentsia commentedWith #31.
Comment #33
yched commentedRTBC if green.
Comment #35
yched commentedSimple reroll - RTBC if green.
Comment #36
dries commentedI would be nice to add a @todo to remove the legacy stuff in D8.
Comment #37
boombatower commentedSeems like a good idea, since that is the plan.
Comment #38
yched commentedAdded the @todo.
Comment #39
webchickThis has been hanging around awhile and is holding up other tests. Since the only additional requirements Dries gave in #36 was to add the todo, and this was to-done ;), committed to HEAD.