1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Finder\Tests\Iterator;
13
14use Symfony\Component\Finder\Iterator\FilenameFilterIterator;
15
16class FilenameFilterIteratorTest extends IteratorTestCase
17{
18    /**
19     * @dataProvider getAcceptData
20     */
21    public function testAccept($matchPatterns, $noMatchPatterns, $expected)
22    {
23        $inner = new InnerNameIterator(['test.php', 'test.py', 'foo.php']);
24
25        $iterator = new FilenameFilterIterator($inner, $matchPatterns, $noMatchPatterns);
26
27        $this->assertIterator($expected, $iterator);
28    }
29
30    public function getAcceptData()
31    {
32        return [
33            [['test.*'], [], ['test.php', 'test.py']],
34            [[], ['test.*'], ['foo.php']],
35            [['*.php'], ['test.*'], ['foo.php']],
36            [['*.php', '*.py'], ['foo.*'], ['test.php', 'test.py']],
37            [['/\.php$/'], [], ['test.php', 'foo.php']],
38            [[], ['/\.php$/'], ['test.py']],
39        ];
40    }
41}
42
43class InnerNameIterator extends \ArrayIterator
44{
45    public function current()
46    {
47        return new \SplFileInfo(parent::current());
48    }
49
50    public function getFilename()
51    {
52        return parent::current();
53    }
54}
55