Skip to content

Remove useless uniqid in tempnam calls in tests #57614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2024
Merged
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
Remove useless uniqid in tempnam calls
  • Loading branch information
GromNaN committed Jul 1, 2024
commit d5edc9366d12f15e9c337df7b22beffd139412c1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test DeprecationErrorHandler with log file
--FILE--
<?php
$filename = tempnam(sys_get_temp_dir(), 'sf-').uniqid();
$filename = tempnam(sys_get_temp_dir(), 'sf-');
$k = 'SYMFONY_DEPRECATIONS_HELPER';
putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'logFile='.$filename);
putenv('ANSICON');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ class ConfigBuilderCacheWarmerTest extends TestCase

protected function setUp(): void
{
$this->varDir = sys_get_temp_dir().'/'.uniqid();
$fs = new Filesystem();
$this->varDir = tempnam(sys_get_temp_dir(), 'sf_var_');
$fs->remove($this->varDir);
$fs->mkdir($this->varDir);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public function testDebugDefaultRootDirectory()
{
$this->fs->remove($this->translationDir);
$this->fs = new Filesystem();
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
$this->translationDir = tempnam(sys_get_temp_dir(), 'sf_translation_');
$this->fs->remove($this->translationDir);
$this->fs->mkdir($this->translationDir.'/translations');
$this->fs->mkdir($this->translationDir.'/templates');

Expand Down Expand Up @@ -150,7 +151,8 @@ public function testNoErrorWithOnlyUnusedOptionAndNoResults()
protected function setUp(): void
{
$this->fs = new Filesystem();
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
$this->translationDir = tempnam(sys_get_temp_dir(), 'sf_translation_');
$this->fs->remove($this->translationDir);
$this->fs->mkdir($this->translationDir.'/translations');
$this->fs->mkdir($this->translationDir.'/templates');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public static function provideCompletionSuggestions(): iterable
protected function setUp(): void
{
$this->fs = new Filesystem();
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
$this->translationDir = tempnam(sys_get_temp_dir(), 'sf_translation_');
$this->fs->remove($this->translationDir);
$this->fs->mkdir($this->translationDir.'/translations');
$this->fs->mkdir($this->translationDir.'/templates');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ public function testDumpWrongSortAndClean()

public function testDumpMessagesAndCleanInRootDirectory()
{
$this->fs->remove($this->translationDir);
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
$this->fs->mkdir($this->translationDir.'/translations');
$this->fs->mkdir($this->translationDir.'/templates');

$tester = $this->createCommandTester(['messages' => ['foo' => 'foo']], [], null, [$this->translationDir.'/trans'], [$this->translationDir.'/views']);
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', '--dump-messages' => true, '--clean' => true]);
$this->assertMatchesRegularExpression('/foo/', $tester->getDisplay());
Expand Down Expand Up @@ -115,11 +110,6 @@ public function testWriteMessages()

public function testWriteMessagesInRootDirectory()
{
$this->fs->remove($this->translationDir);
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
$this->fs->mkdir($this->translationDir.'/translations');
$this->fs->mkdir($this->translationDir.'/templates');

$tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]);
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', '--force' => true]);
$this->assertMatchesRegularExpression('/Translation files were successfully updated./', $tester->getDisplay());
Expand Down Expand Up @@ -174,7 +164,8 @@ public function testFilterDuplicateTransPaths()
protected function setUp(): void
{
$this->fs = new Filesystem();
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
$this->translationDir = tempnam(sys_get_temp_dir(), 'sf_translation_');
$this->fs->remove($this->translationDir);
$this->fs->mkdir($this->translationDir.'/translations');
$this->fs->mkdir($this->translationDir.'/templates');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ class BundlePathsTest extends AbstractWebTestCase
public function testBundlePublicDir()
{
$kernel = static::bootKernel(['test_case' => 'BundlePaths']);
$projectDir = sys_get_temp_dir().'/'.uniqid('sf_bundle_paths', true);
$projectDir = tempnam(sys_get_temp_dir(), 'sf_bundle_paths_');

$fs = new Filesystem();
$fs->remove($projectDir);
$fs->mkdir($projectDir.'/public');
$command = (new Application($kernel))->add(new AssetsInstallCommand($fs, $projectDir));
$exitCode = (new CommandTester($command))->execute(['target' => $projectDir.'/public']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,9 @@ public static function getNonStringValues()
*/
public function testCacheValidityWithContainerParameters($parameter)
{
$cacheDir = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('router_', true);
$cacheDir = tempnam(sys_get_temp_dir(), 'sf_router_');
unlink($cacheDir);
mkdir($cacheDir);

try {
$container = new Container();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public function testConfig(string $name, string $alias)
// $this->generateConfigBuilder('Symfony\\Component\\Config\\Tests\\Builder\\Fixtures\\'.$name, $expectedCode);
// $this->markTestIncomplete('Re-comment the line above and relaunch the tests');

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

Expand Down Expand Up @@ -162,12 +161,12 @@ public function testSetExtraKeyMethodIsNotGeneratedWhenAllowExtraKeysIsFalse()
/**
* Generate the ConfigBuilder or return an already generated instance.
*/
private function generateConfigBuilder(string $configurationClass, ?string $outputDir = null)
private function generateConfigBuilder(string $configurationClass, ?string &$outputDir = null)
{
$outputDir ??= sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('sf_config_builder', true);
if (!str_contains($outputDir, __DIR__)) {
$this->tempDir[] = $outputDir;
}
$outputDir = tempnam(sys_get_temp_dir(), 'sf_config_builder_');
unlink($outputDir);
mkdir($outputDir);
$this->tempDir[] = $outputDir;

$configuration = new $configurationClass();
$rootNode = $configuration->getConfigTreeBuilder()->buildTree();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function setUp(): void
{
parent::setUp();

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

protected function tearDown(): void
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Routing/Tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ protected function setUp(): void
$this->loader = $this->createMock(LoaderInterface::class);
$this->router = new Router($this->loader, 'routing.yml');

$this->cacheDir = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('router_', true);
$this->cacheDir = tempnam(sys_get_temp_dir(), 'sf_router_');
unlink($this->cacheDir);
mkdir($this->cacheDir);
}

protected function tearDown(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class ClassMetadataFactoryCompilerTest extends TestCase

protected function setUp(): void
{
$this->dumpPath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'php_serializer_metadata.'.uniqid('CompiledClassMetadataFactory').'.php';
$this->dumpPath = tempnam(sys_get_temp_dir(), 'sf_serializer_metadata_');
}

protected function tearDown(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ protected function setUp(): void
$this->defaultLocale = \Locale::getDefault();
\Locale::setDefault('en');
$this->fs = new Filesystem();
$this->translationAppDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
$this->translationAppDir = tempnam(sys_get_temp_dir(), 'sf_translation_');
$this->fs->remove($this->translationAppDir);
$this->fs->mkdir($this->translationAppDir.'/translations');
}

Expand Down
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