-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getter for 'from', 'to' event's configuration #68
Changes from 3 commits
f04bb65
2053772
7d05c37
7e12163
6369223
a8728b5
152eef9
af2bf61
d50bec6
acbf221
0420760
fe37b71
81cf8f3
4d4017d
4bbbd01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,20 @@ class Event implements PingableInterface | |
*/ | ||
protected $timezone; | ||
|
||
/** | ||
* Datetime or time since the task is evaluated and possibly executed only for display purposes. | ||
* | ||
* @var \DateTime|string|null | ||
*/ | ||
protected $from = null; | ||
|
||
/** | ||
* Datetime or time until the task is evaluated and possibly executed only for display purposes. | ||
* | ||
* @var \DateTime|string|null | ||
*/ | ||
protected $to = null; | ||
|
||
/** | ||
* The user the command should run as. | ||
* | ||
|
@@ -447,6 +461,8 @@ public function between($from, $to) | |
*/ | ||
public function from($datetime) | ||
{ | ||
$this->from = $datetime; | ||
|
||
return $this->skip(fn () => $this->notYet($datetime)); | ||
} | ||
|
||
|
@@ -459,6 +475,8 @@ public function from($datetime) | |
*/ | ||
public function to($datetime) | ||
{ | ||
$this->to = $datetime; | ||
|
||
return $this->skip(fn () => $this->past($datetime)); | ||
} | ||
|
||
|
@@ -921,6 +939,26 @@ public function getExpression() | |
return $this->expression; | ||
} | ||
|
||
/** | ||
* Get the 'from' configuration for the event if present. | ||
* | ||
* @return \DateTime|string|null | ||
*/ | ||
public function getFrom() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use union type for return, in both cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bump. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
{ | ||
return $this->from; | ||
} | ||
|
||
/** | ||
* Get the 'to' configuration for the event if present. | ||
* | ||
* @return \DateTime|string|null | ||
*/ | ||
public function getTo() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both methods need unit tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
{ | ||
return $this->to; | ||
} | ||
|
||
/** | ||
* Set the event's command. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,6 +154,35 @@ public function test_cron_life_time(): void | |
); | ||
} | ||
|
||
public function test_cron_life_time_getters(): void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Split this test into two tests, one per method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes sir :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
{ | ||
$timezone = new \DateTimeZone('UTC'); | ||
|
||
$date_from = '2023-10-01'; | ||
$date_to = '2023-10-30'; | ||
|
||
$event = new Event($this->id, 'php foo'); | ||
$event->between($date_from, $date_to); | ||
|
||
self::assertTrue( | ||
($date_from == $event->getFrom() && $date_to == $event->getTo()) | ||
); | ||
|
||
$event = new Event($this->id, 'php foo'); | ||
$event->from($date_from); | ||
|
||
self::assertTrue( | ||
($date_from == $event->getFrom()) | ||
); | ||
|
||
$event = new Event($this->id, 'php foo'); | ||
$event->to($date_to); | ||
|
||
self::assertTrue( | ||
($date_to == $event->getTo()) | ||
); | ||
} | ||
|
||
public function test_cron_conditions(): void | ||
{ | ||
$timezone = new \DateTimeZone('UTC'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add union type (
protected \DateTime|string|null $from = null;
) in both cases.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done