菜谱项目

DateComparatorTest.php 2.4KB

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