Skip to content

Commit

Permalink
Fix: Use generators
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Nov 2, 2023
1 parent 28a8f3f commit d1c4528
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
13 changes: 10 additions & 3 deletions test/Unit/Formatter/DefaultDurationFormatterTest.php
Expand Up @@ -34,11 +34,11 @@ public function testFormatFormats(
}

/**
* @return array<string, array{0: Duration, 1: string}>
* @return \Generator<string, array{0: Duration, 1: string}>
*/
public static function provideDurationAndFormattedDuration(): array
public static function provideDurationAndFormattedDuration(): \Generator
{
return [
$values = [
'zero' => [
Duration::fromSecondsAndNanoseconds(
0,
Expand Down Expand Up @@ -96,5 +96,12 @@ public static function provideDurationAndFormattedDuration(): array
'12:34:56.789',
],
];

foreach ($values as $key => [$duration, $formattedDuration]) {
yield $key => [
$duration,
$formattedDuration,
];
}
}
}
31 changes: 25 additions & 6 deletions test/Unit/TimeTest.php
Expand Up @@ -94,11 +94,11 @@ public function testDurationRejectsStartGreaterThanEnd(
}

/**
* @return array<string, array{0: int, 1: int, 2: int, 3: int}>
* @return \Generator<string, array{0: int, 1: int, 2: int, 3: int}>
*/
public static function provideStartGreaterThanEnd(): array
public static function provideStartGreaterThanEnd(): \Generator
{
return [
$values = [
'seconds-greater' => [
11,
1,
Expand All @@ -118,6 +118,15 @@ public static function provideStartGreaterThanEnd(): array
0,
],
];

foreach ($values as $key => [$startSeconds, $startNanoseconds, $endSeconds, $endNanoseconds]) {
yield $key => [
$startSeconds,
$startNanoseconds,
$endSeconds,
$endNanoseconds,
];
}
}

#[Framework\Attributes\DataProvider('provideStartEndAndDuration')]
Expand All @@ -142,11 +151,11 @@ public function testDurationReturnsDifferenceBetweenEndAndStart(
}

/**
* @return array<string, array{0: int, 1: int, 2: int, 3: int, 4: Duration}>
* @return \Generator<string, array{0: int, 1: int, 2: int, 3: int, 4: Duration}>
*/
public static function provideStartEndAndDuration(): array
public static function provideStartEndAndDuration(): \Generator
{
return [
$values = [
'start-equal-to-end' => [
10,
50,
Expand Down Expand Up @@ -178,5 +187,15 @@ public static function provideStartEndAndDuration(): array
),
],
];

foreach ($values as $key => [$startSeconds, $startNanoseconds, $endSeconds, $endNanoseconds, $duration]) {
yield $key => [
$startSeconds,
$startNanoseconds,
$endSeconds,
$endNanoseconds,
$duration,
];
}
}
}

0 comments on commit d1c4528

Please sign in to comment.