]> git.mxchange.org Git - friendica.git/blob - tests/Util/VFSTrait.php
34763b13851167fb9af83384cb7e79a31edd3b48
[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                 ];
25
26                 // create a virtual directory and copy all needed files and folders to it
27                 $this->root = vfsStream::setup('friendica', null, $structure);
28
29                 $this->setConfigFile('config.ini.php');
30                 $this->setConfigFile('settings.ini.php');
31                 $this->setConfigFile('local.ini.php');
32                 $this->setConfigFile('dbstructure.php');
33         }
34
35         /**
36          * Copying a config file from the file system to the Virtual File System
37          *
38          * @param string $filename The filename of the config file
39          */
40         protected function setConfigFile($filename)
41         {
42                 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
43                         '..' . DIRECTORY_SEPARATOR .
44                         'config' . DIRECTORY_SEPARATOR .
45                         $filename;
46
47                 if (file_exists($file)) {
48                         vfsStream::newFile($filename)
49                                 ->at($this->root->getChild('config'))
50                                 ->setContent(file_get_contents($file));
51                 }
52         }
53
54         /**
55          * Delets a config file from the Virtual File System
56          *
57          * @param string $filename The filename of the config file
58          */
59         protected function delConfigFile($filename)
60         {
61                 if ($this->root->hasChild('config/' . $filename)) {
62                         $this->root->removeChild('config/' . $filename);
63                 }
64         }
65 }