From e2f7b99f1694331a25012eec10c5bd8cd247bec9 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Mon, 10 Jun 2013 20:22:34 +0300 Subject: [PATCH] Unit test for "yii\helpers\base\FileHelper" has been created. --- tests/unit/framework/helpers/FileHelperTest.php | 71 +++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/unit/framework/helpers/FileHelperTest.php diff --git a/tests/unit/framework/helpers/FileHelperTest.php b/tests/unit/framework/helpers/FileHelperTest.php new file mode 100644 index 0000000..89a5a02 --- /dev/null +++ b/tests/unit/framework/helpers/FileHelperTest.php @@ -0,0 +1,71 @@ +testFilePath = Yii::getAlias('@yiiunit/runtime') . DIRECTORY_SEPARATOR . get_class($this); + $this->createDir($this->testFilePath); + } + + public function tearDown() + { + $this->removeDir($this->testFilePath); + } + + /** + * Creates directory. + * @param string $dirName directory full name. + */ + protected function createDir($dirName) + { + if (!file_exists($dirName)) { + mkdir($dirName, 0777, true); + } + } + + /** + * Removes directory. + * @param string $dirName directory full name. + */ + protected function removeDir($dirName) + { + if (!empty($dirName) && file_exists($dirName)) { + exec("rm -rf {$dirName}"); + } + } + + // Tests : + + public function testCopyDirectory() { + $basePath = $this->testFilePath; + $srcDirName = $basePath . DIRECTORY_SEPARATOR . 'test_src_dir'; + mkdir($srcDirName, 0777, true); + $files = array( + 'file1.txt' => 'file 1 content', + 'file2.txt' => 'file 2 content', + ); + foreach ($files as $name => $content) { + file_put_contents($srcDirName . DIRECTORY_SEPARATOR . $name, $content); + } + $dstDirName = $basePath . DIRECTORY_SEPARATOR . 'test_dst_dir'; + + FileHelper::copyDirectory($srcDirName, $dstDirName); + + $this->assertTrue(file_exists($dstDirName), 'Destination directory does not exist!'); + foreach ($files as $name => $content) { + $fileName = $dstDirName . DIRECTORY_SEPARATOR . $name; + $this->assertTrue(file_exists($fileName), 'Directory file is missing!'); + $this->assertEquals($content, file_get_contents($fileName), 'Incorrect file content!'); + } + } +} \ No newline at end of file