Skip to content

Commit 77cec4d

Browse files
authored
Fix: Do not use deprecated MT_RAND_PHP constant on PHP 8.3 (#844)
1 parent 93bcd9e commit 77cec4d

20 files changed

+150
-5
lines changed

.github/workflows/tests.yaml

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ jobs:
2222
- "8.0"
2323
- "8.1"
2424
- "8.2"
25-
include:
26-
- experimental: true
27-
php-version: "8.3"
25+
- "8.3"
2826

2927
runs-on: "ubuntu-latest"
3028

@@ -57,4 +55,3 @@ jobs:
5755

5856
- name: "Run tests"
5957
run: "./vendor/bin/phpunit --colors=always"
60-
continue-on-error: "${{ matrix.experimental }}"

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Fixed polish license plates (#685)
77
- Stopped using `static` in callables in `Provider\pt_BR\PhoneNumber` (#785)
88
- Fixed incorrect female name (#794)
9+
- Stopped using the deprecated `MT_RAND_PHP` constant to seed the random generator on PHP 8.3 (#844)
910

1011
## [2023-06-12, v1.23.0](https://github.com/FakerPHP/Faker/compare/v1.22.0..v1.23.0)
1112

src/Faker/Generator.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,22 @@ public function seed($seed = null)
687687
if ($seed === null) {
688688
mt_srand();
689689
} else {
690-
mt_srand((int) $seed, MT_RAND_PHP);
690+
mt_srand((int) $seed, self::mode());
691691
}
692692
}
693693

694+
/**
695+
* @see https://www.php.net/manual/en/migration83.deprecated.php#migration83.deprecated.random
696+
*/
697+
private static function mode(): int
698+
{
699+
if (PHP_VERSION_ID < 80300) {
700+
return MT_RAND_PHP;
701+
}
702+
703+
return MT_RAND_MT19937;
704+
}
705+
694706
public function format($format, $arguments = [])
695707
{
696708
return call_user_func_array($this->getFormatter($format), $arguments);

test/Faker/Core/DateTimeTest.php

+48
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ protected function setUp(): void
2424
$this->extension = $this->faker->ext(DateTimeExtension::class);
2525
}
2626

27+
/**
28+
* @requires PHP < 8.3
29+
*/
2730
public function testDateTime(): void
2831
{
2932
$dateTime = $this->extension->dateTime('2005-10-19T14:12:00');
@@ -32,6 +35,9 @@ public function testDateTime(): void
3235
self::assertEquals(new \DateTime('1990-09-29T12:12:53'), $dateTime);
3336
}
3437

38+
/**
39+
* @requires PHP < 8.3
40+
*/
3541
public function testDateTimeWithTimezone(): void
3642
{
3743
$dateTime = $this->extension->dateTime('2021-09-05T15:10:00', 'America/Los_Angeles');
@@ -41,6 +47,9 @@ public function testDateTimeWithTimezone(): void
4147
self::assertEquals(new \DateTimeZone('America/Los_Angeles'), $dateTime->getTimezone());
4248
}
4349

50+
/**
51+
* @requires PHP < 8.3
52+
*/
4453
public function testDateTimeAD(): void
4554
{
4655
$dateTime = $this->extension->dateTimeAD('2012-04-12T19:22:23');
@@ -49,6 +58,9 @@ public function testDateTimeAD(): void
4958
self::assertEquals(new \DateTime('1166-06-01T17:43:42'), $dateTime);
5059
}
5160

61+
/**
62+
* @requires PHP < 8.3
63+
*/
5264
public function testDateTimeBetween(): void
5365
{
5466
$dateTime = $this->extension->dateTimeBetween('1998-12-18T11:23:40', '2004-09-15T22:10:45');
@@ -63,6 +75,9 @@ public function testDateTimeBetweenShouldThrowIfFromIsNotAnteriorToUntil(): void
6375
$this->extension->dateTimeBetween('2004-09-15T22:10:45', '1998-12-18T11:23:40');
6476
}
6577

78+
/**
79+
* @requires PHP < 8.3
80+
*/
6681
public function testDateTimeInInterval(): void
6782
{
6883
$dateTime = $this->extension->dateTimeInInterval('1999-07-16T17:30:12', '+2 years');
@@ -120,6 +135,9 @@ public function testDateTimeThisCentury(): void
120135
self::assertLessThanOrEqual(new \DateTime('now'), $dateTime);
121136
}
122137

138+
/**
139+
* @requires PHP < 8.3
140+
*/
123141
public function testDate(): void
124142
{
125143
$date = $this->extension->date('Y-m-d', '2102-11-12T14:45:29');
@@ -128,6 +146,9 @@ public function testDate(): void
128146
self::assertEquals('2046-12-26', $date);
129147
}
130148

149+
/**
150+
* @requires PHP < 8.3
151+
*/
131152
public function testTime(): void
132153
{
133154
$time = $this->extension->time('H:i:s', '1978-06-27T09:43:21');
@@ -136,6 +157,9 @@ public function testTime(): void
136157
self::assertEquals('21:59:44', $time);
137158
}
138159

160+
/**
161+
* @requires PHP < 8.3
162+
*/
139163
public function testUnixTime(): void
140164
{
141165
$unixTime = $this->extension->unixTime('1993-08-29T15:10:00');
@@ -144,6 +168,9 @@ public function testUnixTime(): void
144168
self::assertEquals(432630664, $unixTime);
145169
}
146170

171+
/**
172+
* @requires PHP < 8.3
173+
*/
147174
public function testUnitTimeWithNumericUntil(): void
148175
{
149176
$unixTime = $this->extension->unixTime(1643830258);
@@ -152,6 +179,9 @@ public function testUnitTimeWithNumericUntil(): void
152179
self::assertEquals(952499510, $unixTime);
153180
}
154181

182+
/**
183+
* @requires PHP < 8.3
184+
*/
155185
public function testIso8601(): void
156186
{
157187
$iso8601 = $this->extension->iso8601('1993-07-11T15:10:00');
@@ -170,6 +200,9 @@ public function testAmPm(): void
170200
self::assertContains($amPm, ['am', 'pm']);
171201
}
172202

203+
/**
204+
* @requires PHP < 8.3
205+
*/
173206
public function testDayOfMonth(): void
174207
{
175208
$dayOfMonth = $this->extension->dayOfMonth('2001-04-29T15:10:12');
@@ -178,6 +211,9 @@ public function testDayOfMonth(): void
178211
self::assertEquals('25', $dayOfMonth);
179212
}
180213

214+
/**
215+
* @requires PHP < 8.3
216+
*/
181217
public function testDayOfWeek(): void
182218
{
183219
$dayOfWeek = $this->extension->dayOfWeek('2021-12-12T15:10:00');
@@ -186,6 +222,9 @@ public function testDayOfWeek(): void
186222
self::assertEquals('Monday', $dayOfWeek);
187223
}
188224

225+
/**
226+
* @requires PHP < 8.3
227+
*/
189228
public function testMonth(): void
190229
{
191230
$month = $this->extension->month('2021-05-23T15:10:00');
@@ -194,6 +233,9 @@ public function testMonth(): void
194233
self::assertEquals('10', $month);
195234
}
196235

236+
/**
237+
* @requires PHP < 8.3
238+
*/
197239
public function testMonthName(): void
198240
{
199241
$monthName = $this->extension->monthName('2021-06-06T15:10:00');
@@ -202,6 +244,9 @@ public function testMonthName(): void
202244
self::assertEquals('October', $monthName);
203245
}
204246

247+
/**
248+
* @requires PHP < 8.3
249+
*/
205250
public function testYear(): void
206251
{
207252
$year = $this->extension->year('2021-09-12T15:10:00');
@@ -210,6 +255,9 @@ public function testYear(): void
210255
self::assertEquals('1999', $year);
211256
}
212257

258+
/**
259+
* @requires PHP < 8.3
260+
*/
213261
public function testCentury(): void
214262
{
215263
$century = $this->extension->century();

test/Faker/Core/UuidTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public function testUuidReturnsUuid(): void
1414
self::assertTrue($this->isUuid($uuid));
1515
}
1616

17+
/**
18+
* @requires PHP < 8.3
19+
*/
1720
public function testUuidExpectedSeed(): void
1821
{
1922
$instance = new Uuid();

test/Faker/GeneratorTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ public function testUniqueReturnsDifferentUniqueGeneratorWhenResetIsTrue(): void
245245
self::assertNotSame($uniqueGenerator, $generator->unique(true));
246246
}
247247

248+
/**
249+
* @requires PHP < 8.3
250+
*/
248251
public function testUniqueReturnsUniqueGeneratorThatGeneratesUniqueValues(): void
249252
{
250253
$words = [

test/Faker/Provider/BaseTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ public function testOptionalAllowsChainingProviderCallRandomlyReturnNull(): void
410410

411411
/**
412412
* @see https://github.com/fzaninotto/Faker/issues/265
413+
*
414+
* @requires PHP < 8.3
413415
*/
414416
public function testOptionalPercentageAndWeight(): void
415417
{

test/Faker/Provider/BiasedTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public function testUnbiased(): void
4242
}
4343
}
4444

45+
/**
46+
* @requires PHP < 8.3
47+
*/
4548
public function testLinearHigh(): void
4649
{
4750
$this->performFake(['\Faker\Provider\Biased', 'linearHigh']);

test/Faker/Provider/UuidTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public function testUuidReturnsUuid(): void
1616
self::assertTrue($this->isUuid($uuid));
1717
}
1818

19+
/**
20+
* @requires PHP < 8.3
21+
*/
1922
public function testUuidExpectedSeed(): void
2023
{
2124
if (pack('L', 0x6162797A) == pack('N', 0x6162797A)) {

test/Faker/Provider/en_GB/CompanyTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public function testModulus97AlgorithmWithInvalidArgument(): void
2626
$this->faker->calculateModulus97(123);
2727
}
2828

29+
/**
30+
* @requires PHP < 8.3
31+
*/
2932
public function testVat(): void
3033
{
3134
$this->assertDefaultVatFormat($this->faker->vat());
@@ -37,6 +40,9 @@ private function assertDefaultVatFormat($number): void
3740
self::assertEquals(1, preg_match('/^GB[\d]{3} [\d]{4} [\d]{2}$/', $number));
3841
}
3942

43+
/**
44+
* @requires PHP < 8.3
45+
*/
4046
public function testVatBranchType(): void
4147
{
4248
$number = $this->faker->vat(Company::VAT_TYPE_BRANCH);

test/Faker/Provider/fi_FI/PersonTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public function provideSeedAndExpectedReturn()
2323
}
2424

2525
/**
26+
* @requires PHP < 8.3
27+
*
2628
* @dataProvider provideSeedAndExpectedReturn
2729
*/
2830
public function testPersonalIdentityNumberUsesBirthDateIfProvided($seed, $birthdate, $expected): void

test/Faker/Provider/fr_FR/AddressTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ public function testPostcode(): void
1818
self::assertMatchesRegularExpression('@^\d{5}$@', $postcode);
1919
}
2020

21+
/**
22+
* @requires PHP < 8.3
23+
*/
2124
public function testSecondaryAddress(): void
2225
{
2326
self::assertEquals('Étage 007', $this->faker->secondaryAddress());
2427
self::assertEquals('Bât. 932', $this->faker->secondaryAddress());
2528
}
2629

30+
/**
31+
* @requires PHP < 8.3
32+
*/
2733
public function testRegion(): void
2834
{
2935
self::assertEquals('Occitanie', $this->faker->region());

test/Faker/Provider/fr_FR/ColorTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@
1010
*/
1111
final class ColorTest extends TestCase
1212
{
13+
/**
14+
* @requires PHP < 8.3
15+
*/
1316
public function testColorName(): void
1417
{
1518
self::assertEquals('Mandarine', $this->faker->colorName());
1619
self::assertEquals('Acajou', $this->faker->colorName());
1720
}
1821

22+
/**
23+
* @requires PHP < 8.3
24+
*/
1925
public function testSafeColorName(): void
2026
{
2127
self::assertEquals('bleu', $this->faker->safeColorName());

test/Faker/Provider/hu_HU/PersonTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
*/
1111
final class PersonTest extends TestCase
1212
{
13+
/**
14+
* @requires PHP < 8.3
15+
*/
1316
public function testValidMariedFemaleLastnames(): void
1417
{
1518
self::assertEquals('Báró Vassné Zsóka', $this->faker->name('female'));

test/Faker/Provider/ja_JP/InternetTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010
*/
1111
final class InternetTest extends TestCase
1212
{
13+
/**
14+
* @requires PHP < 8.3
15+
*/
1316
public function testUserName(): void
1417
{
1518
self::assertEquals('akira72', $this->faker->userName);
1619
}
1720

21+
/**
22+
* @requires PHP < 8.3
23+
*/
1824
public function testDomainName(): void
1925
{
2026
self::assertEquals('nakajima.com', $this->faker->domainName);

test/Faker/Provider/ja_JP/PersonTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,41 @@
1010
*/
1111
final class PersonTest extends TestCase
1212
{
13+
/**
14+
* @requires PHP < 8.3
15+
*/
1316
public function testKanaNameMaleReturns(): void
1417
{
1518
self::assertEquals('アオタ ミノル', $this->faker->kanaName('male'));
1619
}
1720

21+
/**
22+
* @requires PHP < 8.3
23+
*/
1824
public function testKanaNameFemaleReturns(): void
1925
{
2026
self::assertEquals('アオタ ミキ', $this->faker->kanaName('female'));
2127
}
2228

29+
/**
30+
* @requires PHP < 8.3
31+
*/
2332
public function testFirstKanaNameMaleReturns(): void
2433
{
2534
self::assertEquals('ヒデキ', $this->faker->firstKanaName('male'));
2635
}
2736

37+
/**
38+
* @requires PHP < 8.3
39+
*/
2840
public function testFirstKanaNameFemaleReturns(): void
2941
{
3042
self::assertEquals('マアヤ', $this->faker->firstKanaName('female'));
3143
}
3244

45+
/**
46+
* @requires PHP < 8.3
47+
*/
3348
public function testLastKanaNameReturnsNakajima(): void
3449
{
3550
self::assertEquals('ナカジマ', $this->faker->lastKanaName);

0 commit comments

Comments
 (0)