4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Finder\Tests\Comparator;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Finder\Comparator\DateComparator;
17 class DateComparatorTest extends TestCase
19 public function testConstructor()
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.');
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.');
37 * @dataProvider getTestData
39 public function testTest($test, $match, $noMatch)
41 $c = new DateComparator($test);
43 foreach ($match as $m) {
44 $this->assertTrue($c->test($m), '->test() tests a string against the expression');
47 foreach ($noMatch as $m) {
48 $this->assertFalse($c->test($m), '->test() tests a string against the expression');
52 public function getTestData()
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'))),