3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Test\Util;
25 use org\bovigo\vfs\vfsStream;
26 use org\bovigo\vfs\vfsStreamDirectory;
31 * @var vfsStreamDirectory The Stream Directory
36 * Sets up the Virtual File System for Friendica with common files (config, dbstructure)
38 protected function setUpVfsDir() {
39 // the used directories inside the App class
49 // create a virtual directory and copy all needed files and folders to it
50 $this->root = vfsStream::setup('friendica', 0777, $structure);
52 $this->setConfigFile('static' . DIRECTORY_SEPARATOR . 'dbstructure.config.php', true);
53 $this->setConfigFile('static' . DIRECTORY_SEPARATOR . 'dbview.config.php', true);
54 $this->setConfigFile('static' . DIRECTORY_SEPARATOR . 'defaults.config.php', true);
55 $this->setConfigFile('static' . DIRECTORY_SEPARATOR . 'settings.config.php', true);
57 'mods' . DIRECTORY_SEPARATOR . 'local.config.ci.php',
58 false, 'local.config.php'
63 * Copying a config file from the file system to the Virtual File System
65 * @param string $sourceFilePath The filename of the config file
66 * @param bool $static True, if the folder `static` instead of `config` should be used
68 public function setConfigFile(string $sourceFilePath, bool $static = false, string $targetFileName = null)
70 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
71 '..' . DIRECTORY_SEPARATOR .
74 if (file_exists($file)) {
75 if (empty($targetFileName)) {
76 $tmpArray = preg_split('/\\' . DIRECTORY_SEPARATOR . '/', $sourceFilePath);
77 $targetFileName = array_pop($tmpArray);
79 vfsStream::newFile($targetFileName)
80 ->at($this->root->getChild(($static ? 'static' : 'config')))
81 ->setContent(file_get_contents($file));
83 throw new \Exception(sprintf('Unexpected missing config \'%s\'', $file));
88 * Deletes a config file from the Virtual File System
90 * @param string $filename The filename of the config file
91 * @param bool $static True, if the folder `static` instead of `config` should be used
93 protected function delConfigFile(string $filename, bool $static = false)
95 if ($this->root->hasChild(($static ? 'static' : 'config') . '/' . $filename)) {
96 $this->root->getChild(($static ? 'static' : 'config'))->removeChild($filename);