Use DICE for Console

- Use Friendica\Core\Console as Controller for DI-library
- Refactor every console command to use DICE (when possible)
- Adjusting tests
This commit is contained in:
Philipp Holzer 2019-07-28 22:06:33 +02:00
parent b8a336cc0d
commit a60eb9e33d
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
20 changed files with 400 additions and 166 deletions

View file

@ -2,24 +2,28 @@
namespace Friendica\Test\src\Console;
use Dice\Dice;
use Friendica\App;
use Friendica\BaseObject;
use Friendica\Console\AutomaticInstallation;
use Friendica\Core\Config\Cache\ConfigCache;
use Friendica\Core\Installer;
use Friendica\Core\L10n\L10n;
use Friendica\Core\Logger;
use Friendica\Database\Database;
use Friendica\Test\Util\DBAMockTrait;
use Friendica\Test\Util\DBStructureMockTrait;
use Friendica\Test\Util\RendererMockTrait;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\BaseURL;
use Friendica\Util\Logger\VoidLogger;
use Mockery\MockInterface;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamFile;
/**
* @requires PHP 7.0
*/
class AutomaticInstallationConsoleTest extends ConsoleTest
{
use VFSTrait;
use DBAMockTrait;
use DBStructureMockTrait;
use RendererMockTrait;
@ -38,28 +42,49 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
*/
private $configCache;
/**
* @var App\Mode
*/
private $appMode;
/**
* @var Database
*/
private $dba;
/**
* @var Dice|MockInterface
*/
private $dice;
public function setUp()
{
$this->markTestSkipped('Needs class \'Installer\' as constructing argument for console tests');
parent::setUp();
$this->setUpVfsDir();;
if ($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')) {
$this->root->getChild('config')
->removeChild('local.config.php');
}
$this->dice = \Mockery::mock(Dice::class)->makePartial();
$l10nMock = \Mockery::mock(L10n::class);
$l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
\Friendica\Core\L10n::init($l10nMock);
$this->dice->shouldReceive('create')
->with(L10n::class)
->andReturn($l10nMock);
BaseObject::setDependencyInjection($this->dice);
$this->configCache = new ConfigCache();
$this->configCache->set('system', 'basepath', $this->root->url());
$this->configCache->set('config', 'php_path', trim(shell_exec('which php')));
$this->configCache->set('system', 'theme', 'smarty3');
$this->mockApp($this->root, true);
$this->configMock->shouldReceive('set')->andReturnUsing(function ($cat, $key, $value) {
if ($key !== 'basepath') {
return $this->configCache->set($cat, $key, $value);