Page 1 of 1

Testing on Windows for the first time!

Posted: Fri May 02, 2008 11:16 am
by georgeoc
Hi all.

Today I've been working on a few things to check that my test suite is portable, as I'm hoping to work with a larger team of developers (i.e., more than 1) in the future. For that reason, I have installed WAMP on a copy of Windows, and run my test suite on that platform for the first time. Most tests pass, but I'm stuck on a very simple issue which I have no prior experience of.

I have a very simple class which writes a file to a specified directory. I have a few tests to check that an error is thrown if the directory has no write permissions, or if the file exists and has no write permissions. I did this using touch(($path)) and chmod($path, 0) at the beginning of each test.

In Windows, the tests pass, but I get an error thrown in my tearDown() method that PHP can't unlink the file at $path - "Permission denied". How do I get round this? I have read things to the effect of "Windows doesn't use chmod()", which I appreciate. However, does that mean these tests are irrelevant on Windows (PHP will always be able to write to every directory), or that I need to modify the tests in some way?

Thanks!

Re: Testing on Windows for the first time!

Posted: Thu May 08, 2008 3:42 pm
by georgeoc
Bump.

Can I provide any more information on my question?

Re: Testing on Windows for the first time!

Posted: Thu May 08, 2008 5:31 pm
by Jade
Make sure that you're calling teardown from the same directory as the one that's inside the path. If you're calling teardown from some other folder then it'll need to be chmod 777 as well.

Re: Testing on Windows for the first time!

Posted: Thu May 08, 2008 6:51 pm
by Chris Corbyn
Since windows doesn't have chmod you need to right click the file/folder as I recall. Then you go to Security/Sharing and tweak some settings from there. I know sharing the file on your network with full read-write permissions works but that's not the *correct* way to do it... it's somewhere under Security.

It's been about 4 years since I used a windows machine for more than about 5 minutes though so i may be wrong.

EDIT | By the way, running tests on command line you wouldn't face these issues since PHP will be running under your own userid.

Re: Testing on Windows for the first time!

Posted: Fri May 09, 2008 3:22 am
by Maugrim_The_Reaper
Isn't this perfectly normal?

Windows has always had issues deleting directories and files depending on their location, and the running processes userid. It's not that your tests fail per se, it's that your tests do not account for the realities faced when running PHP on Windows.

Re: Testing on Windows for the first time!

Posted: Fri May 09, 2008 9:07 am
by georgeoc
Maugrim_The_Reaper wrote:Isn't this perfectly normal?

Windows has always had issues deleting directories and files depending on their location, and the running processes userid. It's not that your tests fail per se, it's that your tests do not account for the realities faced when running PHP on Windows.
I absolutely agree, but because of my inexperience with Windows, I don't know how to remedy this.

I'm testing an app designed for distribution to many users, to run in as many environments. With that in mind, my question should perhaps have been: "How do I test that my class throws the correct error when it cannot write to a directory? How do I create/modify a directory in Windows during setUp() which will cause the test method (expecting a permissions Exception) to pass?"

My first post reads as if I'm asking how to achieve write permissions for PHP on Windows. I'm not - I want to know how to test that a class correctly handles bad permissions on Windows.

How should I modify this so it works on Windows?

Code: Select all

    function testItShouldThrowAnErrorWhenFileExistsButHasNoWritePermissions()
    {
        touch($this->_filePath);
        chmod($this->_filePath, 0);
 
        try
        {
            $this->_writer->export($this->_list);
            $this->fail('Should not get to this point');
        }
        catch (M2f_Element_Config_Exception $e)
        {
            $this->assertPattern('~permissions~i', $e->getMessage());
        }
    }