Yaffs site version 1.1
[yaffs-website] / vendor / symfony / finder / Tests / Iterator / FilecontentFilterIteratorTest.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\FilecontentFilterIterator;
15
16 class FilecontentFilterIteratorTest extends IteratorTestCase
17 {
18     public function testAccept()
19     {
20         $inner = new MockFileListIterator(array('test.txt'));
21         $iterator = new FilecontentFilterIterator($inner, array(), array());
22         $this->assertIterator(array('test.txt'), $iterator);
23     }
24
25     public function testDirectory()
26     {
27         $inner = new MockFileListIterator(array('directory'));
28         $iterator = new FilecontentFilterIterator($inner, array('directory'), array());
29         $this->assertIterator(array(), $iterator);
30     }
31
32     public function testUnreadableFile()
33     {
34         $inner = new MockFileListIterator(array('file r-'));
35         $iterator = new FilecontentFilterIterator($inner, array('file r-'), array());
36         $this->assertIterator(array(), $iterator);
37     }
38
39     /**
40      * @dataProvider getTestFilterData
41      */
42     public function testFilter(\Iterator $inner, array $matchPatterns, array $noMatchPatterns, array $resultArray)
43     {
44         $iterator = new FilecontentFilterIterator($inner, $matchPatterns, $noMatchPatterns);
45         $this->assertIterator($resultArray, $iterator);
46     }
47
48     public function getTestFilterData()
49     {
50         $inner = new MockFileListIterator();
51
52         $inner[] = new MockSplFileInfo(array(
53             'name' => 'a.txt',
54             'contents' => 'Lorem ipsum...',
55             'type' => 'file',
56             'mode' => 'r+', )
57         );
58
59         $inner[] = new MockSplFileInfo(array(
60             'name' => 'b.yml',
61             'contents' => 'dolor sit...',
62             'type' => 'file',
63             'mode' => 'r+', )
64         );
65
66         $inner[] = new MockSplFileInfo(array(
67             'name' => 'some/other/dir/third.php',
68             'contents' => 'amet...',
69             'type' => 'file',
70             'mode' => 'r+', )
71         );
72
73         $inner[] = new MockSplFileInfo(array(
74             'name' => 'unreadable-file.txt',
75             'contents' => false,
76             'type' => 'file',
77             'mode' => 'r+', )
78         );
79
80         return array(
81             array($inner, array('.'), array(), array('a.txt', 'b.yml', 'some/other/dir/third.php')),
82             array($inner, array('ipsum'), array(), array('a.txt')),
83             array($inner, array('i', 'amet'), array('Lorem', 'amet'), array('b.yml')),
84         );
85     }
86 }