You are running the unit test and the website under two different user accounts. The one you use for your unit tests has permission to write to your folder, the other one doesn't.
There are two possibilities I see here:
- Run the unit test with the webserver-user
- Change the folder permissions
Running as a different user
Using sudo (or su), you can change the user which will run the command. In doing so, both operations have the same permissions. If one fails, the other will too.
sudo -u username command
Change the folder permissions
Unix has a user and a group assigned to each file and folder. First, create a group for both your users:
groupadd WebsiteGroup
The add your users to that group
usermod -aG WebsiteGroup user1
usermod -aG WebsiteGroup user2
Now assign the group to your folder using chown
/chgrp
. Now when you run your tasks, the group permission is the one that determines success or failure for both.
Man Pages for