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 10 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
30 changes: 30 additions & 0 deletions src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ class Event implements PingableInterface
*/
protected $timezone;

/**
* Datetime or time since the task is evaluated and possibly executed only for display purposes.
*/
protected \DateTime|string|null $from = null;

/**
* Datetime or time until the task is evaluated and possibly executed only for display purposes.
*/
protected \DateTime|string|null $to = null;

/**
* The user the command should run as.
*
Expand Down Expand Up @@ -447,6 +457,8 @@ public function between($from, $to)
*/
public function from($datetime)
{
$this->from = $datetime;

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

Expand All @@ -459,6 +471,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 +935,22 @@ public function getExpression()
return $this->expression;
}

/**
* Get the 'from' configuration for the event if present.
*/
public function getFrom(): \DateTime|string|null
{
return $this->from;
}

/**
* Get the 'to' configuration for the event if present.
*/
public function getTo(): \DateTime|string|null
{
return $this->to;
}

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

public function test_get_from(): void
Copy link
Member

Choose a reason for hiding this comment

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

What about "use data provider (can be one for both cases) to test string and \DateTime in from/to"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In progress.

{
$timezone = new \DateTimeZone('UTC');

$dateFrom = '2023-10-01';

$event = new Event($this->id, 'php foo');
$event->from($dateFrom);

self::assertSame($dateFrom, $event->getFrom());
}

public function test_get_to(): void
{
$timezone = new \DateTimeZone('UTC');
Copy link
Member

Choose a reason for hiding this comment

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

Looks like $timezone is not used in any test, should be removed.


$dateTo = '2023-10-30';

$event = new Event($this->id, 'php foo');
$event->to($dateTo);

self::assertSame($dateTo, $event->getTo());
}

public function test_get_between(): void
{
$timezone = new \DateTimeZone('UTC');

$dateFrom = '2023-10-01';
$dateTo = '2023-10-30';

$event = new Event($this->id, 'php foo');
$event->between($dateFrom, $dateTo);

self::assertSame($dateFrom, $event->getFrom());

self::assertSame($dateTo, $event->getTo());
}

public function test_cron_conditions(): void
{
$timezone = new \DateTimeZone('UTC');
Expand Down