Skip to content

Commit

Permalink
JobSchedule: clones cron expression
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Dec 15, 2023
1 parent 9eb5442 commit b361654
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `ManagedScheduler`
- acquired job locks are scoped just to their id - changing run frequency or job name will not make process loose
the lock
- `CronExpression` is cloned after being added to job manager or scheduler for job immutability

### Removed

Expand Down
4 changes: 2 additions & 2 deletions src/Job/JobSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function create(
$self = new self();
$self->jobConstructor = null;
$self->job = $job;
$self->expression = $expression;
$self->expression = clone $expression;
$self->repeatAfterSeconds = $repeatAfterSeconds;

return $self;
Expand All @@ -48,7 +48,7 @@ public static function createLazy(
{
$self = new self();
$self->jobConstructor = $jobConstructor;
$self->expression = $expression;
$self->expression = clone $expression;
$self->repeatAfterSeconds = $repeatAfterSeconds;

return $self;
Expand Down
6 changes: 4 additions & 2 deletions tests/Unit/Job/JobScheduleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function test(): void
$schedule = JobSchedule::create($job, $expression, $seconds);

self::assertSame($job, $schedule->getJob());
self::assertSame($expression, $schedule->getExpression());
self::assertEquals($expression, $schedule->getExpression());
self::assertNotSame($expression, $schedule->getExpression());
self::assertSame($seconds, $schedule->getRepeatAfterSeconds());
}

Expand All @@ -35,7 +36,8 @@ public function testLazy(): void

self::assertInstanceOf(CallbackJob::class, $schedule->getJob());
self::assertSame($schedule->getJob(), $schedule->getJob());
self::assertSame($expression, $schedule->getExpression());
self::assertEquals($expression, $schedule->getExpression());
self::assertNotSame($expression, $schedule->getExpression());
self::assertSame($seconds, $schedule->getRepeatAfterSeconds());
}

Expand Down

0 comments on commit b361654

Please sign in to comment.