Skip to content

chore: fix data provider name and order by cs-fix #191

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

Merged
merged 1 commit into from
Jul 12, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
58 changes: 29 additions & 29 deletions tests/unit/CronExpressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand All @@ -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'));
}
}
44 changes: 22 additions & 22 deletions tests/unit/TaskLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand All @@ -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());
}
}
Loading