Skip to content
Open
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
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
]),
],
'php_unit_attributes' => true,
'random_api_migration' => true,
])
->setRiskyAllowed(true)
->setFinder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static function (CacheItem $item, $expiry) {

$cache = $this->createCachePool(1);
$cache->clear();
$value = rand();
$value = random_int(0, getrandmax());
$item = $cache->getItem('foo');
$setCacheItemExpiry($item, 0);
$cache->save($item->set($value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testResourceDoesNotExist()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageMatches('/The directory ".*" does not exist./');
new DirectoryResource('/____foo/foobar'.mt_rand(1, 999999));
new DirectoryResource('/____foo/foobar'.random_int(1, 999999));
}

public function testIsFresh()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testResourceDoesNotExist()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageMatches('/The file ".*" does not exist./');
new FileResource('/____foo/foobar'.mt_rand(1, 999999));
new FileResource('/____foo/foobar'.random_int(1, 999999));
}

public function testIsFresh()
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ public function testChownSymlinkFails()

$this->filesystem->symlink($file, $link);

$this->filesystem->chown($link, 'user'.time().mt_rand(1000, 9999));
$this->filesystem->chown($link, 'user'.time().random_int(1000, 9999));
}

public function testChownLinkFails()
Expand All @@ -677,7 +677,7 @@ public function testChownLinkFails()

$this->filesystem->hardlink($file, $link);

$this->filesystem->chown($link, 'user'.time().mt_rand(1000, 9999));
$this->filesystem->chown($link, 'user'.time().random_int(1000, 9999));
}

public function testChownFail()
Expand All @@ -688,7 +688,7 @@ public function testChownFail()
$dir = $this->workspace.\DIRECTORY_SEPARATOR.'dir';
mkdir($dir);

$this->filesystem->chown($dir, 'user'.time().mt_rand(1000, 9999));
$this->filesystem->chown($dir, 'user'.time().random_int(1000, 9999));
}

public function testChgrpByName()
Expand Down Expand Up @@ -795,7 +795,7 @@ public function testChgrpSymlinkFails()

$this->filesystem->symlink($file, $link);

$this->filesystem->chgrp($link, 'user'.time().mt_rand(1000, 9999));
$this->filesystem->chgrp($link, 'user'.time().random_int(1000, 9999));
}

public function testChgrpLinkFails()
Expand All @@ -810,7 +810,7 @@ public function testChgrpLinkFails()

$this->filesystem->hardlink($file, $link);

$this->filesystem->chgrp($link, 'user'.time().mt_rand(1000, 9999));
$this->filesystem->chgrp($link, 'user'.time().random_int(1000, 9999));
}

public function testChgrpFail()
Expand All @@ -821,7 +821,7 @@ public function testChgrpFail()
$dir = $this->workspace.\DIRECTORY_SEPARATOR.'dir';
mkdir($dir);

$this->filesystem->chgrp($dir, 'user'.time().mt_rand(1000, 9999));
$this->filesystem->chgrp($dir, 'user'.time().random_int(1000, 9999));
}

public function testRename()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testSameChoiceFieldCreatedMultipleTimes()
$choices = range(1, 300);

for ($i = 0; $i < 100; ++$i) {
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', mt_rand(1, 400), [
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', random_int(1, 400), [
'choices' => $choices,
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function write(Profile $profile): bool
], ',', '"', '\\');
fclose($file);

if (1 === mt_rand(1, 10)) {
if (1 === random_int(1, 10)) {
$this->removeExpiredProfiles();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class JsonBundleWriterTest extends TestCase
protected function setUp(): void
{
$this->writer = new JsonBundleWriter();
$this->directory = sys_get_temp_dir().'/JsonBundleWriterTest/'.mt_rand(1000, 9999);
$this->directory = sys_get_temp_dir().'/JsonBundleWriterTest/'.random_int(1000, 9999);
$this->filesystem = new Filesystem();

$this->filesystem->mkdir($this->directory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PhpBundleWriterTest extends TestCase
protected function setUp(): void
{
$this->writer = new PhpBundleWriter();
$this->directory = sys_get_temp_dir().'/PhpBundleWriterTest/'.mt_rand(1000, 9999);
$this->directory = sys_get_temp_dir().'/PhpBundleWriterTest/'.random_int(1000, 9999);
$this->filesystem = new Filesystem();

$this->filesystem->mkdir($this->directory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TextBundleWriterTest extends TestCase
protected function setUp(): void
{
$this->writer = new TextBundleWriter();
$this->directory = sys_get_temp_dir().'/TextBundleWriterTest/'.mt_rand(1000, 9999);
$this->directory = sys_get_temp_dir().'/TextBundleWriterTest/'.random_int(1000, 9999);
$this->filesystem = new Filesystem();

$this->filesystem->mkdir($this->directory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LocaleScannerTest extends TestCase

protected function setUp(): void
{
$this->directory = sys_get_temp_dir().'/LocaleScannerTest/'.mt_rand(1000, 9999);
$this->directory = sys_get_temp_dir().'/LocaleScannerTest/'.random_int(1000, 9999);
$this->filesystem = new Filesystem();
$this->scanner = new LocaleScanner();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected function getInitialCursor(): int
{
// the cursor initial value is randomized so that
// when are not in a daemon, we are still rotating the transports
return mt_rand(0, \count($this->transports) - 1);
return random_int(0, \count($this->transports) - 1);
}

protected function getNameSymbol(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected function getInitialCursor(): int
{
// the cursor initial value is randomized so that
// when are not in a daemon, we are still rotating the transports
return mt_rand(0, \count($this->transports) - 1);
return random_int(0, \count($this->transports) - 1);
}

protected function getNameSymbol(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,5 @@ private function strlen(string $s): int
return false === ($encoding = mb_detect_encoding($s, null, true)) ? \strlen($s) : mb_strlen($s, $encoding);
}
}

// @php-cs-fixer-ignore random_api_migration As logic is coupled with mt_srand() in tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// @php-cs-fixer-ignore random_api_migration As logic is coupled with mt_srand() in tests
// @php-cs-fixer-ignore random_api_migration can be seeded using mt_srand()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it be seeded externally or shall be done only in tests?

Loading