]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/Core/Console/ConsoleTest.php
Merge pull request #5921 from annando/ap-video
[friendica.git] / tests / src / Core / Console / ConsoleTest.php
index 0cc5c633591b1825f90872776bfa447b078ea522..75f339e8f5ddba2ae15148bbf1a9c7be00c6b536 100644 (file)
@@ -6,12 +6,15 @@ use Friendica\App;
 use Friendica\BaseObject;
 use Friendica\Database\DBA;
 use Friendica\Test\Util\Intercept;
+use Friendica\Test\Util\VFSTrait;
 use org\bovigo\vfs\vfsStream;
 use org\bovigo\vfs\vfsStreamDirectory;
 use PHPUnit\Framework\TestCase;
 
 abstract class ConsoleTest extends TestCase
 {
+       use VFSTrait;
+
        /**
         * @var MultiUseConsole Extension of the basic Friendica Console for testing purpose
         */
@@ -21,11 +24,6 @@ abstract class ConsoleTest extends TestCase
         */
        protected $app;
 
-       /**
-        * @var vfsStreamDirectory The Stream Directory
-        */
-       protected $root;
-
        protected $stdout;
 
        protected function setUp()
@@ -40,6 +38,11 @@ abstract class ConsoleTest extends TestCase
 
                $this->setUpVfsDir();
 
+               // fake console.php for setting an executable
+               vfsStream::newFile('console.php')
+                       ->at($this->root->getChild('bin'))
+                       ->setContent('<? php');
+
                // Reusable App object
                $this->app = new App($this->root->url());
                BaseObject::setApp($this->app);
@@ -47,7 +50,6 @@ abstract class ConsoleTest extends TestCase
        }
 
        public function execute($args) {
-               DBA::disconnect();
                $this->app->reload();
 
                array_unshift($args, $this->getExecutablePath());
@@ -67,41 +69,4 @@ abstract class ConsoleTest extends TestCase
        protected function getExecutablePath() {
                return $this->root->getChild('bin' . DIRECTORY_SEPARATOR . 'console.php')->url();
        }
-
-       private function setUpVfsDir() {
-               // the used directories inside the App class
-               $structure = [
-                       'config' => [],
-                       'bin' => []
-               ];
-
-               // create a virtual directory and copy all needed files and folders to it
-               $this->root = vfsStream::setup('friendica', null, $structure);
-
-               $this->setConfigFile('config.ini.php');
-               $this->setConfigFile('settings.ini.php');
-               $this->setConfigFile('local.ini.php');
-               $this->setConfigFile('dbstructure.json');
-
-               // fake console.php for setting an executable
-               vfsStream::newFile('console.php')
-                       ->at($this->root->getChild('bin'))
-                       ->setContent('<? php');
-       }
-
-       private function setConfigFile($filename)
-       {
-               $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
-                       '..' . DIRECTORY_SEPARATOR .
-                       '..' . DIRECTORY_SEPARATOR .
-                       '..' . DIRECTORY_SEPARATOR .
-                       'config' . DIRECTORY_SEPARATOR .
-                       $filename;
-
-               if (file_exists($file)) {
-                       vfsStream::newFile($filename)
-                               ->at($this->root->getChild('config'))
-                               ->setContent(file_get_contents($file));
-               }
-       }
 }