assertIterator example

class FileTypeFilterIteratorTest extends RealIteratorTestCase
{
    /** * @dataProvider getAcceptData */
    public function testAccept($mode$expected)
    {
        $inner = new InnerTypeIterator(self::$files);

        $iterator = new FileTypeFilterIterator($inner$mode);

        $this->assertIterator($expected$iterator);
    }

    public static function getAcceptData()
    {
        $onlyFiles = [
            'test.py',
            'foo/bar.tmp',
            'test.php',
            '.bar',
            '.foo/.bar',
            '.foo/bar',
            
class SizeRangeFilterIteratorTest extends RealIteratorTestCase
{
    /** * @dataProvider getAcceptData */
    public function testAccept($size$expected)
    {
        $inner = new InnerSizeIterator(self::$files);

        $iterator = new SizeRangeFilterIterator($inner$size);

        $this->assertIterator($expected$iterator);
    }

    public static function getAcceptData()
    {
        $lessThan1KGreaterThan05K = [
            '.foo',
            '.git',
            'foo',
            'qux',
            'test.php',
            'toto',
            


    /** * @dataProvider getAcceptData */
    public function testAccept($filters$expected)
    {
        $inner = new Iterator(['test.php', 'test.py', 'foo.php']);

        $iterator = new CustomFilterIterator($inner$filters);

        $this->assertIterator($expected$iterator);
    }

    public static function getAcceptData()
    {
        return [
            [[fn (\SplFileInfo $fileinfo) => false][]],
            [[fn (\SplFileInfo $fileinfo) => str_starts_with($fileinfo, 'test')]['test.php', 'test.py']],
            [['is_dir'][]],
        ];
    }
}
class ExcludeDirectoryFilterIteratorTest extends RealIteratorTestCase
{
    /** * @dataProvider getAcceptData */
    public function testAccept($directories$expected)
    {
        $inner = new \RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->toAbsolute(), \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);

        $iterator = new ExcludeDirectoryFilterIterator($inner$directories);

        $this->assertIterator($expected$iterator);
    }

    public static function getAcceptData()
    {
        $foo = [
            '.bar',
            '.foo',
            '.foo/.bar',
            '.foo/bar',
            '.git',
            'test.py',
            
use Symfony\Component\Finder\Iterator\PathFilterIterator;

class PathFilterIteratorTest extends IteratorTestCase
{
    /** * @dataProvider getTestFilterData */
    public function testFilter(\Iterator $inner, array $matchPatterns, array $noMatchPatterns, array $resultArray)
    {
        $iterator = new PathFilterIterator($inner$matchPatterns$noMatchPatterns);
        $this->assertIterator($resultArray$iterator);
    }

    public static function getTestFilterData()
    {
        $inner = new MockFileListIterator();

        // PATH: A/B/C/abc.dat         $inner[] = new MockSplFileInfo([
            'name' => 'abc.dat',
            'relativePathname' => 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
        ]);

        
class FinderTest extends Iterator\RealIteratorTestCase
{
    public function testCreate()
    {
        $this->assertInstanceOf(Finder::class, Finder::create());
    }

    public function testDirectories()
    {
        $finder = $this->buildFinder();
        $this->assertSame($finder$finder->directories());
        $this->assertIterator($this->toAbsolute(['foo', 'qux', 'toto'])$finder->in(self::$tmpDir)->getIterator());

        $finder = $this->buildFinder();
        $finder->directories();
        $finder->files();
        $finder->directories();
        $this->assertIterator($this->toAbsolute(['foo', 'qux', 'toto'])$finder->in(self::$tmpDir)->getIterator());
    }

    public function testFiles()
    {
        $finder = $this->buildFinder();
        
class FilenameFilterIteratorTest extends IteratorTestCase
{
    /** * @dataProvider getAcceptData */
    public function testAccept($matchPatterns$noMatchPatterns$expected)
    {
        $inner = new InnerNameIterator(['test.php', 'test.py', 'foo.php']);

        $iterator = new FilenameFilterIterator($inner$matchPatterns$noMatchPatterns);

        $this->assertIterator($expected$iterator);
    }

    public static function getAcceptData()
    {
        return [
            [['test.*'][]['test.php', 'test.py']],
            [[]['test.*']['foo.php']],
            [['*.php']['test.*']['foo.php']],
            [['*.php', '*.py']['foo.*']['test.php', 'test.py']],
            [['/\.php$/'][]['test.php', 'foo.php']],
            [[]['/\.php$/']['test.py']],
        ];

        }

        foreach ($gitIgnoreFiles as $path => $content) {
            file_put_contents("{$this->tmpDir}/{$path}", $content);
        }

        $inner = new InnerNameIterator($otherFileNames);

        $iterator = new VcsIgnoredFilterIterator($inner$this->tmpDir);

        $this->assertIterator($this->toAbsolute($expectedResult)$iterator);
    }

    public static function getAcceptData(): iterable
    {
        yield 'simple file' => [
            [
                '.gitignore' => 'a.txt',
            ],
            [
                'a.txt',
                'b.txt',
                
namespace Symfony\Component\Finder\Tests\Iterator;

use Symfony\Component\Finder\Iterator\FilecontentFilterIterator;

class FilecontentFilterIteratorTest extends IteratorTestCase
{
    public function testAccept()
    {
        $inner = new MockFileListIterator(['test.txt']);
        $iterator = new FilecontentFilterIterator($inner[][]);
        $this->assertIterator(['test.txt']$iterator);
    }

    public function testDirectory()
    {
        $inner = new MockFileListIterator(['directory']);
        $iterator = new FilecontentFilterIterator($inner['directory'][]);
        $this->assertIterator([]$iterator);
    }

    public function testUnreadableFile()
    {
        
$finder = $this->buildFinder();
        $this->assertSame(
            $finder,
            $finder
                ->ignoreVCS(true)
                ->ignoreDotFiles(true)
                ->ignoreVCSIgnored(true)
        );

        $this->iniSet('open_basedir', \dirname(__DIR__, 5).\PATH_SEPARATOR.self::toAbsolute('gitignore/search_root'));

        $this->assertIterator(self::toAbsolute([
            'gitignore/search_root/b.txt',
            'gitignore/search_root/c.txt',
            'gitignore/search_root/dir',
            'gitignore/search_root/dir/a.txt',
            'gitignore/search_root/dir/c.txt',
        ])$finder->in(self::toAbsolute('gitignore/search_root'))->getIterator());
    }

    protected function buildFinder()
    {
        return Finder::create()->exclude('gitignore');
    }
/** * @dataProvider getAcceptData */
    public function testAccept($size$expected)
    {
        $files = self::$files;
        $files[] = static::toAbsolute('doesnotexist');
        $inner = new Iterator($files);

        $iterator = new DateRangeFilterIterator($inner$size);

        $this->assertIterator($expected$iterator);
    }

    public static function getAcceptData()
    {
        $since20YearsAgo = [
            '.git',
            'test.py',
            'foo',
            'foo/bar.tmp',
            'test.php',
            'toto',
            
Home | Imprint | This part of the site doesn't use cookies.