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 61a3afd

Browse filesBrowse files
committed
Removed unused logic in MockStream
1 parent 247266c commit 61a3afd
Copy full SHA for 61a3afd

File tree

3 files changed

+30
-230
lines changed
Filter options

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
@@ -459,34 +459,30 @@ public function isAbsolutePath($file)
459459
* @param string $prefix The prefix of the generated temporary filename.
460460
* Note: Windows uses only the first three characters of prefix.
461461
*
462-
* @return string The new temporary filename (with path), or false on failure.
462+
* @return string The new temporary filename (with path), or throw an exception on failure.
463463
*/
464464
public function tempnam($dir, $prefix)
465465
{
466-
$limit = 10;
467466
list($scheme, $hierarchy) = $this->getSchemeAndHierarchy($dir);
468467

469468
// If no scheme or scheme is "file" create temp file in local filesystem
470469
if (null === $scheme || 'file' === $scheme) {
471-
472470
$tmpFile = tempnam($hierarchy, $prefix);
473471

474472
// If tempnam failed or no scheme return the filename otherwise prepend the scheme
475-
476-
if (null !== $scheme) {
477-
return $scheme.'://'.$tmpFile;
478-
}
479-
480473
if (false !== $tmpFile) {
474+
if (null !== $scheme) {
475+
return $scheme.'://'.$tmpFile;
476+
}
477+
481478
return $tmpFile;
482479
}
483480

484-
throw new IOException('A temporary file could not be created');
481+
throw new IOException('A temporary file could not be created.');
485482
}
486483

487-
// Loop until we create a valid temp file or have reached $limit attempts
488-
for ($i = 0; $i < $limit; ++$i) {
489-
484+
// Loop until we create a valid temp file or have reached 10 attempts
485+
for ($i = 0; $i < 10; ++$i) {
490486
// Create a unique filename
491487
$tmpFile = $dir.'/'.$prefix.uniqid(mt_rand(), true);
492488

@@ -503,10 +499,9 @@ public function tempnam($dir, $prefix)
503499
@fclose($handle);
504500

505501
return $tmpFile;
506-
507502
}
508503

509-
return false;
504+
throw new IOException('A temporary file could not be created.');
510505
}
511506

512507
/**
@@ -570,7 +565,6 @@ private function getSchemeAndHierarchy($filename)
570565
{
571566
$components = explode('://', $filename, 2);
572567

573-
return count($components) === 2 ? array($components[0], $components[1]) : array(null, $components[0]);
568+
return 2 === count($components) ? array($components[0], $components[1]) : array(null, $components[0]);
574569
}
575-
576570
}

‎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
*/
@@ -953,7 +952,6 @@ public function testTempnam()
953952

954953
$filename = $this->filesystem->tempnam($dirname, 'foo');
955954

956-
$this->assertNotFalse($filename);
957955
$this->assertFileExists($filename);
958956
}
959957

@@ -964,39 +962,34 @@ public function testTempnamWithFileScheme()
964962

965963
$filename = $this->filesystem->tempnam($dirname, 'foo');
966964

967-
$this->assertNotFalse($filename);
968965
$this->assertStringStartsWith($scheme, $filename);
969966
$this->assertFileExists($filename);
970967
}
971968

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

981973
$scheme = 'mock://';
982974
$dirname = $scheme.$this->workspace;
983975

984976
$filename = $this->filesystem->tempnam($dirname, 'foo');
985977

986-
$this->assertNotFalse($filename);
987978
$this->assertStringStartsWith($scheme, $filename);
988979
$this->assertFileExists($filename);
989980
}
990981

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

996-
$filename = $this->filesystem->tempnam($dirname, 'bar');
997-
998990
// The compress.zlib:// stream does not support mode x: creates the file, errors "failed to open stream: operation failed" and returns false
999-
$this->assertFalse($filename);
991+
$this->filesystem->tempnam($dirname, 'bar');
992+
1000993
}
1001994

1002995
public function testTempnamWithPHPTempSchemeFails()
@@ -1006,40 +999,41 @@ public function testTempnamWithPHPTempSchemeFails()
1006999

10071000
$filename = $this->filesystem->tempnam($dirname, 'bar');
10081001

1009-
$this->assertNotFalse($filename);
10101002
$this->assertStringStartsWith($scheme, $filename);
10111003

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

1008+
/**
1009+
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
1010+
*/
10161011
public function testTempnamWithPharSchemeFails()
10171012
{
10181013
// Skip test if Phar disabled phar.readonly must be 0 in php.ini
1019-
if (!Phar::canWrite()) {
1014+
if (!\Phar::canWrite()) {
10201015
$this->markTestSkipped('This test cannot run when phar.readonly is 1.');
10211016
}
10221017

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

1027-
$p = new Phar($this->workspace.'/'.$pharname, 0, $pharname);
1028-
$filename = $this->filesystem->tempnam($dirname, $pharname.'/bar');
1029-
1022+
new \Phar($this->workspace.'/'.$pharname, 0, $pharname);
10301023
// 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
1031-
$this->assertFalse($filename);
1024+
$this->filesystem->tempnam($dirname, $pharname.'/bar');
10321025
}
10331026

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

1039-
$filename = $this->filesystem->tempnam($dirname, 'bar');
1040-
10411035
// The http:// scheme is read-only
1042-
$this->assertFalse($filename);
1036+
$this->filesystem->tempnam($dirname, 'bar');
10431037
}
10441038

10451039
public function testTempnamOnUnwritableFallsBackToSysTmp()
@@ -1049,7 +1043,6 @@ public function testTempnamOnUnwritableFallsBackToSysTmp()
10491043

10501044
$filename = $this->filesystem->tempnam($dirname, 'bar');
10511045

1052-
$this->assertNotFalse($filename);
10531046
$this->assertStringStartsWith(rtrim($scheme.sys_get_temp_dir(), DIRECTORY_SEPARATOR), $filename);
10541047
$this->assertFileExists($filename);
10551048

0 commit comments

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