Skip to content

Commit 8ee904a

Browse files
author
Gianluca Arbezzano
committed
Merge pull request #50 from tomphp/feature/29
Add test for issue #29
2 parents 1c65972 + 18b0982 commit 8ee904a

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/.test_fs
1+
.test_fs
22
build/
33
vendor/
44
phpctags

PHPCtags.class.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ private function process($file)
385385
{
386386
if (is_dir($file) && isset($this->mOptions['R'])) {
387387
$iterator = new RecursiveIteratorIterator(
388-
new RecursiveDirectoryIterator(
388+
new ReadableRecursiveDirectoryIterator(
389389
$file,
390390
FilesystemIterator::SKIP_DOTS |
391391
FilesystemIterator::FOLLOW_SYMLINKS
@@ -432,3 +432,14 @@ public function __toString() {
432432
return "PHPCtags: {$this->message}\n";
433433
}
434434
}
435+
436+
class ReadableRecursiveDirectoryIterator extends RecursiveDirectoryIterator {
437+
function getChildren() {
438+
try {
439+
return new ReadableRecursiveDirectoryIterator($this->getPathname());
440+
} catch(UnexpectedValueException $e) {
441+
file_put_contents('php://stderr', "\nPHPPCtags: {$e->getMessage()} - {$this->getPathname()}\n");
442+
return new RecursiveArrayIterator(array());
443+
}
444+
}
445+
}

tests/Acceptance/AcceptanceTestCase.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract class AcceptanceTestCase extends PHPUnit_Framework_TestCase
3333

3434
protected function setUp()
3535
{
36-
$this->testDir = __DIR__ . '/../.test_fs';
36+
$this->testDir = __DIR__ . '/../../.test_fs';
3737

3838
if (!file_exists($this->testDir)) {
3939
mkdir($this->testDir);
@@ -57,6 +57,20 @@ protected function givenSourceFile($filename, $content)
5757
file_put_contents($filename, $content);
5858
}
5959

60+
protected function givenDirectory($dirname)
61+
{
62+
$dirname = $this->testDir . DIRECTORY_SEPARATOR . $dirname;
63+
64+
mkdir($dirname);
65+
}
66+
67+
protected function givenMode($file, $mode)
68+
{
69+
$file = $this->testDir . DIRECTORY_SEPARATOR . $file;
70+
71+
chmod($file, $mode);
72+
}
73+
6074
/**
6175
* @return void
6276
*/
@@ -177,6 +191,10 @@ private function emptyTestDir()
177191
throw \RuntimeException('Test directory does not exist');
178192
}
179193

194+
foreach (glob($this->testDir . DIRECTORY_SEPARATOR . '*') as $file) {
195+
chmod($file, 0755);
196+
}
197+
180198
$files = new RecursiveIteratorIterator(
181199
new RecursiveDirectoryIterator(
182200
$this->testDir,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace tests\PHPCTags\Acceptance;
4+
5+
final class FilesystemTest extends AcceptanceTestCase
6+
{
7+
/**
8+
* @test
9+
*/
10+
public function itSkipsUnreadableDirectories()
11+
{
12+
$this->givenDirectory('unreadable');
13+
$this->givenSourceFile('unreadable/UnreadableClass.php', <<<EOS
14+
<?php
15+
16+
class UnreadableClass
17+
{
18+
}
19+
EOS
20+
);
21+
$this->givenMode('unreadable', 0000);
22+
23+
$this->runPHPCtags();
24+
$this->assertTagsFileHeaderIsCorrect();
25+
26+
$this->assertTagsFileContainsNoTagsFromFile('unreadable/UnreadableClass.php');
27+
}
28+
}

0 commit comments

Comments
 (0)