setUp() function accepting array as arguments

ilo - October 20, 2009 - 23:51
Project:Drupal
Version:7.x-dev
Component:simpletest.module
Category:feature request
Priority:normal
Assigned:Unassigned
Status:patch (to be ported)
Description

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

ilo - October 20, 2009 - 23:55

I'm creating the issue after an IRC conversation with boombatower

#2

boombatower - October 21, 2009 - 03:07
Assigned to:Anonymous» boombatower
Status:active» needs review

Tested on blog modules by changing its argument to an array and it worked fine, bot will test if more common syntax still works.

AttachmentSizeStatusTest resultOperations
610072-setup-modules-list.patch1.42 KBIdlePassed: 14410 passes, 0 fails, 0 exceptionsView details | Re-test

#3

ilo - October 21, 2009 - 06:25

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

boombatower - October 21, 2009 - 20:36

Good call.

AttachmentSizeStatusTest resultOperations
610072-setup-modules-list.patch1.41 KBIdleRepository checkout: failed to checkout from [:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib/modules/simpletest/].View details | Re-test

#5

Damien Tournoud - October 21, 2009 - 20:44
Status:needs review» needs work

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

ilo - October 21, 2009 - 21:04

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

boombatower - October 22, 2009 - 00:02

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

boombatower - November 4, 2009 - 16:29
Project:Drupal» SimpleTest
Version:7.x-dev» 7.x-2.x-dev
Component:simpletest.module» Code

Lets go the full way and do just array.

#9

boombatower - November 4, 2009 - 16:35
Status:needs work» needs review
AttachmentSizeStatusTest resultOperations
610072-setup-modules-list.patch1.23 KBIgnoredNoneNone

#10

boombatower - November 4, 2009 - 16:36
Status:needs review» fixed

Committed.

#11

boombatower - November 4, 2009 - 16:37

Will need to followup by changing tests.

#12

ilo - November 4, 2009 - 16:37

Thank you very much for the work!

#13

yched - November 4, 2009 - 18:28

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

System Message - November 18, 2009 - 18:30
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#15

yched - November 27, 2009 - 12:02

#16

Damien Tournoud - November 27, 2009 - 20:14
Project:SimpleTest» Drupal
Version:7.x-2.x-dev» 7.x-dev
Component:Code» simpletest.module
Assigned to:boombatower» Anonymous
Status:closed» patch (to be ported)

Let's reconsider this for core.

#17

boombatower - November 27, 2009 - 20:57

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.

 
 

Drupal is a registered trademark of Dries Buytaert.