diff --git a/CHANGELOG.md b/CHANGELOG.md index 5722272..96c8acf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,3 +42,8 @@ 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 + +### Fixed + +- `ListCommand` + - Fix numeric job ids in case option --next is used diff --git a/src/Command/ListCommand.php b/src/Command/ListCommand.php index f8b5fda..4633eac 100644 --- a/src/Command/ListCommand.php +++ b/src/Command/ListCommand.php @@ -17,7 +17,6 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Terminal; use function abs; -use function array_splice; use function floor; use function max; use function mb_strlen; @@ -173,7 +172,18 @@ private function sortJobs(array $jobs, $next): array }); if ($next !== true) { - array_splice($jobs, $next); + $slicedJobs = []; + $count = 0; + foreach ($jobs as $key => $value) { + if ($count >= $next) { + break; + } + + $slicedJobs[$key] = $value; + $count++; + } + + $jobs = $slicedJobs; } } else { /** @infection-ignore-all */ diff --git a/tests/Unit/Command/ListCommandTest.php b/tests/Unit/Command/ListCommandTest.php index bd4b8ff..9cdd5c5 100644 --- a/tests/Unit/Command/ListCommandTest.php +++ b/tests/Unit/Command/ListCommandTest.php @@ -250,9 +250,9 @@ public function testNext(): void self::assertSame( <<<'MSG' - * * * * * / 1 [0] Tests\Orisai\Scheduler\Doubles\CallbackList::job1()........ Next Due: 1 second - * * * * * [1] Tests\Orisai\Scheduler\Doubles\CallbackList::job1()...... Next Due: 59 seconds - * * * * * [2] Tests\Orisai\Scheduler\Doubles\CallbackList::job1()...... Next Due: 59 seconds + * * * * * / 1 [5] Tests\Orisai\Scheduler\Doubles\CallbackList::job1()........ Next Due: 1 second + * * * * * [4] Tests\Orisai\Scheduler\Doubles\CallbackList::job1()...... Next Due: 59 seconds + * * * * * [6] Tests\Orisai\Scheduler\Doubles\CallbackList::job1()...... Next Due: 59 seconds 2 * * * * [3] Tests\Orisai\Scheduler\Doubles\CallbackList::job1()........ Next Due: 1 minute MSG,