Skip to content

Commit 296441f

Browse files
test fix for duplicates
1 parent feab359 commit 296441f

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

tests/structures/StructureLayer.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ class StructureLayer extends TestLayer
1818
*/
1919
public static int $iterations = 50;
2020

21+
/**
22+
* @var array<int> List of already generated timestamps to avoid duplicates
23+
*/
24+
private array $generatedTimestamps = [];
25+
2126
public function providerTimestamp(): \Generator
2227
{
2328
for ($i = 0; $i < self::$iterations; $i++) {
24-
$ts = $this->randomTimestamp();
29+
do {
30+
$ts = $this->randomTimestamp();
31+
} while (in_array($ts, $this->generatedTimestamps, true));
32+
$this->generatedTimestamps[] = $ts;
2533
yield 'ts: ' . $ts => [$ts];
2634
}
2735
}
@@ -30,7 +38,10 @@ public function providerTimestampTimezone(): \Generator
3038
{
3139
for ($i = 0; $i < self::$iterations; $i++) {
3240
$tz = \DateTimeZone::listIdentifiers()[array_rand(\DateTimeZone::listIdentifiers())];
33-
$ts = $this->randomTimestamp($tz);
41+
do {
42+
$ts = $this->randomTimestamp($tz);
43+
} while (in_array($ts, $this->generatedTimestamps, true));
44+
$this->generatedTimestamps[] = $ts;
3445
yield 'ts: ' . $ts . ' tz: ' . $tz => [$ts, $tz];
3546
}
3647
}

0 commit comments

Comments
 (0)