File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments