-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #228 from sensiolabs-de/improve-file-exclusion
improve file exclusion
- Loading branch information
Showing
3 changed files
with
114 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SensioLabs\Deptrac; | ||
|
||
use Symfony\Component\Finder\Iterator\PathFilterIterator; | ||
|
||
class PathNameFilterIterator extends PathFilterIterator | ||
{ | ||
public function accept(): bool | ||
{ | ||
$filename = $this->current()->getPathname(); | ||
|
||
if ('\\' === \DIRECTORY_SEPARATOR) { | ||
$filename = str_replace('\\', '/', $filename); | ||
} | ||
|
||
return $this->isAccepted($filename); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\SensioLabs\Deptrac; | ||
|
||
use ArrayIterator; | ||
use PHPUnit\Framework\TestCase; | ||
use SensioLabs\Deptrac\PathNameFilterIterator; | ||
use SplFileInfo; | ||
|
||
class PathNameFilterIteratorTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider getTestFilterData | ||
*/ | ||
public function testFilter(\Iterator $inner, array $matchPatterns, array $noMatchPatterns, array $resultArray): void | ||
{ | ||
$iterator = new PathNameFilterIterator($inner, $matchPatterns, $noMatchPatterns); | ||
|
||
$values = array_map( | ||
static function (\SplFileInfo $fileInfo) { | ||
return str_replace('/', \DIRECTORY_SEPARATOR, $fileInfo->getPathname()); | ||
}, | ||
iterator_to_array($iterator, false) | ||
); | ||
|
||
sort($values); | ||
sort($resultArray); | ||
|
||
static::assertEquals($resultArray, array_values($values)); | ||
} | ||
|
||
public function getTestFilterData(): array | ||
{ | ||
$inner = new ArrayIterator(); | ||
|
||
//PATH: A/B/C/abc.dat | ||
$inner[] = new SplFileInfo( | ||
'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat' | ||
); | ||
|
||
//PATH: A/B/ab.dat | ||
$inner[] = new SplFileInfo('A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat'); | ||
|
||
//PATH: A/a.dat | ||
$inner[] = new SplFileInfo('A'.\DIRECTORY_SEPARATOR.'a.dat'); | ||
|
||
//PATH: copy/A/B/C/abc.dat.copy | ||
$inner[] = new SplFileInfo( | ||
'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat.copy' | ||
); | ||
|
||
//PATH: copy/A/B/ab.dat.copy | ||
$inner[] = new SplFileInfo( | ||
'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat.copy' | ||
); | ||
|
||
//PATH: copy/A/a.dat.copy | ||
$inner[] = new SplFileInfo('copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'a.dat.copy'); | ||
|
||
return [ | ||
[$inner, ['/^A/'], [], ['A/B/C/abc.dat', 'A/B/ab.dat', 'A/a.dat']], | ||
[$inner, ['/^A\/B/'], [], ['A/B/C/abc.dat', 'A/B/ab.dat']], | ||
[$inner, ['/^A\/B\/C/'], [], ['A/B/C/abc.dat']], | ||
[$inner, ['/A\/B\/C/'], [], ['A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy']], | ||
|
||
[$inner, ['A'], [], ['A/B/C/abc.dat', 'A/B/ab.dat', 'A/a.dat', 'copy/A/B/C/abc.dat.copy', 'copy/A/B/ab.dat.copy', 'copy/A/a.dat.copy']], | ||
[$inner, ['A/B'], [], ['A/B/C/abc.dat', 'A/B/ab.dat', 'copy/A/B/C/abc.dat.copy', 'copy/A/B/ab.dat.copy']], | ||
[$inner, ['A/B/C'], [], ['A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy']], | ||
|
||
[$inner, ['copy/A'], [], ['copy/A/B/C/abc.dat.copy', 'copy/A/B/ab.dat.copy', 'copy/A/a.dat.copy']], | ||
[$inner, ['copy/A/B'], [], ['copy/A/B/C/abc.dat.copy', 'copy/A/B/ab.dat.copy']], | ||
[$inner, ['copy/A/B/C'], [], ['copy/A/B/C/abc.dat.copy']], | ||
]; | ||
} | ||
} |