Skip to content

Commit d5edc93

Browse files
committed
Remove useless uniqid in tempnam calls
1 parent 68b2e16 commit d5edc93

File tree

12 files changed

+28
-28
lines changed

12 files changed

+28
-28
lines changed

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/log_file.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Test DeprecationErrorHandler with log file
33
--FILE--
44
<?php
5-
$filename = tempnam(sys_get_temp_dir(), 'sf-').uniqid();
5+
$filename = tempnam(sys_get_temp_dir(), 'sf-');
66
$k = 'SYMFONY_DEPRECATIONS_HELPER';
77
putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'logFile='.$filename);
88
putenv('ANSICON');

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ConfigBuilderCacheWarmerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ class ConfigBuilderCacheWarmerTest extends TestCase
3737

3838
protected function setUp(): void
3939
{
40-
$this->varDir = sys_get_temp_dir().'/'.uniqid();
4140
$fs = new Filesystem();
41+
$this->varDir = tempnam(sys_get_temp_dir(), 'sf_var_');
42+
$fs->remove($this->varDir);
4243
$fs->mkdir($this->varDir);
4344
}
4445

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public function testDebugDefaultRootDirectory()
8282
{
8383
$this->fs->remove($this->translationDir);
8484
$this->fs = new Filesystem();
85-
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
85+
$this->translationDir = tempnam(sys_get_temp_dir(), 'sf_translation_');
86+
$this->fs->remove($this->translationDir);
8687
$this->fs->mkdir($this->translationDir.'/translations');
8788
$this->fs->mkdir($this->translationDir.'/templates');
8889

@@ -150,7 +151,8 @@ public function testNoErrorWithOnlyUnusedOptionAndNoResults()
150151
protected function setUp(): void
151152
{
152153
$this->fs = new Filesystem();
153-
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
154+
$this->translationDir = tempnam(sys_get_temp_dir(), 'sf_translation_');
155+
$this->fs->remove($this->translationDir);
154156
$this->fs->mkdir($this->translationDir.'/translations');
155157
$this->fs->mkdir($this->translationDir.'/templates');
156158
}

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandCompletionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public static function provideCompletionSuggestions(): iterable
5757
protected function setUp(): void
5858
{
5959
$this->fs = new Filesystem();
60-
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
60+
$this->translationDir = tempnam(sys_get_temp_dir(), 'sf_translation_');
61+
$this->fs->remove($this->translationDir);
6162
$this->fs->mkdir($this->translationDir.'/translations');
6263
$this->fs->mkdir($this->translationDir.'/templates');
6364
}

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ public function testDumpWrongSortAndClean()
7878

7979
public function testDumpMessagesAndCleanInRootDirectory()
8080
{
81-
$this->fs->remove($this->translationDir);
82-
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
83-
$this->fs->mkdir($this->translationDir.'/translations');
84-
$this->fs->mkdir($this->translationDir.'/templates');
85-
8681
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo']], [], null, [$this->translationDir.'/trans'], [$this->translationDir.'/views']);
8782
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', '--dump-messages' => true, '--clean' => true]);
8883
$this->assertMatchesRegularExpression('/foo/', $tester->getDisplay());
@@ -115,11 +110,6 @@ public function testWriteMessages()
115110

116111
public function testWriteMessagesInRootDirectory()
117112
{
118-
$this->fs->remove($this->translationDir);
119-
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
120-
$this->fs->mkdir($this->translationDir.'/translations');
121-
$this->fs->mkdir($this->translationDir.'/templates');
122-
123113
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]);
124114
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', '--force' => true]);
125115
$this->assertMatchesRegularExpression('/Translation files were successfully updated./', $tester->getDisplay());
@@ -174,7 +164,8 @@ public function testFilterDuplicateTransPaths()
174164
protected function setUp(): void
175165
{
176166
$this->fs = new Filesystem();
177-
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
167+
$this->translationDir = tempnam(sys_get_temp_dir(), 'sf_translation_');
168+
$this->fs->remove($this->translationDir);
178169
$this->fs->mkdir($this->translationDir.'/translations');
179170
$this->fs->mkdir($this->translationDir.'/templates');
180171
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/BundlePathsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ class BundlePathsTest extends AbstractWebTestCase
2323
public function testBundlePublicDir()
2424
{
2525
$kernel = static::bootKernel(['test_case' => 'BundlePaths']);
26-
$projectDir = sys_get_temp_dir().'/'.uniqid('sf_bundle_paths', true);
26+
$projectDir = tempnam(sys_get_temp_dir(), 'sf_bundle_paths_');
2727

2828
$fs = new Filesystem();
29+
$fs->remove($projectDir);
2930
$fs->mkdir($projectDir.'/public');
3031
$command = (new Application($kernel))->add(new AssetsInstallCommand($fs, $projectDir));
3132
$exitCode = (new CommandTester($command))->execute(['target' => $projectDir.'/public']);

src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,9 @@ public static function getNonStringValues()
530530
*/
531531
public function testCacheValidityWithContainerParameters($parameter)
532532
{
533-
$cacheDir = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('router_', true);
533+
$cacheDir = tempnam(sys_get_temp_dir(), 'sf_router_');
534+
unlink($cacheDir);
535+
mkdir($cacheDir);
534536

535537
try {
536538
$container = new Container();

src/Symfony/Component/Config/Tests/Builder/GeneratedConfigTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ public function testConfig(string $name, string $alias)
9292
// $this->generateConfigBuilder('Symfony\\Component\\Config\\Tests\\Builder\\Fixtures\\'.$name, $expectedCode);
9393
// $this->markTestIncomplete('Re-comment the line above and relaunch the tests');
9494

95-
$outputDir = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('sf_config_builder', true);
9695
$configBuilder = $this->generateConfigBuilder('Symfony\\Component\\Config\\Tests\\Builder\\Fixtures\\'.$name, $outputDir);
9796
$callback($configBuilder);
9897

@@ -162,12 +161,12 @@ public function testSetExtraKeyMethodIsNotGeneratedWhenAllowExtraKeysIsFalse()
162161
/**
163162
* Generate the ConfigBuilder or return an already generated instance.
164163
*/
165-
private function generateConfigBuilder(string $configurationClass, ?string $outputDir = null)
164+
private function generateConfigBuilder(string $configurationClass, ?string &$outputDir = null)
166165
{
167-
$outputDir ??= sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('sf_config_builder', true);
168-
if (!str_contains($outputDir, __DIR__)) {
169-
$this->tempDir[] = $outputDir;
170-
}
166+
$outputDir = tempnam(sys_get_temp_dir(), 'sf_config_builder_');
167+
unlink($outputDir);
168+
mkdir($outputDir);
169+
$this->tempDir[] = $outputDir;
171170

172171
$configuration = new $configurationClass();
173172
$rootNode = $configuration->getConfigTreeBuilder()->buildTree();

src/Symfony/Component/Routing/Tests/Matcher/Dumper/CompiledUrlMatcherDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function setUp(): void
3030
{
3131
parent::setUp();
3232

33-
$this->dumpPath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'php_matcher.'.uniqid('CompiledUrlMatcher').'.php';
33+
$this->dumpPath = tempnam(sys_get_temp_dir(), 'sf_matcher_');
3434
}
3535

3636
protected function tearDown(): void

src/Symfony/Component/Routing/Tests/RouterTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ protected function setUp(): void
3535
$this->loader = $this->createMock(LoaderInterface::class);
3636
$this->router = new Router($this->loader, 'routing.yml');
3737

38-
$this->cacheDir = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('router_', true);
38+
$this->cacheDir = tempnam(sys_get_temp_dir(), 'sf_router_');
39+
unlink($this->cacheDir);
40+
mkdir($this->cacheDir);
3941
}
4042

4143
protected function tearDown(): void

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy