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

Implement Configuration\Builder in FrameworkExtension #62

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

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[HttpFoundation] File/File full coverage
  • Loading branch information
pborreli authored and fabpot committed Feb 5, 2011
commit f56a6efbf5b86e9da8204ee53f07eb9f416b0916
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/HttpFoundation/File/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ public function getMimeType()
*/
public function size()
{
if (false === ($size = filesize($this->getPath()))) {
if (false === ($size = @filesize($this->getPath()))) {
throw new FileException(sprintf('Could not read file size of %s', $this->getPath()));
}

Expand All @@ -623,7 +623,7 @@ protected function doMove($directory, $filename)
{
$newPath = $directory . DIRECTORY_SEPARATOR . $filename;

if (!rename($this->getPath(), $newPath)) {
if (!@rename($this->getPath(), $newPath)) {
throw new FileException(sprintf('Could not move file %s to %s', $this->getPath(), $newPath));
}

Expand Down
69 changes: 69 additions & 0 deletions 69 tests/Symfony/Tests/Component/HttpFoundation/File/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ public function testGetPathReturnsAbsolutePath()
$this->assertEquals(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'test.gif', $this->file->getPath());
}

public function test__toString()
{
$this->assertEquals(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'test.gif', (string) $this->file);
}

public function testGetWebPathReturnsPathRelativeToDocumentRoot()
{
File::setDocumentRoot(__DIR__);

$this->assertEquals(__DIR__, File::getDocumentRoot());
$this->assertEquals('/Fixtures/test.gif', $this->file->getWebPath());
}

Expand All @@ -42,11 +48,24 @@ public function testGetWebPathReturnsEmptyPathIfOutsideDocumentRoot()
$this->assertEquals('', $this->file->getWebPath());
}

public function testSetDocumentRootThrowsLogicExceptionWhenNotExists()
{
$this->setExpectedException('LogicException');

File::setDocumentRoot(__DIR__.'/Fixtures/not_here');
}

public function testGetNameReturnsNameWithExtension()
{
$this->assertEquals('test.gif', $this->file->getName());
}

public function testGetExtensionReturnsEmptyString()
{
$file = new File(__DIR__.'/Fixtures/test');
$this->assertEquals('', $file->getExtension());
}

public function testGetExtensionReturnsExtensionWithDot()
{
$this->assertEquals('.gif', $this->file->getExtension());
Expand All @@ -66,6 +85,13 @@ public function testGetMimeTypeUsesMimeTypeGuessers()
$this->assertEquals('image/gif', $this->file->getMimeType());
}

public function testGetDefaultExtensionWithoutGuesser()
{
$file = new File(__DIR__.'/Fixtures/directory/.empty');

$this->assertEquals('.empty', $file->getDefaultExtension());
}

public function testGetDefaultExtensionIsBasedOnMimeType()
{
$file = new File(__DIR__.'/Fixtures/test');
Expand All @@ -76,11 +102,33 @@ public function testGetDefaultExtensionIsBasedOnMimeType()
$this->assertEquals('.gif', $file->getDefaultExtension());
}

public function testConstructWhenFileNotExists()
{
$this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');

new File(__DIR__.'/Fixtures/not_here');
}

public function testSizeReturnsFileSize()
{
$this->assertEquals(filesize($this->file->getPath()), $this->file->size());
}

public function testSizeFailing()
{
$dir = __DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'directory';
$path = $dir.DIRECTORY_SEPARATOR.'test.copy.gif';
@unlink($path);
copy(__DIR__.'/Fixtures/test.gif', $path);

$file = new File($path);
@unlink($path);

$this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\FileException');
$file->size($path);

}

public function testMove()
{
$path = __DIR__.'/Fixtures/test.copy.gif';
Expand Down Expand Up @@ -121,6 +169,27 @@ public function testMoveWithNewName()
@unlink($targetPath);
}

public function testMoveFailing()
{
$path = __DIR__.'/Fixtures/test.copy.gif';
$targetPath = '/thisfolderwontexist';
@unlink($path);
@unlink($targetPath);
copy(__DIR__.'/Fixtures/test.gif', $path);

$file = new File($path);

$this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\FileException');
$file->move($targetPath);

$this->assertFileExists($path);
$this->assertFileNotExists($path.$targetPath.'test.gif');
$this->assertEquals($path, $file->getPath());

@unlink($path);
@unlink($targetPath);
}

public function testRename()
{
$path = __DIR__.'/Fixtures/test.copy.gif';
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.