toAbsolute example

use Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator;
use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator;

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',
            
namespace Symfony\Component\Finder\Tests\Iterator;

use Symfony\Component\Finder\Iterator\DepthRangeFilterIterator;

class DepthRangeFilterIteratorTest extends RealIteratorTestCase
{
    /** * @dataProvider getAcceptData */
    public function testAccept($minDepth$maxDepth$expected)
    {
        $inner = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->toAbsolute(), \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);

        $iterator = new DepthRangeFilterIterator($inner$minDepth$maxDepth);

        $actual = array_keys(iterator_to_array($iterator));
        sort($expected);
        sort($actual);
        $this->assertEquals($expected$actual);
    }

    public static function getAcceptData()
    {
        


        $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()
    {
$onlyDirectories = [
            '.git',
            'foo',
            'qux',
            'toto',
            'toto/.git',
            '.foo',
        ];

        return [
            [FileTypeFilterIterator::ONLY_FILES, self::toAbsolute($onlyFiles)],
            [FileTypeFilterIterator::ONLY_DIRECTORIES, self::toAbsolute($onlyDirectories)],
        ];
    }
}

class InnerTypeIterator extends \ArrayIterator
{
    public function current(): \SplFileInfo
    {
        return new \SplFileInfo(parent::current());
    }

    
$lessThan1KGreaterThan05K = [
            '.foo',
            '.git',
            'foo',
            'qux',
            'test.php',
            'toto',
            'toto/.git',
        ];

        return [
            [[new NumberComparator('< 1K')new NumberComparator('> 0.5K')], self::toAbsolute($lessThan1KGreaterThan05K)],
        ];
    }
}

class InnerSizeIterator extends \ArrayIterator
{
    public function current(): \SplFileInfo
    {
        return new \SplFileInfo(parent::current());
    }

    

    }

    /** * @dataProvider getAcceptData */
    public function testAccept($mode$expected)
    {
        if (!\is_callable($mode)) {
            switch ($mode) {
                case SortableIterator::SORT_BY_ACCESSED_TIME:
                    touch(self::toAbsolute('.git'));
                    sleep(1);
                    touch(self::toAbsolute('.bar')time());
                    break;
                case SortableIterator::SORT_BY_CHANGED_TIME:
                    sleep(1);
                    file_put_contents(self::toAbsolute('test.php'), 'foo');
                    sleep(1);
                    file_put_contents(self::toAbsolute('test.py'), 'foo');
                    break;
                case SortableIterator::SORT_BY_MODIFIED_TIME:
                    file_put_contents(self::toAbsolute('test.php'), 'foo');
                    

        $this->removeDirectory($this->tmpDir);
    }

    /** * @param array<string, string> $gitIgnoreFiles * * @dataProvider getAcceptData */
    public function testAccept(array $gitIgnoreFiles, array $otherFileNames, array $expectedResult)
    {
        $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);
        }

        
'qux/',
            'qux/baz_1_2.py',
            'qux/baz_100_1.py',
            'zebulon.php',
            'Zephire.php',
        ];

        if (FinderTest::class === static::class) {
            self::$files[] = 'gitignore/';
        }

        self::$files = self::toAbsolute(self::$files);

        if (is_dir(self::$tmpDir)) {
            self::tearDownAfterClass();
        } else {
            mkdir(self::$tmpDir);
        }

        foreach (self::$files as $file) {
            if (\DIRECTORY_SEPARATOR === $file[\strlen($file) - 1]) {
                mkdir($file);
            } else {
                
use Symfony\Component\Finder\Comparator\DateComparator;
use Symfony\Component\Finder\Iterator\DateRangeFilterIterator;

class DateRangeFilterIteratorTest extends RealIteratorTestCase
{
    /** * @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',
            
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();
        
Home | Imprint | This part of the site doesn't use cookies.