HoursFieldTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Cron\Tests;
  3. use Cron\HoursField;
  4. use DateTime;
  5. use PHPUnit_Framework_TestCase;
  6. /**
  7. * @author Michael Dowling <mtdowling@gmail.com>
  8. */
  9. class HoursFieldTest extends PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * @covers Cron\HoursField::validate
  13. */
  14. public function testValidatesField()
  15. {
  16. $f = new HoursField();
  17. $this->assertTrue($f->validate('1'));
  18. $this->assertTrue($f->validate('*'));
  19. $this->assertTrue($f->validate('*/3,1,1-12'));
  20. }
  21. /**
  22. * @covers Cron\HoursField::increment
  23. */
  24. public function testIncrementsDate()
  25. {
  26. $d = new DateTime('2011-03-15 11:15:00');
  27. $f = new HoursField();
  28. $f->increment($d);
  29. $this->assertEquals('2011-03-15 12:00:00', $d->format('Y-m-d H:i:s'));
  30. $d->setTime(11, 15, 0);
  31. $f->increment($d, true);
  32. $this->assertEquals('2011-03-15 10:59:00', $d->format('Y-m-d H:i:s'));
  33. }
  34. /**
  35. * @covers Cron\HoursField::increment
  36. */
  37. public function testIncrementsDateWithThirtyMinuteOffsetTimezone()
  38. {
  39. $tz = date_default_timezone_get();
  40. date_default_timezone_set('America/St_Johns');
  41. $d = new DateTime('2011-03-15 11:15:00');
  42. $f = new HoursField();
  43. $f->increment($d);
  44. $this->assertEquals('2011-03-15 12:00:00', $d->format('Y-m-d H:i:s'));
  45. $d->setTime(11, 15, 0);
  46. $f->increment($d, true);
  47. $this->assertEquals('2011-03-15 10:59:00', $d->format('Y-m-d H:i:s'));
  48. date_default_timezone_set($tz);
  49. }
  50. /**
  51. * @covers Cron\HoursField::increment
  52. */
  53. public function testIncrementDateWithFifteenMinuteOffsetTimezone()
  54. {
  55. $tz = date_default_timezone_get();
  56. date_default_timezone_set('Asia/Kathmandu');
  57. $d = new DateTime('2011-03-15 11:15:00');
  58. $f = new HoursField();
  59. $f->increment($d);
  60. $this->assertEquals('2011-03-15 12:00:00', $d->format('Y-m-d H:i:s'));
  61. $d->setTime(11, 15, 0);
  62. $f->increment($d, true);
  63. $this->assertEquals('2011-03-15 10:59:00', $d->format('Y-m-d H:i:s'));
  64. date_default_timezone_set($tz);
  65. }
  66. }