DateComparatorTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Finder\Tests\Comparator;
  11. use Symfony\Component\Finder\Comparator\DateComparator;
  12. class DateComparatorTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testConstructor()
  15. {
  16. try {
  17. new DateComparator('foobar');
  18. $this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.');
  19. } catch (\Exception $e) {
  20. $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.');
  21. }
  22. try {
  23. new DateComparator('');
  24. $this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.');
  25. } catch (\Exception $e) {
  26. $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.');
  27. }
  28. }
  29. /**
  30. * @dataProvider getTestData
  31. */
  32. public function testTest($test, $match, $noMatch)
  33. {
  34. $c = new DateComparator($test);
  35. foreach ($match as $m) {
  36. $this->assertTrue($c->test($m), '->test() tests a string against the expression');
  37. }
  38. foreach ($noMatch as $m) {
  39. $this->assertFalse($c->test($m), '->test() tests a string against the expression');
  40. }
  41. }
  42. public function getTestData()
  43. {
  44. return array(
  45. array('< 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))),
  46. array('until 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))),
  47. array('before 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))),
  48. array('> 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))),
  49. array('after 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))),
  50. array('since 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))),
  51. array('!= 2005-10-10', array(strtotime('2005-10-11')), array(strtotime('2005-10-10'))),
  52. );
  53. }
  54. }