public function FixtureTrait::fixtureCreateFiles in Mini site 8
Create directories and files with content.
Parameters
array $files: Array of files. If the key is integer - the value considered to be a directory; if the key is string, the key is considered to be a file name and the value is a content of the file. For files within directories, all parent directories are created.
Return value
array Array of created files, keyed by absolute path to the created files.
3 calls to FixtureTrait::fixtureCreateFiles()
- FixtureTest::testFixtureCreateFiles in tests/
src/ Unit/ FixtureTest.php - Test fixtureCreateFiles() method.
- FixtureTrait::fixtureCreateArchive in tests/
src/ Traits/ FixtureTrait.php - Create archive from an array of specified files.
- FixtureTrait::fixtureCreateFile in tests/
src/ Traits/ FixtureTrait.php - Create a single file with content.
File
- tests/
src/ Traits/ FixtureTrait.php, line 57
Class
- FixtureTrait
- Trait FixtureTrait.
Namespace
Drupal\Tests\minisite\TraitsCode
public function fixtureCreateFiles(array $files) {
$paths = [];
$dirs = [];
foreach ($files as $name => $value) {
// Directories are entries with int key.
if (is_int($name)) {
$path = $this->fixtureDir . \DIRECTORY_SEPARATOR . $value;
$dirs[] = $path;
$paths[$path] = $value;
unset($files[$name]);
}
}
$fs = new Filesystem();
$fs
->mkdir($dirs);
foreach ($files as $name => $content) {
$path = $this->fixtureDir . \DIRECTORY_SEPARATOR . $name;
$fs
->dumpFile($path, $content);
$paths[$path] = $name;
}
return $paths;
}