Search code examples
phpfilesimpletest

fopen problem with php simple test


I'm seriously stumped by this one. I'm learning to use simpletest to run my unit tests. In one of my sample test classes, I'm testing a parser which takes a file and works on the content.

I decided to make a file with sample content to test the parser. This file was to be in a subdirectory. After runningfopen() and fwrite(), I kept getting errors that the file does not exist. I tried a file_exists() and it also return false. I then removed the path and left only the filename, this time it worked but I couldn't find the file. I moved the code out of the test class and run it and it worked fine and the file was in the current working directory.

It seems to me that, running the code in the test methods creates the file somewhere else other than the current directory. That is the problem, I can't find the files. I have done a deep search, manually gone through my wamp folders and still cannot find it.

I'd appreciate it if someone can help me out here. I'm running php 5.3.5 on wampserver 2.0i. Simpletest is version 1.1 Alpha 3. Thanks.


Solution

  • You can call getcwd http://php.net/manual/en/function.getcwd.php to get the current working directory.