]> 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 fd09a794528b4a343664c8c5a306ec75a60ac6b7..75f339e8f5ddba2ae15148bbf1a9c7be00c6b536 100644 (file)
@@ -4,11 +4,17 @@ namespace Friendica\Test\src\Core\Console;
 
 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
         */
@@ -30,12 +36,23 @@ abstract class ConsoleTest extends TestCase
                        $this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.');
                }
 
+               $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 = BaseObject::getApp();
+               $this->app = new App($this->root->url());
+               BaseObject::setApp($this->app);
                $this->console = new MultiUseConsole();
        }
 
        public function execute($args) {
+               $this->app->reload();
+
+               array_unshift($args, $this->getExecutablePath());
                Intercept::reset();
                $this->console->reset();
                $this->console->parseTestArgv($args);
@@ -45,4 +62,11 @@ abstract class ConsoleTest extends TestCase
                Intercept::reset();
                return $returnStr;
        }
+
+       /**
+        * @return string returns the path to the console executable during tests
+        */
+       protected function getExecutablePath() {
+               return $this->root->getChild('bin' . DIRECTORY_SEPARATOR . 'console.php')->url();
+       }
 }