Running `phpunit AllTests` fails during execution of the DrupalTest_TestSuite::setUp() method with a PHP Fatal error: require_once(): Failed opening required 'sites/all/modules/pathauto/pathauto.inc'.

To fix this I believe we need to ensure that the working directory is changed to the Drupal $base_path in DrupalTest_TestSuite::setUp(). This can be done in a similar way to the method used in DrupalTest_TestCase::setUp(). Then switch back to the original working directory at the end of the DrupalTest_TestSuite::tearDown() method.

Comments

chop’s picture

Status: Active » Needs review
StatusFileSize
new4.14 KB

Here's a patch that ensures we're in the correct working directory when using the command line test runner to run a DrupalTest test case or a DrupalTest test suite.

chop’s picture

StatusFileSize
new6.34 KB

OK, again, nice response from all the hordes of PHPUnit users. I guess I'll press on talking to myself. At least it helps me keep track of what I'm doing here.

I've created a new patch addressing this issue, to replace the previous patch in Comment #1. In the new patch, I realised that the setUp and tearDown methods are run repeatedly during test execution. In tha case of the DrupalTest_TestCase::setUp and DrupalTest_TestCase::tearDown the methods are run once for each test. For DrupalTest_TestSuite::setUp and DrupalTest_TestSuite::tearDown the methods are run once for each execution of the suite. So knowing this, why are we going to check on the current working directory every time they're run.

This new patch ensures that the current working directory is checked and changed less often and only when necessary.

Apply it instead of the previous patch and post a comment with any problems or suggestions.

chop’s picture

I've tested the patch from Comment #2 - phpunit-testsuite-cwd.patch as thoroughly as I can and have found to my chagrin that it does nothing to reduce the number of calls to chdir(). This was the goal of the changes I made in this second patch, so it is a failure in that respect. It seems that we still find ourselves moving between the working directory where the initial call to PHPUnit was made and the Drupal root path where Drupal expects you to be when executing Drupal functions, just as often as before.

This is mainly because the DrupalTest_TestSuite::tearDown() and DrupalTest_TestCase::tearDown() method will always put you back where you started, which is just what we want it to do as it turns out. I cannot see a way around this. In fact, when I consider it, I don't think we need to find a way around it. I guess it is really an intended consequence of setting up the environment for the Drupal test and then returning it to normal on the completion of the test.

So, it is back to the patch from Comment #1 - phpunit-testsuite-cwd.patch I'm afraid.

chop’s picture

Status: Needs review » Fixed

Applied patch to CVS after a month use locally.

Status: Fixed » Closed (fixed)
Issue tags: -base_path, -PHPUnit, -setUp, -tearDown, -AllTests, -test suite, -working directory

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