Skip to content

Commit

Permalink
tests: eliminate usage of uniqid()
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurk committed Jan 3, 2023
1 parent fcc0e69 commit 81fb79a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion tests/FileUploadControl/FileUploadControlValidationTest.phpt
Expand Up @@ -19,6 +19,7 @@ use Nette\Http\UrlScript;
use Nette\Utils\FileSystem;
use Nette\Utils\Helpers;
use Nette\Utils\Json;
use Nette\Utils\Random;
use Tester\Assert;

require_once __DIR__ . '/../bootstrap.php';
Expand Down Expand Up @@ -136,7 +137,7 @@ class FileUploadControlValidationTest extends TestCase
$control = $this->createFileUploadControl();
$control->addRule(Form::IMAGE, 'only PNG is allowed');

$file = Environment::getTempDir() . '/' . uniqid();
$file = Environment::getTempDir() . '/' . Random::generate();
FileSystem::write($file, $this->readChunk(__DIR__ . '/Fixtures/image.png', 64));

$files = ['fileUpload' => ['upload' => [
Expand Down
Expand Up @@ -13,6 +13,7 @@ use Nepada\FileUploadControl\Utils\NetteFinder;
use Nepada\FileUploadControl\Utils\NetteRandomProvider;
use NepadaTests\Environment;
use NepadaTests\TestCase;
use Nette\Utils\Random;
use Tester\Assert;

require_once __DIR__ . '/../../bootstrap.php';
Expand All @@ -37,7 +38,7 @@ class FileSystemStorageManagerTest extends TestCase

public function testGarbageCollection(): void
{
$directory = Environment::getTempDir() . '/' . uniqid();
$directory = Environment::getTempDir() . '/' . Random::generate();
$ttl = 2;

$oldNamespace = $this->createStorageManager($directory, $ttl)->createNewNamespace();
Expand Down Expand Up @@ -66,7 +67,7 @@ class FileSystemStorageManagerTest extends TestCase

private function createStorageManager(?string $directory = null, int $ttl = FileSystemStorageManager::DEFAULT_TTL): FileSystemStorageManager
{
$directory ??= Environment::getTempDir() . '/' . uniqid();
$directory ??= Environment::getTempDir() . '/' . Random::generate();
$fileSystem = new NetteFileSystem();
$finder = new NetteFinder();
$dateTimeProvider = new DefaultDateTimeProvider();
Expand Down
3 changes: 2 additions & 1 deletion tests/FileUploadControl/Storage/FileSystemStorageTest.phpt
Expand Up @@ -15,6 +15,7 @@ use NepadaTests\FileUploadControl\FileUploadFactory;
use NepadaTests\FileUploadControl\Storage\Metadata\InMemoryMetadataJournal;
use NepadaTests\TestCase;
use Nette;
use Nette\Utils\Random;
use Tester\Assert;

require_once __DIR__ . '/../../bootstrap.php';
Expand Down Expand Up @@ -186,7 +187,7 @@ class FileSystemStorageTest extends TestCase
*/
private function createStorage(array $journalData = []): FileSystemStorage
{
$directory = Environment::getTempDir() . '/' . uniqid();
$directory = Environment::getTempDir() . '/' . Random::generate();
Nette\Utils\FileSystem::createDir($directory);

$journal = new InMemoryMetadataJournal($journalData);
Expand Down
Expand Up @@ -13,6 +13,7 @@ use Nepada\FileUploadControl\Utils\NetteFinder;
use NepadaTests\Environment;
use NepadaTests\TestCase;
use Nette;
use Nette\Utils\Random;
use Tester\Assert;

require_once __DIR__ . '/../../../bootstrap.php';
Expand Down Expand Up @@ -86,7 +87,7 @@ class FileSystemMetadataJournalTest extends TestCase

private function createJournal(): FileSystemMetadataJournal
{
$directory = Environment::getTempDir() . '/' . uniqid();
$directory = Environment::getTempDir() . '/' . Random::generate();
Nette\Utils\FileSystem::createDir($directory);

return new FileSystemMetadataJournal(new NetteFileSystem(), new NetteFinder(), $directory);
Expand Down

0 comments on commit 81fb79a

Please sign in to comment.