mirror of
https://github.com/friendica/friendica
synced 2025-04-23 23:10:10 +00:00
Bugfixing & Enhancement
- Added Mocking Engine for App, DBA, Config - Using Mocking Engine for AutomaticInstallationConsoleTest - Using Mocking Engine for ConfigConsoleTest - Removing MultiUserConsole - Workaround
This commit is contained in:
parent
f7147fae96
commit
0e22c18a9d
10 changed files with 515 additions and 175 deletions
|
@ -2,27 +2,16 @@
|
|||
|
||||
namespace Friendica\Test\src\Core\Console;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Database\DBA;
|
||||
use Asika\SimpleConsole\Console;
|
||||
use Friendica\Test\Util\AppMockTrait;
|
||||
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
|
||||
*/
|
||||
private $console;
|
||||
/**
|
||||
* @var App The Friendica App
|
||||
*/
|
||||
protected $app;
|
||||
use AppMockTrait;
|
||||
|
||||
protected $stdout;
|
||||
|
||||
|
@ -30,43 +19,37 @@ abstract class ConsoleTest extends TestCase
|
|||
{
|
||||
parent::setUp();
|
||||
|
||||
Intercept::setUp();
|
||||
|
||||
if (!getenv('MYSQL_DATABASE')) {
|
||||
$this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.');
|
||||
}
|
||||
|
||||
Intercept::setUp();
|
||||
|
||||
$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);
|
||||
$this->console = new MultiUseConsole();
|
||||
$this->mockApp($this->root);
|
||||
}
|
||||
|
||||
public function execute($args) {
|
||||
$this->app->reload();
|
||||
protected function tearDown()
|
||||
{
|
||||
\Mockery::close();
|
||||
|
||||
array_unshift($args, $this->getExecutablePath());
|
||||
Intercept::reset();
|
||||
$this->console->reset();
|
||||
$this->console->parseTestArgv($args);
|
||||
$this->console->execute();
|
||||
|
||||
$returnStr = Intercept::$cache;
|
||||
Intercept::reset();
|
||||
return $returnStr;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string returns the path to the console executable during tests
|
||||
* Dumps the execution of an console output to a string and returns it
|
||||
*
|
||||
* @param Console $console The current console instance
|
||||
*
|
||||
* @return string the output of the execution
|
||||
*/
|
||||
protected function getExecutablePath() {
|
||||
return $this->root->getChild('bin' . DIRECTORY_SEPARATOR . 'console.php')->url();
|
||||
protected function dumpExecute($console)
|
||||
{
|
||||
Intercept::reset();
|
||||
$console->execute();
|
||||
$returnStr = Intercept::$cache;
|
||||
Intercept::reset();
|
||||
|
||||
return $returnStr;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue