ScheduleCheckerTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Jobby\Tests;
  3. use Jobby\ScheduleChecker;
  4. use PHPUnit_Framework_TestCase;
  5. class ScheduleCheckerTest extends PHPUnit_Framework_TestCase
  6. {
  7. /**
  8. * @var ScheduleChecker
  9. */
  10. private $scheduleChecker;
  11. /**
  12. * @return void
  13. */
  14. protected function setUp()
  15. {
  16. parent::setUp();
  17. $this->scheduleChecker = new ScheduleChecker();
  18. }
  19. /**
  20. * @return void
  21. */
  22. public function test_it_can_detect_a_due_job_from_a_datetime_string()
  23. {
  24. $this->assertTrue($this->scheduleChecker->isDue(date('Y-m-d H:i:s')));
  25. }
  26. /**
  27. * @return void
  28. */
  29. public function test_it_can_detect_a_non_due_job_from_a_datetime_string()
  30. {
  31. $this->assertFalse($this->scheduleChecker->isDue(date('Y-m-d H:i:s', strtotime('tomorrow'))));
  32. }
  33. /**
  34. * @return void
  35. */
  36. public function test_it_can_detect_a_due_job_from_a_cron_expression()
  37. {
  38. $this->assertTrue($this->scheduleChecker->isDue("* * * * *"));
  39. }
  40. /**
  41. * @return void
  42. */
  43. public function test_it_can_detect_a_non_due_job_from_a_cron_expression()
  44. {
  45. $hour = date("H", strtotime('+1 hour'));
  46. $this->assertFalse($this->scheduleChecker->isDue("* {$hour} * * *"));
  47. }
  48. /**
  49. * @return void
  50. */
  51. public function test_it_can_use_a_closure_to_detect_a_due_job()
  52. {
  53. $this->assertTrue(
  54. $this->scheduleChecker->isDue(function() {
  55. return true;
  56. })
  57. );
  58. }
  59. /**
  60. * @return void
  61. */
  62. public function test_it_can_use_a_closure_to_detect_a_non_due_job()
  63. {
  64. $this->assertFalse(
  65. $this->scheduleChecker->isDue(function() {
  66. return false;
  67. })
  68. );
  69. }
  70. }