diff --git a/src/Task/FileSystem/CopyDir.php b/src/Task/FileSystem/CopyDir.php index 45f31993f..8a4be564a 100644 --- a/src/Task/FileSystem/CopyDir.php +++ b/src/Task/FileSystem/CopyDir.php @@ -17,6 +17,9 @@ */ class CopyDir extends BaseDir { + /** @var int $chmod */ + protected $chmod = 0755; + public function run() { foreach ($this->dirs as $src => $dst) { @@ -26,13 +29,38 @@ public function run() return Result::success($this); } + /** + * Sets the default folder permissions for the destination if it doesn't exist + * + * @link http://en.wikipedia.org/wiki/Chmod + * @link http://php.net/manual/en/function.mkdir.php + * @link http://php.net/manual/en/function.chmod.php + * @param int $value + * @return $this + */ + public function dirPermissions($value) + { + $this->chmod = (int)$value; + return $this; + } + + /** + * Copies a directory to another location. + * + * @param string $src Source directory + * @param string $dst Destination directory + * @throws \Robo\Exception\TaskException + * @return void + */ protected function copyDir($src, $dst) { $dir = @opendir($src); if (false === $dir) { throw new TaskException($this, "Cannot open source directory '" . $src . "'"); } - @mkdir($dst); + if (!is_dir($dst)) { + mkdir($dst, $this->chmod, true); + } while (false !== ($file = readdir($dir))) { if (($file !== '.') && ($file !== '..')) { $srcFile = $src . '/' . $file; diff --git a/tests/_data/claypit/some/deeply/existing_file b/tests/_data/claypit/some/deeply/existing_file new file mode 100644 index 000000000..37cfa2826 --- /dev/null +++ b/tests/_data/claypit/some/deeply/existing_file @@ -0,0 +1 @@ +some existing file diff --git a/tests/_data/claypit/some/deeply/nested/structu.re b/tests/_data/claypit/some/deeply/nested/structu.re new file mode 100644 index 000000000..98a202cbc --- /dev/null +++ b/tests/_data/claypit/some/deeply/nested/structu.re @@ -0,0 +1 @@ +Just a file diff --git a/tests/_data/claypit/some_destination/deeply/existing_file b/tests/_data/claypit/some_destination/deeply/existing_file new file mode 100644 index 000000000..1765b73ba --- /dev/null +++ b/tests/_data/claypit/some_destination/deeply/existing_file @@ -0,0 +1 @@ +some_destination existing file diff --git a/tests/cli/CliGuy.php b/tests/cli/CliGuy.php index 206ffa51b..c45bf69d6 100644 --- a/tests/cli/CliGuy.php +++ b/tests/cli/CliGuy.php @@ -748,7 +748,7 @@ public function taskConcat($files) { * [!] Method is generated. Documentation taken from corresponding module. * * @param $file - * @return ReplaceInFile + * @return Replace * @see \Codeception\Module\CliHelper::taskReplaceInFile() */ public function taskReplaceInFile($file) { @@ -760,7 +760,7 @@ public function taskReplaceInFile($file) { * [!] Method is generated. Documentation taken from corresponding module. * * @param $file - * @return WriteToFile + * @return Write * @see \Codeception\Module\CliHelper::taskWriteToFile() */ public function taskWriteToFile($file) { @@ -807,7 +807,7 @@ public function taskCopyDir($dirs) { /** * [!] Method is generated. Documentation taken from corresponding module. * - * @return Filesystem + * @return FilesystemStack * @see \Codeception\Module\CliHelper::taskFilesystemStack() */ public function taskFilesystemStack() { diff --git a/tests/cli/CopyDirOverwritesFilesCept.php b/tests/cli/CopyDirOverwritesFilesCept.php new file mode 100644 index 000000000..133d6e7f8 --- /dev/null +++ b/tests/cli/CopyDirOverwritesFilesCept.php @@ -0,0 +1,11 @@ +wantTo('overwrite a file with CopyDir task'); +$I->amInPath(codecept_data_dir() . 'sandbox'); +$I->seeDirFound('some'); +$I->seeFileFound('existing_file', 'some'); +$I->taskCopyDir(['some' => 'some_destination']) + ->run(); +$I->seeFileFound('existing_file', 'some_destination/deeply'); +$I->openFile('some_destination/deeply/existing_file'); +$I->seeInThisFile('some existing file'); diff --git a/tests/cli/CopyDirRecursiveCept.php b/tests/cli/CopyDirRecursiveCept.php new file mode 100644 index 000000000..7ca8e4fd1 --- /dev/null +++ b/tests/cli/CopyDirRecursiveCept.php @@ -0,0 +1,10 @@ +wantTo('copy dir recursively with CopyDir task'); +$I->amInPath(codecept_data_dir() . 'sandbox'); +$I->seeDirFound('some/deeply/nested'); +$I->seeFileFound('structu.re', 'some/deeply/nested'); +$I->taskCopyDir(['some/deeply' => 'some_destination/deeply']) + ->run(); +$I->seeDirFound('some_destination/deeply/nested'); +$I->seeFileFound('structu.re', 'some_destination/deeply/nested');