TYPO3  7.6
DateComparatorTest.php
Go to the documentation of this file.
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 
15 
16 class DateComparatorTest extends \PHPUnit_Framework_TestCase
17 {
18  public function testConstructor()
19  {
20  try {
21  new DateComparator('foobar');
22  $this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.');
23  } catch (\Exception $e) {
24  $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.');
25  }
26 
27  try {
28  new DateComparator('');
29  $this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.');
30  } catch (\Exception $e) {
31  $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.');
32  }
33  }
34 
38  public function testTest($test, $match, $noMatch)
39  {
40  $c = new DateComparator($test);
41 
42  foreach ($match as $m) {
43  $this->assertTrue($c->test($m), '->test() tests a string against the expression');
44  }
45 
46  foreach ($noMatch as $m) {
47  $this->assertFalse($c->test($m), '->test() tests a string against the expression');
48  }
49  }
50 
51  public function getTestData()
52  {
53  return array(
54  array('< 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))),
55  array('until 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))),
56  array('before 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))),
57  array('> 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))),
58  array('after 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))),
59  array('since 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))),
60  array('!= 2005-10-10', array(strtotime('2005-10-11')), array(strtotime('2005-10-10'))),
61  );
62  }
63 }