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 b8e304b

Browse filesBrowse files
committed
Removed unused logic in MockStream
1 parent d67e377 commit b8e304b
Copy full SHA for b8e304b

File tree

Expand file treeCollapse file tree

3 files changed

+30
-230
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+30
-230
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-23Lines changed: 16 additions & 23 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,39 +960,34 @@ 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
}
969966

970967
public function testTempnamWithMockScheme()
971968
{
972-
// We avoid autoloading via ClassLoader as stream_wrapper_register creates the object
973-
if (!@include __DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'MockStream'.DIRECTORY_SEPARATOR.'MockStream.php') {
974-
$this->markTestSkipped('Unable to load mock:// stream.');
975-
}
976-
977-
stream_wrapper_register('mock', 'MockStream\MockStream');
969+
stream_wrapper_register('mock', 'Symfony\Component\Filesystem\Tests\Fixtures\MockStream\MockStream');
978970

979971
$scheme = 'mock://';
980972
$dirname = $scheme.$this->workspace;
981973

982974
$filename = $this->filesystem->tempnam($dirname, 'foo');
983975

984-
$this->assertNotFalse($filename);
985976
$this->assertStringStartsWith($scheme, $filename);
986977
$this->assertFileExists($filename);
987978
}
988979

980+
/**
981+
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
982+
*/
989983
public function testTempnamWithZlibSchemeFails()
990984
{
991985
$scheme = 'compress.zlib://';
992986
$dirname = $scheme.$this->workspace;
993987

994-
$filename = $this->filesystem->tempnam($dirname, 'bar');
995-
996988
// 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);
989+
$this->filesystem->tempnam($dirname, 'bar');
990+
998991
}
999992

1000993
public function testTempnamWithPHPTempSchemeFails()
@@ -1004,40 +997,41 @@ public function testTempnamWithPHPTempSchemeFails()
1004997

1005998
$filename = $this->filesystem->tempnam($dirname, 'bar');
1006999

1007-
$this->assertNotFalse($filename);
10081000
$this->assertStringStartsWith($scheme, $filename);
10091001

10101002
// The php://temp stream deletes the file after close
10111003
$this->assertFileNotExists($filename);
10121004
}
10131005

1006+
/**
1007+
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
1008+
*/
10141009
public function testTempnamWithPharSchemeFails()
10151010
{
10161011
// Skip test if Phar disabled phar.readonly must be 0 in php.ini
1017-
if (!Phar::canWrite()) {
1012+
if (!\Phar::canWrite()) {
10181013
$this->markTestSkipped('This test cannot run when phar.readonly is 1.');
10191014
}
10201015

10211016
$scheme = 'phar://';
10221017
$dirname = $scheme.$this->workspace;
10231018
$pharname = 'foo.phar';
10241019

1025-
$p = new Phar($this->workspace.'/'.$pharname, 0, $pharname);
1026-
$filename = $this->filesystem->tempnam($dirname, $pharname.'/bar');
1027-
1020+
new \Phar($this->workspace.'/'.$pharname, 0, $pharname);
10281021
// 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);
1022+
$this->filesystem->tempnam($dirname, $pharname.'/bar');
10301023
}
10311024

1025+
/**
1026+
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
1027+
*/
10321028
public function testTempnamWithHTTPSchemeFails()
10331029
{
10341030
$scheme = 'http://';
10351031
$dirname = $scheme.$this->workspace;
10361032

1037-
$filename = $this->filesystem->tempnam($dirname, 'bar');
1038-
10391033
// The http:// scheme is read-only
1040-
$this->assertFalse($filename);
1034+
$this->filesystem->tempnam($dirname, 'bar');
10411035
}
10421036

10431037
public function testTempnamOnUnwritableFallsBackToSysTmp()
@@ -1047,7 +1041,6 @@ public function testTempnamOnUnwritableFallsBackToSysTmp()
10471041

10481042
$filename = $this->filesystem->tempnam($dirname, 'bar');
10491043

1050-
$this->assertNotFalse($filename);
10511044
$this->assertStringStartsWith(rtrim($scheme.sys_get_temp_dir(), DIRECTORY_SEPARATOR), $filename);
10521045
$this->assertFileExists($filename);
10531046

0 commit comments

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