]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/Console/ConsoleTest.php
Merge pull request #5848 from nupplaphil/friendica-5847
[friendica.git] / tests / src / Core / Console / ConsoleTest.php
1 <?php
2
3 namespace Friendica\Test\src\Core\Console;
4
5 use Friendica\App;
6 use Friendica\BaseObject;
7 use Friendica\Database\DBA;
8 use Friendica\Test\Util\Intercept;
9 use Friendica\Test\Util\VFSTrait;
10 use org\bovigo\vfs\vfsStream;
11 use org\bovigo\vfs\vfsStreamDirectory;
12 use PHPUnit\Framework\TestCase;
13
14 abstract class ConsoleTest extends TestCase
15 {
16         use VFSTrait;
17
18         /**
19          * @var MultiUseConsole Extension of the basic Friendica Console for testing purpose
20          */
21         private $console;
22         /**
23          * @var App The Friendica App
24          */
25         protected $app;
26
27         protected $stdout;
28
29         protected function setUp()
30         {
31                 parent::setUp();
32
33                 Intercept::setUp();
34
35                 if (!getenv('MYSQL_DATABASE')) {
36                         $this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.');
37                 }
38
39                 $this->setUpVfsDir();
40
41                 // fake console.php for setting an executable
42                 vfsStream::newFile('console.php')
43                         ->at($this->root->getChild('bin'))
44                         ->setContent('<? php');
45
46                 // Reusable App object
47                 $this->app = new App($this->root->url());
48                 BaseObject::setApp($this->app);
49                 $this->console = new MultiUseConsole();
50         }
51
52         public function execute($args) {
53                 DBA::disconnect();
54                 $this->app->reload();
55
56                 array_unshift($args, $this->getExecutablePath());
57                 Intercept::reset();
58                 $this->console->reset();
59                 $this->console->parseTestArgv($args);
60                 $this->console->execute();
61
62                 $returnStr = Intercept::$cache;
63                 Intercept::reset();
64                 return $returnStr;
65         }
66
67         /**
68          * @return string returns the path to the console executable during tests
69          */
70         protected function getExecutablePath() {
71                 return $this->root->getChild('bin' . DIRECTORY_SEPARATOR . 'console.php')->url();
72         }
73 }