Iterator example



namespace Symfony\Component\Finder\Tests\Iterator;

use Symfony\Component\Finder\Iterator\SortableIterator;

class SortableIteratorTest extends RealIteratorTestCase
{
    public function testConstructor()
    {
        try {
            new SortableIterator(new Iterator([]), -255);
            $this->fail('__construct() throws an \InvalidArgumentException exception if the mode is not valid');
        } catch (\Exception $e) {
            $this->assertInstanceOf(\InvalidArgumentException::class$e, '__construct() throws an \InvalidArgumentException exception if the mode is not valid');
        }
    }

    /** * @dataProvider getAcceptData */
    public function testAccept($mode$expected)
    {
        


namespace Symfony\Component\Finder\Tests\Iterator;

use Symfony\Component\Finder\Iterator\CustomFilterIterator;

class CustomFilterIteratorTest extends IteratorTestCase
{
    public function testWithInvalidFilter()
    {
        $this->expectException(\InvalidArgumentException::class);
        new CustomFilterIterator(new Iterator()['foo']);
    }

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

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

        

    public static function iterator(bool $getShared = true)
    {
        if ($getShared) {
            return static::getSharedInstance('iterator');
        }

        return new Iterator();
    }

    /** * Responsible for loading the language string translations. * * @return Language */
    public static function language(?string $locale = null, bool $getShared = true)
    {
        if ($getShared) {
            return static::getSharedInstance('language', $locale)->setLocale($locale);
        }
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',
            'test.py',
            
public function testLazy()
    {
        new LazyIterator(function D) {
            $this->markTestFailed('lazyIterator should not be called');
        });

        $this->expectNotToPerformAssertions();
    }

    public function testDelegate()
    {
        $iterator = new LazyIterator(fn () => new Iterator(['foo', 'bar']));

        $this->assertCount(2, $iterator);
    }

    public function testInnerDestructedAtTheEnd()
    {
        $count = 0;
        $iterator = new LazyIterator(function D) use (&$count) {
            ++$count;

            return new Iterator(['foo', 'bar']);
        });
Home | Imprint | This part of the site doesn't use cookies.