8000 [Filesystem] Added unit tests for remove method. · symfony/symfony@bba0080 · GitHub
[go: up one dir, main page]

Skip to content

Commit bba0080

Browse files
committed
[Filesystem] Added unit tests for remove method.
1 parent 8e861b7 commit bba0080

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

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

+67
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,71 @@ public function testTouchCreatesEmptyFilesFromTraversableObject()
238238
$this->assertFileExists($basePath.'2');
239239
$this->assertFileExists($basePath.'3');
240240
}
241+
242+
public function testRemoveCleansFilesLinksAndDirectoriesIteratively()
243+
{
244+
$basePath = $this->workspace.DIRECTORY_SEPARATOR.'directory'.DIRECTORY_SEPARATOR;
245+
246+
mkdir($basePath);
247+
mkdir($basePath.'dir');
248+
touch($basePath.'file');
249+
link($basePath.'file', $basePath.'link');
250+
251+
$this->filesystem->remove($basePath);
252+
253+
$this->assertTrue(!is_dir($basePath));
254+
}
255+
256+
public function testRemoveCleansArrayOfFilesLinksAndDirectories()
257+
{
258+
$basePath = $this->workspace.DIRECTORY_SEPARATOR;
259+
260+
mkdir($basePath.'dir');
261+
touch($basePath.'file');
262+
link($basePath.'file', $basePath.'link');
263+
264+
$files = array(
265+
$basePath.'dir', $basePath.'file', $basePath.'link'
266+
);
267+
268+
$this->filesystem->remove($files);
269+
270+
$this->assertTrue(!is_dir($basePath.'dir'));
271+
$this->assertTrue(!is_file($basePath.'file'));
272+
$this->assertTrue(!is_link($basePath.'link'));
273+
}
274+
275+
public function testRemoveCleansTraversableObjectOfFilesLinksAndDirectories()
276+
{
277+
$basePath = $this->workspace.DIRECTORY_SEPARATOR;
278+
279+
mkdir($basePath.'dir');
280+
touch($basePath.'file');
281+ link($basePath.'file', $basePath.'link');
282+
283+
$files = new \ArrayObject(array(
284+
$basePath.'dir', $basePath.'file', $basePath.'link'
285+
));
286+
287+
$this->filesystem->remove($files);
288+
289+
$this->assertTrue(!is_dir($basePath.'dir'));
290+
$this->assertTrue(!is_file($basePath.'file'));
291+
$this->assertTrue(!is_link($basePath.'link'));
292+
}
293+
294+
public function testRemoveIgnoresNonExistingFiles()
295+
{
296+
$basePath = $this->workspace.DIRECTORY_SEPARATOR;
297+
298+
mkdir($basePath.'dir');
299+
300+
$files = array(
301+
$basePath.'dir', $basePath.'file'
302+
);
303+
304+
$this->filesystem->remove($files);
305+
306+
$this->assertTrue(!is_dir($basePath.'dir'));
307+
}
241308
}

0 commit comments

Comments
 (0)
0