Skip to content

Commit a91e200

Browse files
committed
[Filesystem] Added unit tests for touch method.
1 parent 7e297db commit a91e200

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,59 @@ public function testMkdirCreatesDirectoriesEvenIfItFailsToCreateOneOfThem()
193193
unlink($basePath.'2');
194194
rmdir($basePath.'3');
195195
}
196+
197+
public function testTouchCreatesEmptyFile()
198+
{
199+
$basePath = sys_get_temp_dir().DIRECTORY_SEPARATOR.time();
200+
$file = $basePath.'1';
201+
202+
$filesystem = new Filesystem();
203+
$filesystem->touch($file);
204+
205+
$this->assertFileExists($basePath.'1');
206+
207+
unlink($basePath.'1');
208+
}
209+
210+
public function testTouchCreatesEmptyFilesFromArray()
211+
{
212+
$basePath = sys_get_temp_dir().DIRECTORY_SEPARATOR.time();
213+
$files = array(
214+
$basePath.'1', $basePath.'2', $basePath.'3'
215+
);
216+
mkdir($basePath);
217+
218+
$filesystem = new Filesystem();
219+
$filesystem->touch($files);
220+
221+
$this->assertFileExists($basePath.'1');
222+
$this->assertFileExists($basePath.'2');
223+
$this->assertFileExists($basePath.'3');
224+
225+
unlink($basePath.'1');
226+
unlink($basePath.'2');
227+
unlink($basePath.'3');
228+
rmdir($basePath);
229+
}
230+
231+
public function testTouchCreatesEmptyFilesFromTraversableObject()
232+
{
233+
$basePath = sys_get_temp_dir().DIRECTORY_SEPARATOR.time();
234+
$files = new \ArrayObject(array(
235+
$basePath.'1', $basePath.'2', $basePath.'3'
236+
));
237+
mkdir($basePath);
238+
239+
$filesystem = new Filesystem();
240+
$filesystem->touch($files);
241+
242+
$this->assertFileExists($basePath.'1');
243+
$this->assertFileExists($basePath.'2');
244+
$this->assertFileExists($basePath.'3');
245+
246+
unlink($basePath.'1');
247+
unlink($basePath.'2');
248+
unlink($basePath.'3');
249+
rmdir($basePath);
250+
}
196251
}

0 commit comments

Comments
 (0)