3 * @copyright Copyright (C) 2010-2021, 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
48 // create a virtual directory and copy all needed files and folders to it
49 $this->root = vfsStream::setup('friendica', 0777, $structure);
51 $this->setConfigFile('dbstructure.config.php', true);
52 $this->setConfigFile('defaults.config.php', true);
53 $this->setConfigFile('settings.config.php', true);
54 $this->setConfigFile('local.config.php');
58 * Copying a config file from the file system to the Virtual File System
60 * @param string $filename The filename of the config file
61 * @param bool $static True, if the folder `static` instead of `config` should be used
63 protected function setConfigFile(string $filename, bool $static = false)
65 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
66 '..' . DIRECTORY_SEPARATOR .
67 ($static ? 'static' : 'config') . DIRECTORY_SEPARATOR .
70 if (file_exists($file)) {
71 vfsStream::newFile($filename)
72 ->at($this->root->getChild(($static ? 'static' : 'config')))
73 ->setContent(file_get_contents($file));
78 * Delets a config file from the Virtual File System
80 * @param string $filename The filename of the config file
81 * @param bool $static True, if the folder `static` instead of `config` should be used
83 protected function delConfigFile(string $filename, bool $static = false)
85 if ($this->root->hasChild(($static ? 'static' : 'config') . '/' . $filename)) {
86 $this->root->getChild(($static ? 'static' : 'config'))->removeChild($filename);