]> git.mxchange.org Git - friendica.git/blob - tests/Util/VFSTrait.php
Merge pull request #6638 from Ixiter/develop-markdown-anchors
[friendica.git] / tests / Util / VFSTrait.php
1 <?php
2
3 namespace Friendica\Test\Util;
4
5
6 use org\bovigo\vfs\vfsStream;
7 use org\bovigo\vfs\vfsStreamDirectory;
8
9 trait VFSTrait
10 {
11         /**
12          * @var vfsStreamDirectory The Stream Directory
13          */
14         protected $root;
15
16         /**
17          * Sets up the Virtual File System for Friendica with common files (config, dbstructure)
18          */
19         protected function setUpVfsDir() {
20                 // the used directories inside the App class
21                 $structure = [
22                         'config' => [],
23                         'bin' => [],
24                         'test' => []
25                 ];
26
27                 // create a virtual directory and copy all needed files and folders to it
28                 $this->root = vfsStream::setup('friendica', null, $structure);
29
30                 $this->setConfigFile('defaults.config.php');
31                 $this->setConfigFile('settings.config.php');
32                 $this->setConfigFile('local.config.php');
33                 $this->setConfigFile('dbstructure.config.php');
34         }
35
36         /**
37          * Copying a config file from the file system to the Virtual File System
38          *
39          * @param string $filename The filename of the config file
40          */
41         protected function setConfigFile($filename)
42         {
43                 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
44                         '..' . DIRECTORY_SEPARATOR .
45                         'config' . DIRECTORY_SEPARATOR .
46                         $filename;
47
48                 if (file_exists($file)) {
49                         vfsStream::newFile($filename)
50                                 ->at($this->root->getChild('config'))
51                                 ->setContent(file_get_contents($file));
52                 }
53         }
54
55         /**
56          * Delets a config file from the Virtual File System
57          *
58          * @param string $filename The filename of the config file
59          */
60         protected function delConfigFile($filename)
61         {
62                 if ($this->root->hasChild('config/' . $filename)) {
63                         $this->root->getChild('config')->removeChild($filename);
64                 }
65         }
66 }