Skip to content
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

Merged
merged 15 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


/**
* 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.
*
Expand Down Expand Up @@ -447,6 +461,8 @@ public function between($from, $to)
*/
public function from($datetime)
{
$this->from = $datetime;

return $this->skip(fn () => $this->notYet($datetime));
}

Expand All @@ -459,6 +475,8 @@ public function from($datetime)
*/
public function to($datetime)
{
$this->to = $datetime;

return $this->skip(fn () => $this->past($datetime));
}

Expand Down Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use union type for return, in both cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both methods need unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
return $this->to;
}

/**
* Set the event's command.
*
Expand Down
29 changes: 29 additions & 0 deletions tests/Unit/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,35 @@ public function test_cron_life_time(): void
);
}

public function test_cron_life_time_getters(): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split this test into two tests, one per method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sir :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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');
Expand Down
Loading