Skip to content

Commit

Permalink
[Filesystem] Added unit tests for remove method.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzal committed Apr 6, 2012
1 parent 8e861b7 commit bba0080
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Expand Up @@ -238,4 +238,71 @@ public function testTouchCreatesEmptyFilesFromTraversableObject()
$this->assertFileExists($basePath.'2');
$this->assertFileExists($basePath.'3');
}

public function testRemoveCleansFilesLinksAndDirectoriesIteratively()
{
$basePath = $this->workspace.DIRECTORY_SEPARATOR.'directory'.DIRECTORY_SEPARATOR;

mkdir($basePath);
mkdir($basePath.'dir');
touch($basePath.'file');
link($basePath.'file', $basePath.'link');

$this->filesystem->remove($basePath);

$this->assertTrue(!is_dir($basePath));
}

public function testRemoveCleansArrayOfFilesLinksAndDirectories()
{
$basePath = $this->workspace.DIRECTORY_SEPARATOR;

mkdir($basePath.'dir');
touch($basePath.'file');
link($basePath.'file', $basePath.'link');

$files = array(
$basePath.'dir', $basePath.'file', $basePath.'link'
);

$this->filesystem->remove($files);

$this->assertTrue(!is_dir($basePath.'dir'));
$this->assertTrue(!is_file($basePath.'file'));
$this->assertTrue(!is_link($basePath.'link'));
}

public function testRemoveCleansTraversableObjectOfFilesLinksAndDirectories()
{
$basePath = $this->workspace.DIRECTORY_SEPARATOR;

mkdir($basePath.'dir');
touch($basePath.'file');
link($basePath.'file', $basePath.'link');

$files = new \ArrayObject(array(
$basePath.'dir', $basePath.'file', $basePath.'link'
));

$this->filesystem->remove($files);

$this->assertTrue(!is_dir($basePath.'dir'));
$this->assertTrue(!is_file($basePath.'file'));
$this->assertTrue(!is_link($basePath.'link'));
}

public function testRemoveIgnoresNonExistingFiles()
{
$basePath = $this->workspace.DIRECTORY_SEPARATOR;

mkdir($basePath.'dir');

$files = array(
$basePath.'dir', $basePath.'file'
);

$this->filesystem->remove($files);

$this->assertTrue(!is_dir($basePath.'dir'));
}
}

0 comments on commit bba0080

Please sign in to comment.