3 namespace Friendica\Test\src\Core\Console;
6 use Friendica\BaseObject;
7 use Friendica\Database\DBA;
8 use Friendica\Test\Util\Intercept;
9 use org\bovigo\vfs\vfsStream;
10 use org\bovigo\vfs\vfsStreamDirectory;
11 use PHPUnit\Framework\TestCase;
13 abstract class ConsoleTest extends TestCase
16 * @var MultiUseConsole Extension of the basic Friendica Console for testing purpose
20 * @var App The Friendica App
25 * @var vfsStreamDirectory The Stream Directory
31 protected function setUp()
37 if (!getenv('MYSQL_DATABASE')) {
38 $this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.');
43 // Reusable App object
44 $this->app = new App($this->root->url());
45 BaseObject::setApp($this->app);
46 $this->console = new MultiUseConsole();
49 public function execute($args) {
53 array_unshift($args, $this->getExecutablePath());
55 $this->console->reset();
56 $this->console->parseTestArgv($args);
57 $this->console->execute();
59 $returnStr = Intercept::$cache;
65 * @return string returns the path to the console executable during tests
67 protected function getExecutablePath() {
68 return $this->root->getChild('bin' . DIRECTORY_SEPARATOR . 'console.php')->url();
71 private function setUpVfsDir() {
72 // the used directories inside the App class
78 // create a virtual directory and copy all needed files and folders to it
79 $this->root = vfsStream::setup('friendica', null, $structure);
81 $this->setConfigFile('config.ini.php');
82 $this->setConfigFile('settings.ini.php');
83 $this->setConfigFile('local.ini.php');
84 $this->setConfigFile('dbstructure.json');
86 // fake console.php for setting an executable
87 vfsStream::newFile('console.php')
88 ->at($this->root->getChild('bin'))
89 ->setContent('<? php');
92 private function setConfigFile($filename)
94 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
95 '..' . DIRECTORY_SEPARATOR .
96 '..' . DIRECTORY_SEPARATOR .
97 '..' . DIRECTORY_SEPARATOR .
98 'config' . DIRECTORY_SEPARATOR .
101 if (file_exists($file)) {
102 vfsStream::newFile($filename)
103 ->at($this->root->getChild('config'))
104 ->setContent(file_get_contents($file));