How to use ./
in PHPunit ? i've tried several ways like these :
mkdir('./foo)
It's always failed but it's work via browser.
But if i use :
mkdir('../../../foo')
It's work via PHPUnit BUT error via browser.
But if i use :
mkdir(dirname(__FILE__).'../../../foo');
Not working at all.
Try this,
mkdir(dirname(FILE).'/../../../foo');
dirname(FILE) will give you the absolute path of where your file is. This can be different to the command line and the browser. Lets assume a basic install where the webpage is in /apps/website on the file system (or C:\apps\website on Windows).
Your web server likey serves the website as the default (for simple configuration) so
http://localhost/
is the URL. So now the web server, and command line have different paths for the a source code file.
If index.php is in the website directory, dirname(FILE) will give you different results:
Browser: /index.php,
Command Line: /apps/website/index.php
With this in mind, the ../foo.php will also be in a different relative directory based on where you run it from.
Browser: Invalid since you can not go above / Command Line: /apps/foo.php (/apps/website/../foo.php)
When writing your test, you need to know where you are in the structure, and where the relative path is to your location, and then make the relative path changes accordingly. Assuming you have a lib subdirectory to website (/apps/website/lib) and the PHPUnit test is in that directory, and you want foo.php from the parent, then you can use
dirname(__FILE__) . '/../foo.php'); //Assuming __FILE__ is /apps/website/lib/file.php
dirname() normally does not have the trailing slash, so you need to add it when combining the remaining relative paths.