]> git.mxchange.org Git - friendica.git/blobdiff - tests/Util/VFSTrait.php
Merge pull request #8102 from annando/servertest
[friendica.git] / tests / Util / VFSTrait.php
index d51ba5b6a5ebab9b21f004b2335286232c8c9f18..ecf0880d29b68729da0ec46e41003521639e3165 100644 (file)
@@ -13,40 +13,58 @@ trait VFSTrait
         */
        protected $root;
 
+       /**
+        * Sets up the Virtual File System for Friendica with common files (config, dbstructure)
+        */
        protected function setUpVfsDir() {
                // the used directories inside the App class
                $structure = [
                        'config' => [],
-                       'bin' => []
+                       'bin' => [],
+                       'static' => [],
+                       'test' => [],
+                       'logs' => [],
                ];
 
                // create a virtual directory and copy all needed files and folders to it
-               $this->root = vfsStream::setup('friendica', null, $structure);
+               $this->root = vfsStream::setup('friendica', 0777, $structure);
 
-               $this->setConfigFile('config.ini.php');
-               $this->setConfigFile('settings.ini.php');
-               $this->setConfigFile('local.ini.php');
-               $this->setConfigFile('dbstructure.php');
+               $this->setConfigFile('dbstructure.config.php', true);
+               $this->setConfigFile('defaults.config.php', true);
+               $this->setConfigFile('settings.config.php', true);
+               $this->setConfigFile('local.config.php');
        }
 
-       protected function setConfigFile($filename)
+       /**
+        * Copying a config file from the file system to the Virtual File System
+        *
+        * @param string $filename The filename of the config file
+        * @param bool $static True, if the folder `static` instead of `config` should be used
+        */
+       protected function setConfigFile($filename, bool $static = false)
        {
                $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
                        '..' . DIRECTORY_SEPARATOR .
-                       'config' . DIRECTORY_SEPARATOR .
+                       ($static ? 'static' : 'config') . DIRECTORY_SEPARATOR .
                        $filename;
 
                if (file_exists($file)) {
                        vfsStream::newFile($filename)
-                               ->at($this->root->getChild('config'))
+                               ->at($this->root->getChild(($static ? 'static' : 'config')))
                                ->setContent(file_get_contents($file));
                }
        }
 
-       protected function delConfigFile($filename)
+       /**
+        * Delets a config file from the Virtual File System
+        *
+        * @param string $filename The filename of the config file
+        * @param bool $static True, if the folder `static` instead of `config` should be used
+        */
+       protected function delConfigFile($filename, bool $static = false)
        {
-               if ($this->root->hasChild('config/' . $filename)) {
-                       $this->root->removeChild('config/' . $filename);
+               if ($this->root->hasChild(($static ? 'static' : 'config') . '/' . $filename)) {
+                       $this->root->getChild(($static ? 'static' : 'config'))->removeChild($filename);
                }
        }
 }