Skip to content

Commit

Permalink
[TASK] Functional $pathsToProvideInTestInstance improvements
Browse files Browse the repository at this point in the history
FunctionalTestCase property $pathsToProvideInTestInstance handles
creation of target parent directory if it does not exist and can
copy directory structures recursive.

Closes: #107
  • Loading branch information
lolli42 authored and ohader committed May 6, 2019
1 parent e963d70 commit e2a7c80
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
19 changes: 13 additions & 6 deletions Classes/Core/Functional/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,31 @@ abstract class FunctionalTestCase extends BaseTestCase
* The array keys are the source paths and the array values are the destination
* paths, example:
*
* array(
* [
* 'typo3/sysext/impext/Tests/Functional/Fixtures/Folders/fileadmin/user_upload' =>
* 'fileadmin/user_upload',
* 'typo3conf/ext/my_own_ext/Tests/Functional/Fixtures/Folders/uploads/tx_myownext' =>
* 'uploads/tx_myownext'
* );
* ]
*
* To be able to link from my_own_ext the extension path needs also to be registered in
* property $testExtensionsToLoad
*
* @var array
* @var string[]
*/
protected $pathsToLinkInTestInstance = [];

/**
* Similar to $pathsToLinkInTestInstance, with the difference that given
* paths are really duplicated and provided in the instance - instead of
* using symbolic links.
* using symbolic links. Examples:
*
* [
* // Copy an entire directory recursive to fileadmin
* 'typo3/sysext/lowlevel/Tests/Functional/Fixtures/testImages/' => 'fileadmin/',
* // Copy a single file into some deep destination directory
* 'typo3/sysext/lowlevel/Tests/Functional/Fixtures/testImage/someImage.jpg' => 'fileadmin/_processed_/0/a/someImage.jpg',
* ]
*
* @var string[]
*/
Expand Down Expand Up @@ -183,9 +190,9 @@ abstract class FunctionalTestCase extends BaseTestCase
* To create additional folders add the paths to this array. Given paths are expected to be
* relative to the test instance root and have to begin with a slash. Example:
*
* array(
* [
* 'fileadmin/user_upload'
* );
* ]
*
* @var array
*/
Expand Down
41 changes: 40 additions & 1 deletion Classes/Core/Testbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,16 @@ public function providePathsInTestInstance(string $instancePath, array $pathsToP
);
}
$destinationPath = $instancePath . '/' . ltrim($designationIdentifier, '/');
$success = copy($sourcePath, $destinationPath);
$destinationParentPath = dirname($destinationPath);
if (is_file($sourcePath)) {
if (!is_dir($destinationParentPath)) {
// Create parent dir if it does not exist yet
mkdir($destinationParentPath, 0775, true);
}
$success = copy($sourcePath, $destinationPath);
} else {
$success = $this->copyRecursive($sourcePath, $destinationPath);
}
if (!$success) {
throw new Exception(
'Can not copy the path ' . $sourcePath . ' to ' . $destinationPath,
Expand Down Expand Up @@ -782,6 +791,36 @@ public static function resetTableSequences(Connection $connection, string $table
}
}

/**
* Copy a directory structure $from a source $to a destination,
*
* @param $from Absolute source path
* @param $to Absolute target path
* @return bool True if all went well
*/
protected function copyRecursive($from, $to) {
$dir = opendir($from);
if (!file_exists($to)) {
mkdir($to, 0775, true);
}
$result = true;
while (false !== ($file = readdir($dir))) {
if ($file == '.' || $file == '..') {
continue;
}
if (is_dir($from . DIRECTORY_SEPARATOR . $file)) {
$success = $this->copyRecursive($from . DIRECTORY_SEPARATOR . $file, $to . DIRECTORY_SEPARATOR . $file);
$result = $result & $success;
}
else {
$success = copy($from . DIRECTORY_SEPARATOR . $file, $to . DIRECTORY_SEPARATOR . $file);
$result = $result & $success;
}
}
closedir($dir);
return $result;
}

/**
* Get Path to vendor dir
* Since we are installed in vendor dir, we can safely assume the path of the vendor
Expand Down

0 comments on commit e2a7c80

Please sign in to comment.