I would like to pull certain configuration items from settings.php from a DrupalWebTestCase in order to test my module (in this case, a SFTP module). I want to do it this way so that I don't hardcode my SFTP credentials.

For example, in my DrupalWebTestCase, I have:

  public function test_sftp()
    // then I would try to connect, etc....

In settings.php:

$conf['mymodule_test_sftp'] = array(
 'host' => 'example.com',
 // etc...

When I run the unit testing suite, this unit test fails, the value returned by variable_get is NULL.


Running the code below, returns the correct database settings, but I get "Undefined index: mymodule_test_sftp":

  public function test_sftp()
    global $databases, $conf;
  • Have you used variables_set('mymodule_test_sftp', $variable); first? – Paul Bönisch Jan 27 '16 at 13:25
  • No, but I do not want to hard code my credentials. That's why I want to use settings.php – Weboide Jan 27 '16 at 13:26
  • in your simpletest check the db values manually to ensure they are there – Paul Bönisch Jan 27 '16 at 13:31
  • See my edit, it does pull the right databases information. I also tried with global $conf, but this still gives an error. – Weboide Jan 27 '16 at 13:43
  • 2
    Simpletest is running on separate Drupal instance witch don't have setting.php edited by you. variable_get() gets you values from system.variable but in your simpletest from simpletestxxxx.system.variable I suposse – Paul Bönisch Jan 27 '16 at 13:57

Just faced a similar issue. What I have found out is that in your DrupalWebTestCase child class you still have access to all variables defined in settings.php before calling parent::setUp(). Which means you can do something like this:

class MymoduleWebTestCase extends DrupalWebTestCase {

  public function setUp() {
    $mymodule_test_sftp = variable_get('mymodule_test_sftp');


    variable_set('mymodule_test_sftp', $mymodule_test_sftp);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.