class RegexDirectoryIteratorTest

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/FileSystem/RegexDirectoryIteratorTest.php \Drupal\Tests\Component\FileSystem\RegexDirectoryIteratorTest
  2. 8.9.x core/tests/Drupal/Tests/Component/FileSystem/RegexDirectoryIteratorTest.php \Drupal\Tests\Component\FileSystem\RegexDirectoryIteratorTest
  3. 11.x core/tests/Drupal/Tests/Component/FileSystem/RegexDirectoryIteratorTest.php \Drupal\Tests\Component\FileSystem\RegexDirectoryIteratorTest

@coversDefaultClass \Drupal\Component\FileSystem\RegexDirectoryIterator @group FileSystem

Hierarchy

Expanded class hierarchy of RegexDirectoryIteratorTest

File

core/tests/Drupal/Tests/Component/FileSystem/RegexDirectoryIteratorTest.php, line 15

Namespace

Drupal\Tests\Component\FileSystem
View source
class RegexDirectoryIteratorTest extends TestCase {
    
    /**
     * @covers ::accept
     * @dataProvider providerTestRegexDirectoryIterator
     */
    public function testRegexDirectoryIterator(array $directory, $regex, array $expected) : void {
        vfsStream::setup('root', NULL, $directory);
        $iterator = new RegexDirectoryIterator(vfsStream::url('root'), $regex);
        // Create an array of filenames to assert against.
        $file_list = array_map(function (\SplFileInfo $file) {
            return $file->getFilename();
        }, array_values(iterator_to_array($iterator)));
        $this->assertSame($expected, $file_list);
    }
    
    /**
     * Provider for self::testRegexDirectoryIterator().
     */
    public static function providerTestRegexDirectoryIterator() {
        return [
            [
                [
                    '1.yml' => '',
                ],
                '/\\.yml$/',
                [
                    '1.yml',
                ],
            ],
            [
                [
                    '1.yml' => '',
                    '2.yml' => '',
                    '3.txt' => '',
                ],
                '/\\.yml$/',
                [
                    '1.yml',
                    '2.yml',
                ],
            ],
            [
                [
                    '1.yml' => '',
                    '2.yml' => '',
                    '3.txt' => '',
                ],
                '/\\.txt/',
                [
                    '3.txt',
                ],
            ],
            [
                [
                    '1.yml' => '',
                    // Ensure we don't recurse in directories even if that match the
                    // regex.
'2.yml' => [
                        '3.yml' => '',
                        '4.yml' => '',
                    ],
                    '3.txt' => '',
                ],
                '/\\.yml$/',
                [
                    '1.yml',
                ],
            ],
            [
                [
                    '1.yml' => '',
                    '2.yml' => '',
                    '3.txt' => '',
                ],
                '/^\\d/',
                [
                    '1.yml',
                    '2.yml',
                    '3.txt',
                ],
            ],
            [
                [
                    '1.yml' => '',
                    '2.yml' => '',
                    '3.txt' => '',
                ],
                '/^\\D/',
                [],
            ],
        ];
    }

}

Members

Title Sort descending Modifiers Object type Summary
RegexDirectoryIteratorTest::providerTestRegexDirectoryIterator public static function Provider for self::testRegexDirectoryIterator().
RegexDirectoryIteratorTest::testRegexDirectoryIterator public function @covers ::accept
@dataProvider providerTestRegexDirectoryIterator

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.