public function FinderTest::testAccessDeniedException in Database Sanitize 7
File
- vendor/
symfony/ finder/ Tests/ FinderTest.php, line 667
Class
Namespace
Symfony\Component\Finder\TestsCode
public function testAccessDeniedException() {
if ('\\' === \DIRECTORY_SEPARATOR) {
$this
->markTestSkipped('chmod is not supported on Windows');
}
$finder = $this
->buildFinder();
$finder
->files()
->in(self::$tmpDir);
// make 'foo' directory non-readable
$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()));
}
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($testDir, 0777);
clearstatcache($testDir);
if ($couldRead) {
$this
->markTestSkipped('could read test files while test requires unreadable');
}
}