From 0806cecb0599b600f281337448f66080aecde8ac Mon Sep 17 00:00:00 2001 From: michalsn Date: Sat, 12 Jul 2025 09:29:28 +0200 Subject: [PATCH] chore: fix data provider name and order by cs-fix --- tests/unit/CronExpressionTest.php | 58 +++++++++++++++---------------- tests/unit/TaskLogTest.php | 44 +++++++++++------------ 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/tests/unit/CronExpressionTest.php b/tests/unit/CronExpressionTest.php index 8655f0b..283651d 100644 --- a/tests/unit/CronExpressionTest.php +++ b/tests/unit/CronExpressionTest.php @@ -154,6 +154,28 @@ public function testEveryHour($hourTrue, $hourFalse) $this->assertFalse($this->cron->shouldRun('00 * * * *')); } + public static function provideEveryHour(): iterable + { + $hours24 = array_map(static fn ($h) => [ + $h . ':00', + $h . ':10', + ], range(0, 23)); + $hoursAM = array_map(static fn ($h) => [ + $h . ':00 AM', + $h . ':10 AM', + ], range(1, 12)); + $hoursPM = array_map(static fn ($h) => [ + $h . ':00 PM', + $h . ':10 PM', + ], range(1, 12)); + + return [ + ...$hours24, + ...$hoursAM, + ...$hoursPM, + ]; + } + public function testQuarterPastHour() { $this->cron->testTime('6:15 PM'); @@ -192,26 +214,15 @@ public function testEveryWeekdayInMonth() $this->assertFalse($this->cron->shouldRun('0 20 * 10 1-5')); } - public static function provideEveryHour(): iterable + #[DataProvider('provideNextRun')] + public function testNextRun(string $exp, string $expected) { - $hours24 = array_map(static fn ($h) => [ - $h . ':00', - $h . ':10', - ], range(0, 23)); - $hoursAM = array_map(static fn ($h) => [ - $h . ':00 AM', - $h . ':10 AM', - ], range(1, 12)); - $hoursPM = array_map(static fn ($h) => [ - $h . ':00 PM', - $h . ':10 PM', - ], range(1, 12)); + $this->cron->testTime('October 5, 2020 8:00 pm'); - return [ - ...$hours24, - ...$hoursAM, - ...$hoursPM, - ]; + $next = $this->cron->nextRun($exp); + + $this->assertInstanceOf(Time::class, $next); + $this->assertSame($expected, $next->format('F j, Y g:i a')); } public static function provideNextRun(): iterable @@ -237,15 +248,4 @@ public static function provideNextRun(): iterable ['* * * * 6,0', 'October 9, 2020 8:00 pm'], ]; } - - #[DataProvider('provideNextRun')] - public function testNextRun(string $exp, string $expected) - { - $this->cron->testTime('October 5, 2020 8:00 pm'); - - $next = $this->cron->nextRun($exp); - - $this->assertInstanceOf(Time::class, $next); - $this->assertSame($expected, $next->format('F j, Y g:i a')); - } } diff --git a/tests/unit/TaskLogTest.php b/tests/unit/TaskLogTest.php index cb9549e..e79aa0c 100644 --- a/tests/unit/TaskLogTest.php +++ b/tests/unit/TaskLogTest.php @@ -22,6 +22,28 @@ */ final class TaskLogTest extends TestCase { + /** + * @param array|bool|int|string|null $output + * + * @throws Exception + */ + #[DataProvider('provideDuration')] + public function testDuration(string $start, string $end, string $expected, $output) + { + $start = new Time($start); + $end = new Time($end); + + $log = new TaskLog([ + 'task' => new Task('closure', static function () {}), + 'output' => $output, + 'runStart' => $start, + 'runEnd' => $end, + 'error' => null, + ]); + + $this->assertSame($expected, $log->duration()); + } + public static function provideDuration(): iterable { return [ @@ -45,26 +67,4 @@ public static function provideDuration(): iterable ], ]; } - - /** - * @param array|bool|int|string|null $output - * - * @throws Exception - */ - #[DataProvider('provideDuration')] - public function testDuration(string $start, string $end, string $expected, $output) - { - $start = new Time($start); - $end = new Time($end); - - $log = new TaskLog([ - 'task' => new Task('closure', static function () {}), - 'output' => $output, - 'runStart' => $start, - 'runEnd' => $end, - 'error' => null, - ]); - - $this->assertSame($expected, $log->duration()); - } }