OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
reader
/
API
/
vendor
/
symfony
/
finder
/
Tests
/
Iterator
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
08/07/2024 04:34:19 AM
rwxr-xr-x
📄
CustomFilterIteratorTest.php
1.19 KB
08/07/2024 04:34:19 AM
rw-r--r--
📄
DateRangeFilterIteratorTest.php
2.51 KB
08/07/2024 04:34:19 AM
rw-r--r--
📄
DepthRangeFilterIteratorTest.php
2.8 KB
08/07/2024 04:34:19 AM
rw-r--r--
📄
ExcludeDirectoryFilterIteratorTest.php
2.92 KB
08/07/2024 04:34:19 AM
rw-r--r--
📄
FileTypeFilterIteratorTest.php
1.99 KB
08/07/2024 04:34:20 AM
rw-r--r--
📄
FilecontentFilterIteratorTest.php
2.56 KB
08/07/2024 04:34:19 AM
rw-r--r--
📄
FilenameFilterIteratorTest.php
1.19 KB
08/07/2024 04:34:19 AM
rw-r--r--
📄
InnerNameIterator.php
555 bytes
08/07/2024 04:34:20 AM
rw-r--r--
📄
Iterator.php
1.1 KB
08/07/2024 04:34:20 AM
rw-r--r--
📄
IteratorTestCase.php
3.4 KB
08/07/2024 04:34:20 AM
rw-r--r--
📄
LazyIteratorTest.php
1.22 KB
08/07/2024 04:34:20 AM
rw-r--r--
📄
MockFileListIterator.php
553 bytes
08/07/2024 04:34:20 AM
rw-r--r--
📄
MockSplFileInfo.php
3.21 KB
08/07/2024 04:34:20 AM
rw-r--r--
📄
MultiplePcreFilterIteratorTest.php
2.36 KB
08/07/2024 04:34:20 AM
rw-r--r--
📄
PathFilterIteratorTest.php
3.03 KB
08/07/2024 04:34:20 AM
rw-r--r--
📄
RealIteratorTestCase.php
4.81 KB
08/07/2024 04:34:20 AM
rw-r--r--
📄
RecursiveDirectoryIteratorTest.php
1.56 KB
08/07/2024 04:34:20 AM
rw-r--r--
📄
SizeRangeFilterIteratorTest.php
1.63 KB
08/07/2024 04:34:20 AM
rw-r--r--
📄
SortableIteratorTest.php
8.22 KB
08/07/2024 04:34:20 AM
rw-r--r--
📄
VcsIgnoredFilterIteratorTest.php
10.18 KB
08/07/2024 04:34:20 AM
rw-r--r--
📄
VfsIteratorTestTrait.php
5.36 KB
08/07/2024 04:34:20 AM
rw-r--r--
Editing: VcsIgnoredFilterIteratorTest.php
Close
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Iterator\VcsIgnoredFilterIterator; class VcsIgnoredFilterIteratorTest extends IteratorTestCase { private string $tmpDir; protected function setUp(): void { $this->tmpDir = realpath(sys_get_temp_dir()).\DIRECTORY_SEPARATOR.'symfony_finder_vcs_ignored'; mkdir($this->tmpDir); } protected function tearDown(): void { $this->removeDirectory($this->tmpDir); } /** * @param array<string, string> $gitIgnoreFiles * * @dataProvider getAcceptData */ public function testAccept(array $gitIgnoreFiles, array $otherFileNames, array $expectedResult, string $baseDir = '') { $otherFileNames = $this->toAbsolute($otherFileNames); foreach ($otherFileNames as $path) { if (str_ends_with($path, '/')) { mkdir($path); } else { touch($path); } } foreach ($gitIgnoreFiles as $path => $content) { file_put_contents("{$this->tmpDir}/{$path}", $content); } $inner = new InnerNameIterator($otherFileNames); $baseDir = $this->tmpDir.('' !== $baseDir ? '/'.$baseDir : ''); $iterator = new VcsIgnoredFilterIterator($inner, $baseDir); $this->assertIterator($this->toAbsolute($expectedResult), $iterator); } public static function getAcceptData(): iterable { yield 'simple file' => [ [ '.gitignore' => 'a.txt', ], [ 'a.txt', 'b.txt', 'dir/', 'dir/a.txt', ], [ 'b.txt', 'dir', ], ]; yield 'simple file - .gitignore and in() from repository root' => [ [ '.gitignore' => 'a.txt', ], [ '.git', 'a.txt', 'b.txt', 'dir/', 'dir/a.txt', ], [ '.git', 'b.txt', 'dir', ], ]; yield 'nested git repositories only consider .gitignore files of the most inner repository' => [ [ '.gitignore' => "nested/*\na.txt", 'nested/.gitignore' => 'c.txt', 'nested/dir/.gitignore' => 'f.txt', ], [ '.git', 'a.txt', 'b.txt', 'nested/', 'nested/.git', 'nested/c.txt', 'nested/d.txt', 'nested/dir/', 'nested/dir/e.txt', 'nested/dir/f.txt', ], [ '.git', 'a.txt', 'b.txt', 'nested', 'nested/.git', 'nested/d.txt', 'nested/dir', 'nested/dir/e.txt', ], 'nested', ]; yield 'simple file at root' => [ [ '.gitignore' => '/a.txt', ], [ 'a.txt', 'b.txt', 'dir/', 'dir/a.txt', ], [ 'b.txt', 'dir', 'dir/a.txt', ], ]; yield 'directory' => [ [ '.gitignore' => 'dir/', ], [ 'a.txt', 'dir/', 'dir/a.txt', 'dir/b.txt', ], [ 'a.txt', ], ]; yield 'directory matching a file' => [ [ '.gitignore' => 'dir.txt/', ], [ 'dir.txt', ], [ 'dir.txt', ], ]; yield 'directory at root' => [ [ '.gitignore' => '/dir/', ], [ 'dir/', 'dir/a.txt', 'other/', 'other/dir/', 'other/dir/b.txt', ], [ 'other', 'other/dir', 'other/dir/b.txt', ], ]; yield 'simple file in nested .gitignore' => [ [ 'nested/.gitignore' => 'a.txt', ], [ 'a.txt', 'nested/', 'nested/a.txt', 'nested/nested/', 'nested/nested/a.txt', ], [ 'a.txt', 'nested', 'nested/nested', ], ]; yield 'simple file at root of nested .gitignore' => [ [ 'nested/.gitignore' => '/a.txt', ], [ 'a.txt', 'nested/', 'nested/a.txt', 'nested/nested/', 'nested/nested/a.txt', ], [ 'a.txt', 'nested', 'nested/nested', 'nested/nested/a.txt', ], ]; yield 'directory in nested .gitignore' => [ [ 'nested/.gitignore' => 'dir/', ], [ 'a.txt', 'dir/', 'dir/a.txt', 'nested/', 'nested/dir/', 'nested/dir/a.txt', 'nested/nested/', 'nested/nested/dir/', 'nested/nested/dir/a.txt', ], [ 'a.txt', 'dir', 'dir/a.txt', 'nested', 'nested/nested', ], ]; yield 'directory matching a file in nested .gitignore' => [ [ 'nested/.gitignore' => 'dir.txt/', ], [ 'dir.txt', 'nested/', 'nested/dir.txt', ], [ 'dir.txt', 'nested', 'nested/dir.txt', ], ]; yield 'directory at root of nested .gitignore' => [ [ 'nested/.gitignore' => '/dir/', ], [ 'a.txt', 'dir/', 'dir/a.txt', 'nested/', 'nested/dir/', 'nested/dir/a.txt', 'nested/nested/', 'nested/nested/dir/', 'nested/nested/dir/a.txt', ], [ 'a.txt', 'dir', 'dir/a.txt', 'nested', 'nested/nested', 'nested/nested/dir', 'nested/nested/dir/a.txt', ], ]; yield 'negated pattern in nested .gitignore' => [ [ '.gitignore' => '*.txt', 'nested/.gitignore' => "!a.txt\ndir/", ], [ 'a.txt', 'b.txt', 'nested/', 'nested/a.txt', 'nested/b.txt', 'nested/dir/', 'nested/dir/a.txt', 'nested/dir/b.txt', ], [ 'nested', 'nested/a.txt', ], ]; yield 'negated pattern in ignored nested .gitignore' => [ [ '.gitignore' => "*.txt\n/nested/", 'nested/.gitignore' => "!a.txt\ndir/", ], [ 'a.txt', 'b.txt', 'nested/', 'nested/a.txt', 'nested/b.txt', 'nested/dir/', 'nested/dir/a.txt', 'nested/dir/b.txt', ], [], ]; yield 'directory pattern negated in a subdirectory' => [ [ '.gitignore' => 'c/', 'a/.gitignore' => '!c/', ], [ 'a/', 'a/b/', 'a/b/c/', 'a/b/c/d.txt', ], [ 'a', 'a/b', 'a/b/c', 'a/b/c/d.txt', ], ]; yield 'file included from subdirectory with everything excluded' => [ [ '.gitignore' => "/a/**\n!/a/b.txt", ], [ 'a/', 'a/a.txt', 'a/b.txt', 'a/c.txt', ], [ 'a/b.txt', ], ]; } public function testAcceptAtRootDirectory() { $inner = new InnerNameIterator([__FILE__]); $iterator = new VcsIgnoredFilterIterator($inner, '/'); $this->assertIterator([__FILE__], $iterator); } private function toAbsolute(array $files): array { foreach ($files as &$path) { $path = "{$this->tmpDir}/{$path}"; } return $files; } private function removeDirectory(string $dir): void { foreach ((new Finder())->in($dir)->ignoreDotFiles(false)->depth('< 1') as $file) { $path = $file->getRealPath(); if ($file->isDir()) { $this->removeDirectory($path); } else { unlink($path); } } rmdir($dir); } }