|
From: Steven B. <ste...@gm...> - 2010-02-15 15:29:40
|
On Mon, Feb 15, 2010 at 1:39 AM, Wermelinger Reguel <
reg...@vo...> wrote:
> Hello
>
> Thanks four your response.
>
> The explicit using of the full directory name didn't get the Test to work.
> I tried the following codes:
> ----------------------------------------------------------------------
> require_once(dirname(__FILE__).'..\lib\AutoLoader.php'); // --> fails
> require_once(dirname(__FILE__).'\..\lib\AutoLoader.php'); // --> works
> require_once('..\lib\AutoLoader.php'); // --> fails
> require_once('\..\lib\AutoLoader.php'); // --> works
> ----------------------------------------------------------------------
>
> I assume that the includes/require call inside a SimpleTest only works if
> the path starts with a leading directory seperator. However this doesn't
> really help. This way I can include the files which I'am including explicit.
> But the included files have other dependencies and make further includes.
> And that framework which im loading makes it's includes also without the
> leading directory-seperator.
>
> Though i can go now and search/replace all the includes inside this
> framework, that's the worst case for me. As the execution as a PHP-script
> works it must be an issue of SimpleTest. And for me it's not good practice
> to adjust working code, just to let it pass it's test.
>
> Isn't there an easier way to bring this SimpleTest to work? Has nobody else
> the same problems with the simpleTest run-configuration?
>
> Best regards,
> Reguel
>
You can modify the include path to include the directories which have all of
your includes. You can add these into the php.ini file. The SimpleTest
Eclipse runner has the capability for you to specify which php.ini file you
wish to use (see the Eclipse/Simpletest preferences). I typically use a
different php.ini file for running tests and this allows me to specify that
"special" php.ini file. You may just need to add your "lib" directory to
the include path. The reason why SimpleTest fails is that it starts in a
different directory so the include path resolves wrong (the include path
typically includes ".") when running the test via SimpleTest.
Alternately you could set the include path at the top of your script [
http://php.net/manual/en/function.set-include-path.php] or you could include
a standard test library script at the top of each test script which does
this for you.
I have had the problem you specified, but I solved it using the method I
previously described (dirname(__FILE__)). In my applications I always use
this method to load libraries. I had problems (many years ago) when I
relied on the files being magically found by the include path (which is why
it works running it one way, but not another way) because inevitably I would
need to deploy my application somewhere else and having to duplicate the
include path environment exactly everywhere can become burdensome. Also by
explicitly telling php where to find the file you save the server from
having to traverse all of the paths in the include_path to try and find each
file you specify. In your case it looks like you are just using this in one
place to load an autoloader file so it probably does not cause much of a
performance hit. My reasons may or may not be best practices but they work
for me -- YMMV.
Regards,
Steven Balthazor
|