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\DateRangeFilterIterator;
15use Symfony\Component\Finder\Comparator\DateComparator;
16
17class DateRangeFilterIteratorTest extends RealIteratorTestCase
18{
19    /**
20     * @dataProvider getAcceptData
21     */
22    public function testAccept($size, $expected)
23    {
24        $inner = new Iterator(self::$files);
25
26        $iterator = new DateRangeFilterIterator($inner, $size);
27
28        $this->assertIterator($expected, $iterator);
29    }
30
31    public function getAcceptData()
32    {
33        $since20YearsAgo = array(
34            '.git',
35            'test.py',
36            'foo',
37            'foo/bar.tmp',
38            'test.php',
39            'toto',
40            '.bar',
41            '.foo',
42            '.foo/.bar',
43            'foo bar',
44            '.foo/bar',
45        );
46
47        $since2MonthsAgo = array(
48            '.git',
49            'test.py',
50            'foo',
51            'toto',
52            '.bar',
53            '.foo',
54            '.foo/.bar',
55            'foo bar',
56            '.foo/bar',
57        );
58
59        $untilLastMonth = array(
60            '.git',
61            'foo',
62            'foo/bar.tmp',
63            'test.php',
64            'toto',
65            '.foo',
66        );
67
68        return array(
69            array(array(new DateComparator('since 20 years ago')), $this->toAbsolute($since20YearsAgo)),
70            array(array(new DateComparator('since 2 months ago')), $this->toAbsolute($since2MonthsAgo)),
71            array(array(new DateComparator('until last month')), $this->toAbsolute($untilLastMonth)),
72        );
73    }
74}
75