Yaffs site version 1.1
[yaffs-website] / vendor / symfony / finder / Tests / Iterator / FilterIteratorTest.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 /**
15  * @author Alex Bogomazov
16  */
17 class FilterIteratorTest extends RealIteratorTestCase
18 {
19     public function testFilterFilesystemIterators()
20     {
21         $i = new \FilesystemIterator($this->toAbsolute());
22
23         // it is expected that there are test.py test.php in the tmpDir
24         $i = $this->getMockForAbstractClass('Symfony\Component\Finder\Iterator\FilterIterator', array($i));
25         $i->expects($this->any())
26             ->method('accept')
27             ->will($this->returnCallback(function () use ($i) {
28                 return (bool) preg_match('/\.php/', (string) $i->current());
29             })
30         );
31
32         $c = 0;
33         foreach ($i as $item) {
34             ++$c;
35         }
36
37         $this->assertEquals(1, $c);
38
39         $i->rewind();
40
41         $c = 0;
42         foreach ($i as $item) {
43             ++$c;
44         }
45
46         // This would fail in php older than 5.5.23/5.6.7 with \FilterIterator
47         // but works with Symfony\Component\Finder\Iterator\FilterIterator
48         // see https://bugs.php.net/68557
49         $this->assertEquals(1, $c);
50     }
51 }