Testing on Windows for the first time!

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
georgeoc
Forum Contributor
Posts: 166
Joined: Wed Aug 09, 2006 4:21 pm
Location: London, UK

Testing on Windows for the first time!

Post 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!
georgeoc
Forum Contributor
Posts: 166
Joined: Wed Aug 09, 2006 4:21 pm
Location: London, UK

Re: Testing on Windows for the first time!

Post by georgeoc »

Bump.

Can I provide any more information on my question?
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Testing on Windows for the first time!

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Testing on Windows for the first time!

Post 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.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Re: Testing on Windows for the first time!

Post 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.
georgeoc
Forum Contributor
Posts: 166
Joined: Wed Aug 09, 2006 4:21 pm
Location: London, UK

Re: Testing on Windows for the first time!

Post 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());
        }
    }
 
Post Reply