views:

24

answers:

3

(Sorry if this is titled poorly. I'm actually trying to accomplish two things - find out how the current directory can get changed in PHP, and fix a bug in Simpletest running on WAMP.)

I'm running SimpleTest (simpletest.org) on my Windows 7 local machine on EasyPHP (a WAMP variation).

When I run tests, the directory changes from the local script dir back to: C:\Program Files (x86)\EasyPHP\apache according to getcwd().

I created a couple short scripts to examine getcwd() output. They return the current script path as expected: C:\Users\Burton\Desktop\Sites\dbmover. The scripts:

serverpath/getcwd.php: <? echo getcwd(); require_once('tests/getcwd.php) ?>

serverpath/tests/getcwd.php: <? echo getcwd(); ?>

Both return the current path: C:\Users\Burton\Desktop\Sites\dbmover

I did a search through Simpletest source to check for use of chdir() and chroot() - the only ways. Simpletest doesn't use chdir();

What else could be changing the path??

This relative path problem is apparently very common for Simpletest used in Windows. This poster on stackoverflow has it, as does this poster elsewhere.

Some people treat the problem as normal, but I think it's a bug.

I've been getting around it myself by using dirname(__FILE__) but I'd rather fix it to work correctly.

A: 

This sounds more like an include_path problem. What does echo get_include_path(); reveal?

bradym
It shows .;C:\php5\pear when called from within my test script. (I don't have a php5 directory). This is what shows for both the problem script and the dummy test scripts.
Burton Kent
+1  A: 

I have never used simpletest, and without knowing the internals it is difficult to say. However: commands called (exec / system / etc.) could influence the working dir. One of note is that the cgi version of php (not the sapi cli) changes it's working dir to that of a script, and could possibly be used for php -l syntax checks & other applications. If that's the problem, be sure to pass it the -C parameter.

Wrikken
Thanks... it gave me the idea of what else to check. I didn't find anything you mentioned - but at least I'll know for next time.
Burton Kent
+1  A: 

Turns out that the path problem is caused by how Simpletest is run. It has a cool feature called "autorun", which is basically an include file at the top of the first file calling tests.

It uses register_shutdown_function() which runs just before the script exits. However, the path as this function runs is all wrong in many versions of WAMP.

I've submitted a bug fix for this problem.

BTW, functions that can change the directory in PHP are: system() exec() chdir() chroot()

Burton Kent