setUp() function accepting array as arguments
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | simpletest.module |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | patch (to be ported) |
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.

#1
I'm creating the issue after an IRC conversation with boombatower
#2
Tested on blog modules by changing its argument to an array and it worked fine, bot will test if more common syntax still works.
#3
Thanks 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
#4
Good call.
#5
If 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.#6
I 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.
#7
The 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.
#8
Lets go the full way and do just array.
#9
#10
Committed.
#11
Will need to followup by changing tests.
#12
Thank you very much for the work!
#13
I'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...
}
}
#14
Automatically closed -- issue fixed for 2 weeks with no activity.
#15
Crosslinking to #644628: FieldAttachTestCase cannot be reused
#16
Let's reconsider this for core.
#17
If 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.