scratch – Blame information for rev 122
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
120 | office | 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\Comparator; |
||
13 | |||
14 | use PHPUnit\Framework\TestCase; |
||
15 | use Symfony\Component\Finder\Comparator\DateComparator; |
||
16 | |||
17 | class DateComparatorTest extends TestCase |
||
18 | { |
||
19 | public function testConstructor() |
||
20 | { |
||
21 | try { |
||
22 | new DateComparator('foobar'); |
||
23 | $this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.'); |
||
24 | } catch (\Exception $e) { |
||
25 | $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.'); |
||
26 | } |
||
27 | |||
28 | try { |
||
29 | new DateComparator(''); |
||
30 | $this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.'); |
||
31 | } catch (\Exception $e) { |
||
32 | $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.'); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @dataProvider getTestData |
||
38 | */ |
||
39 | public function testTest($test, $match, $noMatch) |
||
40 | { |
||
41 | $c = new DateComparator($test); |
||
42 | |||
43 | foreach ($match as $m) { |
||
44 | $this->assertTrue($c->test($m), '->test() tests a string against the expression'); |
||
45 | } |
||
46 | |||
47 | foreach ($noMatch as $m) { |
||
48 | $this->assertFalse($c->test($m), '->test() tests a string against the expression'); |
||
49 | } |
||
50 | } |
||
51 | |||
52 | public function getTestData() |
||
53 | { |
||
54 | return array( |
||
55 | array('< 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))), |
||
56 | array('until 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))), |
||
57 | array('before 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))), |
||
58 | array('> 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))), |
||
59 | array('after 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))), |
||
60 | array('since 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))), |
||
61 | array('!= 2005-10-10', array(strtotime('2005-10-11')), array(strtotime('2005-10-10'))), |
||
62 | ); |
||
63 | } |
||
64 | } |