Yaffs site version 1.1
[yaffs-website] / vendor / symfony / finder / Tests / Iterator / FileTypeFilterIteratorTest.php
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
12 namespace Symfony\Component\Finder\Tests\Iterator;
13
14 use Symfony\Component\Finder\Iterator\FileTypeFilterIterator;
15
16 class FileTypeFilterIteratorTest extends RealIteratorTestCase
17 {
18     /**
19      * @dataProvider getAcceptData
20      */
21     public function testAccept($mode, $expected)
22     {
23         $inner = new InnerTypeIterator(self::$files);
24
25         $iterator = new FileTypeFilterIterator($inner, $mode);
26
27         $this->assertIterator($expected, $iterator);
28     }
29
30     public function getAcceptData()
31     {
32         $onlyFiles = array(
33             'test.py',
34             'foo/bar.tmp',
35             'test.php',
36             '.bar',
37             '.foo/.bar',
38             '.foo/bar',
39             'foo bar',
40         );
41
42         $onlyDirectories = array(
43             '.git',
44             'foo',
45             'toto',
46             'toto/.git',
47             '.foo',
48         );
49
50         return array(
51             array(FileTypeFilterIterator::ONLY_FILES, $this->toAbsolute($onlyFiles)),
52             array(FileTypeFilterIterator::ONLY_DIRECTORIES, $this->toAbsolute($onlyDirectories)),
53         );
54     }
55 }
56
57 class InnerTypeIterator extends \ArrayIterator
58 {
59     public function current()
60     {
61         return new \SplFileInfo(parent::current());
62     }
63
64     public function isFile()
65     {
66         return $this->current()->isFile();
67     }
68
69     public function isDir()
70     {
71         return $this->current()->isDir();
72     }
73 }