Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9dd27aa

Browse filesBrowse files
committed
Removed enused logic in MockStream
1 parent d67e377 commit 9dd27aa
Copy full SHA for 9dd27aa

File tree

3 files changed

+30
-225
lines changed
Filter options

3 files changed

+30
-225
lines changed

‎src/Symfony/Component/Filesystem/Filesystem.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/Filesystem.php
+10-16Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -454,34 +454,30 @@ public function isAbsolutePath($file)
454454
* @param string $prefix The prefix of the generated temporary filename.
455455
* Note: Windows uses only the first three characters of prefix.
456456
*
457-
* @return string The new temporary filename (with path), or false on failure.
457+
* @return string The new temporary filename (with path), or throw an exception on failure.
458458
*/
459459
public function tempnam($dir, $prefix)
460460
{
461-
$limit = 10;
462461
list($scheme, $hierarchy) = $this->getSchemeAndHierarchy($dir);
463462

464463
// If no scheme or scheme is "file" create temp file in local filesystem
465464
if (null === $scheme || 'file' === $scheme) {
466-
467465
$tmpFile = tempnam($hierarchy, $prefix);
468466

469467
// If tempnam failed or no scheme return the filename otherwise prepend the scheme
470-
471-
if (null !== $scheme) {
472-
return $scheme.'://'.$tmpFile;
473-
}
474-
475468
if (false !== $tmpFile) {
469+
if (null !== $scheme) {
470+
return $scheme.'://'.$tmpFile;
471+
}
472+
476473
return $tmpFile;
477474
}
478475

479-
throw new IOException('A temporary file could not be created');
476+
throw new IOException('A temporary file could not be created.');
480477
}
481478

482-
// Loop until we create a valid temp file or have reached $limit attempts
483-
for ($i = 0; $i < $limit; ++$i) {
484-
479+
// Loop until we create a valid temp file or have reached 10 attempts
480+
for ($i = 0; $i < 10; ++$i) {
485481
// Create a unique filename
486482
$tmpFile = $dir.'/'.$prefix.uniqid(mt_rand(), true);
487483

@@ -498,10 +494,9 @@ public function tempnam($dir, $prefix)
498494
@fclose($handle);
499495

500496
return $tmpFile;
501-
502497
}
503498

504-
return false;
499+
throw new IOException('A temporary file could not be created.');
505500
}
506501

507502
/**
@@ -565,7 +560,6 @@ private function getSchemeAndHierarchy($filename)
565560
{
566561
$components = explode('://', $filename, 2);
567562

568-
return count($components) === 2 ? array($components[0], $components[1]) : array(null, $components[0]);
563+
return 2 === count($components) ? array($components[0], $components[1]) : array(null, $components[0]);
569564
}
570-
571565
}

‎src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
+16-18Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Filesystem\Tests;
1313

14-
use Phar;
1514
/**
1615
* Test class for Filesystem.
1716
*/
@@ -951,7 +950,6 @@ public function testTempnam()
951950

952951
$filename = $this->filesystem->tempnam($dirname, 'foo');
953952

954-
$this->assertNotFalse($filename);
955953
$this->assertFileExists($filename);
956954
}
957955

@@ -962,7 +960,6 @@ public function testTempnamWithFileScheme()
962960

963961
$filename = $this->filesystem->tempnam($dirname, 'foo');
964962

965-
$this->assertNotFalse($filename);
966963
$this->assertStringStartsWith($scheme, $filename);
967964
$this->assertFileExists($filename);
968965
}
@@ -974,27 +971,28 @@ public function testTempnamWithMockScheme()
974971
$this->markTestSkipped('Unable to load mock:// stream.');
975972
}
976973

977-
stream_wrapper_register('mock', 'MockStream\MockStream');
974+
stream_wrapper_register('mock', 'Symfony\Component\Filesystem\Tests\Fixtures\MockStream\MockStream');
978975

979976
$scheme = 'mock://';
980977
$dirname = $scheme.$this->workspace;
981978

982979
$filename = $this->filesystem->tempnam($dirname, 'foo');
983980

984-
$this->assertNotFalse($filename);
985981
$this->assertStringStartsWith($scheme, $filename);
986982
$this->assertFileExists($filename);
987983
}
988984

985+
/**
986+
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
987+
*/
989988
public function testTempnamWithZlibSchemeFails()
990989
{
991990
$scheme = 'compress.zlib://';
992991
$dirname = $scheme.$this->workspace;
993992

994-
$filename = $this->filesystem->tempnam($dirname, 'bar');
995-
996993
// The compress.zlib:// stream does not support mode x: creates the file, errors "failed to open stream: operation failed" and returns false
997-
$this->assertFalse($filename);
994+
$this->filesystem->tempnam($dirname, 'bar');
995+
998996
}
999997

1000998
public function testTempnamWithPHPTempSchemeFails()
@@ -1004,40 +1002,41 @@ public function testTempnamWithPHPTempSchemeFails()
10041002

10051003
$filename = $this->filesystem->tempnam($dirname, 'bar');
10061004

1007-
$this->assertNotFalse($filename);
10081005
$this->assertStringStartsWith($scheme, $filename);
10091006

10101007
// The php://temp stream deletes the file after close
10111008
$this->assertFileNotExists($filename);
10121009
}
10131010

1011+
/**
1012+
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
1013+
*/
10141014
public function testTempnamWithPharSchemeFails()
10151015
{
10161016
// Skip test if Phar disabled phar.readonly must be 0 in php.ini
1017-
if (!Phar::canWrite()) {
1017+
if (!\Phar::canWrite()) {
10181018
$this->markTestSkipped('This test cannot run when phar.readonly is 1.');
10191019
}
10201020

10211021
$scheme = 'phar://';
10221022
$dirname = $scheme.$this->workspace;
10231023
$pharname = 'foo.phar';
10241024

1025-
$p = new Phar($this->workspace.'/'.$pharname, 0, $pharname);
1026-
$filename = $this->filesystem->tempnam($dirname, $pharname.'/bar');
1027-
1025+
new \Phar($this->workspace.'/'.$pharname, 0, $pharname);
10281026
// The phar:// stream does not support mode x: fails to create file, errors "failed to open stream: phar error: "$filename" is not a file in phar "$pharname"" and returns false
1029-
$this->assertFalse($filename);
1027+
$this->filesystem->tempnam($dirname, $pharname.'/bar');
10301028
}
10311029

1030+
/**
1031+
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
1032+
*/
10321033
public function testTempnamWithHTTPSchemeFails()
10331034
{
10341035
$scheme = 'http://';
10351036
$dirname = $scheme.$this->workspace;
10361037

1037-
$filename = $this->filesystem->tempnam($dirname, 'bar');
1038-
10391038
// The http:// scheme is read-only
1040-
$this->assertFalse($filename);
1039+
$this->filesystem->tempnam($dirname, 'bar');
10411040
}
10421041

10431042
public function testTempnamOnUnwritableFallsBackToSysTmp()
@@ -1047,7 +1046,6 @@ public function testTempnamOnUnwritableFallsBackToSysTmp()
10471046

10481047
$filename = $this->filesystem->tempnam($dirname, 'bar');
10491048

1050-
$this->assertNotFalse($filename);
10511049
$this->assertStringStartsWith(rtrim($scheme.sys_get_temp_dir(), DIRECTORY_SEPARATOR), $filename);
10521050
$this->assertFileExists($filename);
10531051

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.