Skip to content

Commit

Permalink
[Finder] Fix findertest readability
Browse files Browse the repository at this point in the history
  • Loading branch information
1emming authored and fabpot committed Aug 31, 2014
1 parent b5d0501 commit 8a47b62
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions src/Symfony/Component/Finder/Tests/FinderTest.php
Expand Up @@ -728,17 +728,30 @@ public function testAccessDeniedException(Adapter\AdapterInterface $adapter)
$finder->files()->in(self::$tmpDir);

// make 'foo' directory non-readable
chmod(self::$tmpDir.DIRECTORY_SEPARATOR.'foo', 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);
$testDir = self::$tmpDir.DIRECTORY_SEPARATOR.'foo';
chmod($testDir, 0333);

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');
}
}

/**
Expand All @@ -754,12 +767,20 @@ public function testIgnoredAccessDeniedException(Adapter\AdapterInterface $adapt
$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)
Expand Down

0 comments on commit 8a47b62

Please sign in to comment.