minor #11635 [Finder] Fix findertest readability (1emming)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11635).

Discussion
----------

[Finder] Fix findertest readability

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | part of #11631, #11588
| License       | MIT

When running on Ubuntu it is hard to setup an account that allows the `chmod` to downgrade the rights on a directory but is not allow to read from the downgraded directory.

Commits
-------

8a47b62 [Finder] Fix findertest readability
This commit is contained in:
Fabien Potencier 2014-08-31 06:03:33 +02:00
commit 55d17fad19
1 changed files with 31 additions and 10 deletions

View File

@ -728,17 +728,30 @@ class FinderTest extends Iterator\RealIteratorTestCase
$finder->files()->in(self::$tmpDir);
// make 'foo' directory non-readable
chmod(self::$tmpDir.DIRECTORY_SEPARATOR.'foo', 0333);
$testDir = self::$tmpDir.DIRECTORY_SEPARATOR.'foo';
chmod($testDir, 0333);
try {
$this->assertIterator($this->toAbsolute(array('foo bar', 'test.php', 'test.py')), $finder->getIterator());
$this->fail('Finder should throw an exception when opening a non-readable directory.');
} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\\Component\\Finder\\Exception\\AccessDeniedException', $e);
if (false === $couldRead = is_readable($testDir)) {
try {
$this->assertIterator($this->toAbsolute(array('foo bar', 'test.php', 'test.py')), $finder->getIterator());
$this->fail('Finder should throw an exception when opening a non-readable directory.');
} catch (\Exception $e) {
$expectedExceptionClass = 'Symfony\\Component\\Finder\\Exception\\AccessDeniedException';
if ($e instanceof \PHPUnit_Framework_ExpectationFailedException) {
$this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, 'PHPUnit_Framework_ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));
}
$this->assertInstanceOf($expectedExceptionClass, $e);
}
}
// restore original permissions
chmod(self::$tmpDir.DIRECTORY_SEPARATOR.'foo', 0777);
chmod($testDir, 0777);
clearstatcache($testDir);
if ($couldRead) {
$this->markTestSkipped('could read test files while test requires unreadable');
}
}
/**
@ -754,12 +767,20 @@ class FinderTest extends Iterator\RealIteratorTestCase
$finder->files()->ignoreUnreadableDirs()->in(self::$tmpDir);
// make 'foo' directory non-readable
chmod(self::$tmpDir.DIRECTORY_SEPARATOR.'foo', 0333);
$testDir = self::$tmpDir.DIRECTORY_SEPARATOR.'foo';
chmod($testDir, 0333);
$this->assertIterator($this->toAbsolute(array('foo bar', 'test.php', 'test.py')), $finder->getIterator());
if (false === ($couldRead = is_readable($testDir))) {
$this->assertIterator($this->toAbsolute(array('foo bar', 'test.php', 'test.py')), $finder->getIterator());
}
// restore original permissions
chmod(self::$tmpDir.DIRECTORY_SEPARATOR.'foo', 0777);
chmod($testDir, 0777);
clearstatcache($testDir);
if ($couldRead) {
$this->markTestSkipped('could read test files while test requires unreadable');
}
}
private function buildTestData(array $tests)