]> git.mxchange.org Git - friendica.git/blob - tests/Util/VFSTrait.php
Switch from dbstructure.json to dbstructure.php
[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         protected function setUpVfsDir() {
17                 // the used directories inside the App class
18                 $structure = [
19                         'config' => [],
20                         'bin' => []
21                 ];
22
23                 // create a virtual directory and copy all needed files and folders to it
24                 $this->root = vfsStream::setup('friendica', null, $structure);
25
26                 $this->setConfigFile('config.ini.php');
27                 $this->setConfigFile('settings.ini.php');
28                 $this->setConfigFile('local.ini.php');
29                 $this->setConfigFile('dbstructure.php');
30         }
31
32         protected function setConfigFile($filename)
33         {
34                 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
35                         '..' . DIRECTORY_SEPARATOR .
36                         'config' . DIRECTORY_SEPARATOR .
37                         $filename;
38
39                 if (file_exists($file)) {
40                         vfsStream::newFile($filename)
41                                 ->at($this->root->getChild('config'))
42                                 ->setContent(file_get_contents($file));
43                 }
44         }
45
46         protected function delConfigFile($filename)
47         {
48                 if ($this->root->hasChild('config/' . $filename)) {
49                         $this->root->removeChild('config/' . $filename);
50                 }
51         }
52 }