You have a couple of options.
Add a tearDown()
method to the test that resets the file permissions so that git does not think that the file was modified. Then even if the test fails the file will be reset.
http://phpunit.de/manual/current/en/fixtures.html
public function tearDown() {
@chmod(__DIR__ . $file, 0755); //Whatever the old permissions were;
}
If you are using PHP 5.3+, you can use name-spacing and mock the is_readable
function. In your test file, override is_readable
with your own function. You will need to make sure that your override is in the same namespace as your class that you are testing.
http://www.schmengler-se.de/-php-mocking-built-in-functions-like-time-in-unit-tests
In your class you would do this:
namespace SUT
class SUT {
public function readFile($path) {
...
if(!is_readable($path))
throw new FileNotReadableException("The file $path is not readable");
...
}
}
Then in your test you do the following:
namespace SUT
function is_readable($filename) {
if (str_pos('unreadable') !== FALSE)) {
return false;
}
return true;
}
class SUTTest extends PHPUNIT_Framework_TestCase {
/**
* @expectedException Data\Exceptions\FileNotReadableException
*/
public function testFileNotReadableException() {
$file = '/_files/6504/58/6332_unreadable.xlsx';
$sut = new SUT();
$sut->readFile($file);
}
}
You would then not even have to include the files in your repo or worry about the permissions on it.