Merge pull request #7444 from nupplaphil/task/dice_console

Use DICE for Console
This commit is contained in:
Hypolite Petovan 2019-07-31 14:07:45 -04:00 committed by GitHub
commit e9f0c4dbfb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 407 additions and 166 deletions

View file

@ -6,6 +6,4 @@ require dirname(__DIR__) . '/vendor/autoload.php';
$dice = new \Dice\Dice(); $dice = new \Dice\Dice();
$dice = $dice->addRules(include __DIR__ . '/../static/dependencies.config.php'); $dice = $dice->addRules(include __DIR__ . '/../static/dependencies.config.php');
\Friendica\BaseObject::setDependencyInjection($dice); (new Friendica\Core\Console($dice, $argv))->execute();
(new Friendica\Core\Console($argv))->execute();

View file

@ -2,8 +2,9 @@
namespace Friendica\Console; namespace Friendica\Console;
use Friendica\App;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Database\DBA; use Friendica\Database\Database;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use RuntimeException; use RuntimeException;
@ -20,6 +21,19 @@ class ArchiveContact extends \Asika\SimpleConsole\Console
{ {
protected $helpOptions = ['h', 'help', '?']; protected $helpOptions = ['h', 'help', '?'];
/**
* @var App\Mode
*/
private $appMode;
/**
* @var Database
*/
private $dba;
/**
* @var L10n\L10n
*/
private $l10n;
protected function getHelp() protected function getHelp()
{ {
$help = <<<HELP $help = <<<HELP
@ -37,10 +51,17 @@ HELP;
return $help; return $help;
} }
public function __construct(App\Mode $appMode, Database $dba, L10n\L10n $l10n, array $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
$this->dba = $dba;
$this->l10n = $l10n;
}
protected function doExecute() protected function doExecute()
{ {
$a = \Friendica\BaseObject::getApp();
if ($this->getOption('v')) { if ($this->getOption('v')) {
$this->out('Class: ' . __CLASS__); $this->out('Class: ' . __CLASS__);
$this->out('Arguments: ' . var_export($this->args, true)); $this->out('Arguments: ' . var_export($this->args, true));
@ -56,16 +77,16 @@ HELP;
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
} }
if ($a->getMode()->isInstall()) { if ($this->appMode->isInstall()) {
throw new RuntimeException('Friendica isn\'t properly installed yet.'); throw new RuntimeException('Friendica isn\'t properly installed yet.');
} }
$nurl = Strings::normaliseLink($this->getArgument(0)); $nurl = Strings::normaliseLink($this->getArgument(0));
if (!DBA::exists('contact', ['nurl' => $nurl, 'archive' => false])) { if (!$this->dba->exists('contact', ['nurl' => $nurl, 'archive' => false])) {
throw new RuntimeException(L10n::t('Could not find any unarchived contact entry for this URL (%s)', $nurl)); throw new RuntimeException(L10n::t('Could not find any unarchived contact entry for this URL (%s)', $nurl));
} }
if (DBA::update('contact', ['archive' => true], ['nurl' => $nurl])) { if ($this->dba->update('contact', ['archive' => true], ['nurl' => $nurl])) {
$this->out(L10n::t('The contact entries have been archived')); $this->out($this->l10n->t('The contact entries have been archived'));
} else { } else {
throw new RuntimeException('The contact archival failed.'); throw new RuntimeException('The contact archival failed.');
} }

View file

@ -3,10 +3,11 @@
namespace Friendica\Console; namespace Friendica\Console;
use Asika\SimpleConsole\Console; use Asika\SimpleConsole\Console;
use Friendica\BaseObject; use Friendica\App;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\Installer; use Friendica\Core\Installer;
use Friendica\Core\Theme; use Friendica\Core\Theme;
use Friendica\Database\Database;
use Friendica\Util\BasePath; use Friendica\Util\BasePath;
use Friendica\Util\BaseURL; use Friendica\Util\BaseURL;
use Friendica\Util\ConfigFileLoader; use Friendica\Util\ConfigFileLoader;
@ -14,6 +15,25 @@ use RuntimeException;
class AutomaticInstallation extends Console class AutomaticInstallation extends Console
{ {
/**
* @var App\Mode
*/
private $appMode;
/**
* @var Config\Cache\ConfigCache
*/
private $configCache;
/**
* @var Config\Configuration
*/
private $config;
/**
* @var Database
*/
private $dba;
protected function getHelp() protected function getHelp()
{ {
return <<<HELP return <<<HELP
@ -69,17 +89,26 @@ Examples
HELP; HELP;
} }
public function __construct(App\Mode $appMode, Config\Cache\ConfigCache $configCache, Config\Configuration $config, Database $dba, array $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
$this->configCache =$configCache;
$this->config = $config;
$this->dba = $dba;
}
protected function doExecute() protected function doExecute()
{ {
// Initialise the app // Initialise the app
$this->out("Initializing setup...\n"); $this->out("Initializing setup...\n");
$a = BaseObject::getApp();
$installer = new Installer(); $installer = new Installer();
$configCache = $a->getConfigCache(); $configCache = $this->configCache;
$basepath = new BasePath($a->getBasePath()); $basePathConf = $configCache->get('system', 'basepath');
$basepath = new BasePath($basePathConf);
$installer->setUpCache($configCache, $basepath->getPath()); $installer->setUpCache($configCache, $basepath->getPath());
$this->out(" Complete!\n\n"); $this->out(" Complete!\n\n");
@ -103,13 +132,13 @@ HELP;
if ($config_file != 'config' . DIRECTORY_SEPARATOR . 'local.config.php') { if ($config_file != 'config' . DIRECTORY_SEPARATOR . 'local.config.php') {
// Copy config file // Copy config file
$this->out("Copying config file...\n"); $this->out("Copying config file...\n");
if (!copy($a->getBasePath() . DIRECTORY_SEPARATOR . $config_file, $a->getBasePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php')) { if (!copy($basePathConf . DIRECTORY_SEPARATOR . $config_file, $basePathConf . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php')) {
throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '" . $a->getBasePath() . "'" . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "local.config.php' manually.\n"); throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '" . $basePathConf . "'" . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "local.config.php' manually.\n");
} }
} }
//reload the config cache //reload the config cache
$loader = new ConfigFileLoader($a->getBasePath(), $a->getMode()); $loader = new ConfigFileLoader($basePathConf);
$loader->setupCache($configCache); $loader->setupCache($configCache);
} else { } else {
@ -159,7 +188,7 @@ HELP;
$this->out('The Friendica URL has to be set during CLI installation.'); $this->out('The Friendica URL has to be set during CLI installation.');
return 1; return 1;
} else { } else {
$baseUrl = new BaseURL($a->getConfig(), []); $baseUrl = new BaseURL($this->config, []);
$baseUrl->saveByURL($url); $baseUrl->saveByURL($url);
} }
@ -173,7 +202,7 @@ HELP;
$installer->resetChecks(); $installer->resetChecks();
if (!$installer->checkDB($configCache, $a->getProfiler())) { if (!$installer->checkDB($this->dba)) {
$errorMessage = $this->extractErrors($installer->getChecks()); $errorMessage = $this->extractErrors($installer->getChecks());
throw new RuntimeException($errorMessage); throw new RuntimeException($errorMessage);
} }
@ -185,7 +214,7 @@ HELP;
$installer->resetChecks(); $installer->resetChecks();
if (!$installer->installDatabase($a->getBasePath())) { if (!$installer->installDatabase($basePathConf)) {
$errorMessage = $this->extractErrors($installer->getChecks()); $errorMessage = $this->extractErrors($installer->getChecks());
throw new RuntimeException($errorMessage); throw new RuntimeException($errorMessage);
} }
@ -194,8 +223,8 @@ HELP;
// Install theme // Install theme
$this->out("Installing theme\n"); $this->out("Installing theme\n");
if (!empty(Config::get('system', 'theme'))) { if (!empty($this->config->get('system', 'theme'))) {
Theme::install(Config::get('system', 'theme')); Theme::install($this->config->get('system', 'theme'));
$this->out(" Complete\n\n"); $this->out(" Complete\n\n");
} else { } else {
$this->out(" Theme setting is empty. Please check the file 'config/local.config.php'\n\n"); $this->out(" Theme setting is empty. Please check the file 'config/local.config.php'\n\n");

View file

@ -20,6 +20,11 @@ class Cache extends \Asika\SimpleConsole\Console
{ {
protected $helpOptions = ['h', 'help', '?']; protected $helpOptions = ['h', 'help', '?'];
/**
* @var App\Mode
*/
private $appMode;
protected function getHelp() protected function getHelp()
{ {
$help = <<<HELP $help = <<<HELP
@ -54,10 +59,15 @@ HELP;
return $help; return $help;
} }
public function __construct(App\Mode $appMode, array $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
}
protected function doExecute() protected function doExecute()
{ {
$a = \Friendica\BaseObject::getApp();
if ($this->getOption('v')) { if ($this->getOption('v')) {
$this->out('Executable: ' . $this->executable); $this->out('Executable: ' . $this->executable);
$this->out('Class: ' . __CLASS__); $this->out('Class: ' . __CLASS__);
@ -65,7 +75,7 @@ HELP;
$this->out('Options: ' . var_export($this->options, true)); $this->out('Options: ' . var_export($this->options, true));
} }
if ($a->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) { if (!$this->appMode->has(App\Mode::DBCONFIGAVAILABLE)) {
$this->out('Database isn\'t ready or populated yet, database cache won\'t be available'); $this->out('Database isn\'t ready or populated yet, database cache won\'t be available');
} }

View file

@ -4,7 +4,7 @@ namespace Friendica\Console;
use Asika\SimpleConsole\CommandArgsException; use Asika\SimpleConsole\CommandArgsException;
use Friendica\App; use Friendica\App;
use Friendica\Core; use Friendica\Core\Config\Configuration;
use RuntimeException; use RuntimeException;
/** /**
@ -35,6 +35,15 @@ class Config extends \Asika\SimpleConsole\Console
{ {
protected $helpOptions = ['h', 'help', '?']; protected $helpOptions = ['h', 'help', '?'];
/**
* @var App\Mode
*/
private $appMode;
/**
* @var Configuration
*/
private $config;
protected function getHelp() protected function getHelp()
{ {
$help = <<<HELP $help = <<<HELP
@ -69,10 +78,16 @@ HELP;
return $help; return $help;
} }
public function __construct(App\Mode $appMode, Configuration $config, array $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
$this->config = $config;
}
protected function doExecute() protected function doExecute()
{ {
$a = \Friendica\BaseObject::getApp();
if ($this->getOption('v')) { if ($this->getOption('v')) {
$this->out('Executable: ' . $this->executable); $this->out('Executable: ' . $this->executable);
$this->out('Class: ' . __CLASS__); $this->out('Class: ' . __CLASS__);
@ -84,7 +99,7 @@ HELP;
throw new CommandArgsException('Too many arguments'); throw new CommandArgsException('Too many arguments');
} }
if (!$a->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) { if (!$this->appMode->has(App\Mode::DBCONFIGAVAILABLE)) {
$this->out('Database isn\'t ready or populated yet, showing file config only'); $this->out('Database isn\'t ready or populated yet, showing file config only');
} }
@ -93,14 +108,14 @@ HELP;
$key = $this->getArgument(1); $key = $this->getArgument(1);
$value = $this->getArgument(2); $value = $this->getArgument(2);
if (is_array(Core\Config::get($cat, $key))) { if (is_array($this->config->get($cat, $key))) {
throw new RuntimeException("$cat.$key is an array and can't be set using this command."); throw new RuntimeException("$cat.$key is an array and can't be set using this command.");
} }
$result = Core\Config::set($cat, $key, $value); $result = $this->config->set($cat, $key, $value);
if ($result) { if ($result) {
$this->out("{$cat}.{$key} <= " . $this->out("{$cat}.{$key} <= " .
Core\Config::get($cat, $key)); $this->config->get($cat, $key));
} else { } else {
$this->out("Unable to set {$cat}.{$key}"); $this->out("Unable to set {$cat}.{$key}");
} }
@ -109,7 +124,7 @@ HELP;
if (count($this->args) == 2) { if (count($this->args) == 2) {
$cat = $this->getArgument(0); $cat = $this->getArgument(0);
$key = $this->getArgument(1); $key = $this->getArgument(1);
$value = Core\Config::get($this->getArgument(0), $this->getArgument(1)); $value = $this->config->get($this->getArgument(0), $this->getArgument(1));
if (is_array($value)) { if (is_array($value)) {
foreach ($value as $k => $v) { foreach ($value as $k => $v) {
@ -122,11 +137,12 @@ HELP;
if (count($this->args) == 1) { if (count($this->args) == 1) {
$cat = $this->getArgument(0); $cat = $this->getArgument(0);
Core\Config::load($cat); $this->config->load($cat);
$configCache = $this->config->getCache();
if ($a->getConfigCache()->get($cat) !== null) { if ($configCache->get($cat) !== null) {
$this->out("[{$cat}]"); $this->out("[{$cat}]");
$catVal = $a->getConfigCache()->get($cat); $catVal = $configCache->get($cat);
foreach ($catVal as $key => $value) { foreach ($catVal as $key => $value) {
if (is_array($value)) { if (is_array($value)) {
foreach ($value as $k => $v) { foreach ($value as $k => $v) {
@ -142,13 +158,13 @@ HELP;
} }
if (count($this->args) == 0) { if (count($this->args) == 0) {
Core\Config::load(); $this->config->load();
if (Core\Config::get('system', 'config_adapter') == 'jit' && $a->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) { if ($this->config->get('system', 'config_adapter') == 'jit' && $this->appMode->has(App\Mode::DBCONFIGAVAILABLE)) {
$this->out('Warning: The JIT (Just In Time) Config adapter doesn\'t support loading the entire configuration, showing file config only'); $this->out('Warning: The JIT (Just In Time) Config adapter doesn\'t support loading the entire configuration, showing file config only');
} }
$config = $a->getConfigCache()->getAll(); $config = $this->config->getCache()->getAll();
foreach ($config as $cat => $section) { foreach ($config as $cat => $section) {
if (is_array($section)) { if (is_array($section)) {
foreach ($section as $key => $value) { foreach ($section as $key => $value) {

View file

@ -2,9 +2,9 @@
namespace Friendica\Console; namespace Friendica\Console;
use Friendica\Core; use Friendica\Core\Config\Cache\ConfigCache;
use Friendica\Core\Update; use Friendica\Core\Update;
use Friendica\Database\DBA; use Friendica\Database\Database;
use Friendica\Database\DBStructure; use Friendica\Database\DBStructure;
use RuntimeException; use RuntimeException;
@ -17,6 +17,15 @@ class DatabaseStructure extends \Asika\SimpleConsole\Console
{ {
protected $helpOptions = ['h', 'help', '?']; protected $helpOptions = ['h', 'help', '?'];
/**
* @var Database
*/
private $dba;
/**
* @var ConfigCache
*/
private $configCache;
protected function getHelp() protected function getHelp()
{ {
$help = <<<HELP $help = <<<HELP
@ -39,6 +48,14 @@ HELP;
return $help; return $help;
} }
public function __construct(Database $dba, ConfigCache $configCache, $argv = null)
{
parent::__construct($argv);
$this->dba = $dba;
$this->configCache = $configCache;
}
protected function doExecute() protected function doExecute()
{ {
if ($this->getOption('v')) { if ($this->getOption('v')) {
@ -56,26 +73,24 @@ HELP;
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
} }
if (!DBA::connected()) { if (!$this->dba->isConnected()) {
throw new RuntimeException('Unable to connect to database'); throw new RuntimeException('Unable to connect to database');
} }
Core\Config::load(); $basePath = $this->configCache->get('system', 'basepath');
$a = get_app();
switch ($this->getArgument(0)) { switch ($this->getArgument(0)) {
case "dryrun": case "dryrun":
$output = DBStructure::update($a->getBasePath(), true, false); $output = DBStructure::update($basePath, true, false);
break; break;
case "update": case "update":
$force = $this->getOption(['f', 'force'], false); $force = $this->getOption(['f', 'force'], false);
$override = $this->getOption(['o', 'override'], false); $override = $this->getOption(['o', 'override'], false);
$output = Update::run($a->getBasePath(), $force, $override,true, false); $output = Update::run($basePath, $force, $override,true, false);
break; break;
case "dumpsql": case "dumpsql":
ob_start(); ob_start();
DBStructure::printStructure($a->getBasePath()); DBStructure::printStructure($basePath);
$output = ob_get_clean(); $output = ob_get_clean();
break; break;
case "toinnodb": case "toinnodb":

View file

@ -2,6 +2,7 @@
namespace Friendica\Console; namespace Friendica\Console;
use Friendica\App;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Model\Contact; use Friendica\Model\Contact;
@ -20,6 +21,15 @@ class GlobalCommunityBlock extends \Asika\SimpleConsole\Console
{ {
protected $helpOptions = ['h', 'help', '?']; protected $helpOptions = ['h', 'help', '?'];
/**
* @var App\Mode
*/
private $appMode;
/**
* @var L10n\L10n
*/
private $l10n;
protected function getHelp() protected function getHelp()
{ {
$help = <<<HELP $help = <<<HELP
@ -38,10 +48,16 @@ HELP;
return $help; return $help;
} }
public function __construct(App\Mode $appMode, L10n $l10n, $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
$this->l10n = $l10n;
}
protected function doExecute() protected function doExecute()
{ {
$a = \get_app();
if ($this->getOption('v')) { if ($this->getOption('v')) {
$this->out('Class: ' . __CLASS__); $this->out('Class: ' . __CLASS__);
$this->out('Arguments: ' . var_export($this->args, true)); $this->out('Arguments: ' . var_export($this->args, true));
@ -57,18 +73,18 @@ HELP;
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
} }
if ($a->getMode()->isInstall()) { if ($this->appMode->isInstall()) {
throw new \RuntimeException('Database isn\'t ready or populated yet'); throw new \RuntimeException('Database isn\'t ready or populated yet');
} }
$contact_id = Contact::getIdForURL($this->getArgument(0)); $contact_id = Contact::getIdForURL($this->getArgument(0));
if (!$contact_id) { if (!$contact_id) {
throw new \RuntimeException(L10n::t('Could not find any contact entry for this URL (%s)', $this->getArgument(0))); throw new \RuntimeException($this->l10n->t('Could not find any contact entry for this URL (%s)', $this->getArgument(0)));
} }
$block_reason = $this->getArgument(1); $block_reason = $this->getArgument(1);
if(Contact::block($contact_id, $block_reason)) { if(Contact::block($contact_id, $block_reason)) {
$this->out(L10n::t('The contact has been blocked from the node')); $this->out($this->l10n->t('The contact has been blocked from the node'));
} else { } else {
throw new \RuntimeException('The contact block failed.'); throw new \RuntimeException('The contact block failed.');
} }

View file

@ -2,8 +2,8 @@
namespace Friendica\Console; namespace Friendica\Console;
use Friendica\BaseObject; use Friendica\App;
use Friendica\Database\DBA; use Friendica\Database\Database;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use RuntimeException; use RuntimeException;
@ -24,6 +24,15 @@ class GlobalCommunitySilence extends \Asika\SimpleConsole\Console
{ {
protected $helpOptions = ['h', 'help', '?']; protected $helpOptions = ['h', 'help', '?'];
/**
* @var App\Mode
*/
private $appMode;
/**
* @var Database
*/
private $dba;
protected function getHelp() protected function getHelp()
{ {
$help = <<<HELP $help = <<<HELP
@ -44,6 +53,14 @@ HELP;
return $help; return $help;
} }
public function __construct(App\Mode $appMode, Database $dba, array $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
$this->dba =$dba;
}
protected function doExecute() protected function doExecute()
{ {
if ($this->getOption('v')) { if ($this->getOption('v')) {
@ -61,13 +78,13 @@ HELP;
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
} }
if (BaseObject::getApp()->getMode()->isInstall()) { if ($this->appMode->isInstall()) {
throw new RuntimeException('Database isn\'t ready or populated yet'); throw new RuntimeException('Database isn\'t ready or populated yet');
} }
$contact_id = Contact::getIdForURL($this->getArgument(0)); $contact_id = Contact::getIdForURL($this->getArgument(0));
if ($contact_id) { if ($contact_id) {
DBA::update('contact', ['hidden' => true], ['id' => $contact_id]); $this->dba->update('contact', ['hidden' => true], ['id' => $contact_id]);
$this->out('The account has been successfully silenced from the global community page.'); $this->out('The account has been successfully silenced from the global community page.');
} else { } else {
throw new RuntimeException('Could not find any public contact entry for this URL (' . $this->getArgument(0) . ')'); throw new RuntimeException('Could not find any public contact entry for this URL (' . $this->getArgument(0) . ')');

View file

@ -2,7 +2,8 @@
namespace Friendica\Console; namespace Friendica\Console;
use Friendica\Core; use Friendica\App;
use Friendica\Core\Config\Configuration;
/** /**
* @brief Sets maintenance mode for this node * @brief Sets maintenance mode for this node
@ -13,6 +14,15 @@ class Maintenance extends \Asika\SimpleConsole\Console
{ {
protected $helpOptions = ['h', 'help', '?']; protected $helpOptions = ['h', 'help', '?'];
/**
* @var App\Mode
*/
private $appMode;
/**
* @var Configuration
*/
private $config;
protected function getHelp() protected function getHelp()
{ {
$help = <<<HELP $help = <<<HELP
@ -42,10 +52,16 @@ HELP;
return $help; return $help;
} }
public function __construct(App\Mode $appMode, Configuration $config, $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
$this->config = $config;
}
protected function doExecute() protected function doExecute()
{ {
$a = \Friendica\BaseObject::getApp();
if ($this->getOption('v')) { if ($this->getOption('v')) {
$this->out('Class: ' . __CLASS__); $this->out('Class: ' . __CLASS__);
$this->out('Arguments: ' . var_export($this->args, true)); $this->out('Arguments: ' . var_export($this->args, true));
@ -61,20 +77,20 @@ HELP;
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
} }
if ($a->getMode()->isInstall()) { if ($this->appMode->isInstall()) {
throw new \RuntimeException('Database isn\'t ready or populated yet'); throw new \RuntimeException('Database isn\'t ready or populated yet');
} }
$enabled = intval($this->getArgument(0)); $enabled = intval($this->getArgument(0));
Core\Config::set('system', 'maintenance', $enabled); $this->config->set('system', 'maintenance', $enabled);
$reason = $this->getArgument(1); $reason = $this->getArgument(1);
if ($enabled && $this->getArgument(1)) { if ($enabled && $this->getArgument(1)) {
Core\Config::set('system', 'maintenance_reason', $this->getArgument(1)); $this->config->set('system', 'maintenance_reason', $this->getArgument(1));
} else { } else {
Core\Config::set('system', 'maintenance_reason', ''); $this->config->set('system', 'maintenance_reason', '');
} }
if ($enabled) { if ($enabled) {

View file

@ -2,8 +2,9 @@
namespace Friendica\Console; namespace Friendica\Console;
use Friendica\Core\L10n; use Friendica\App;
use Friendica\Database\DBA; use Friendica\Core\L10n\L10n;
use Friendica\Database\Database;
use Friendica\Model\User; use Friendica\Model\User;
use RuntimeException; use RuntimeException;
@ -20,6 +21,19 @@ class NewPassword extends \Asika\SimpleConsole\Console
{ {
protected $helpOptions = ['h', 'help', '?']; protected $helpOptions = ['h', 'help', '?'];
/**
* @var App\Mode
*/
private $appMode;
/**
* @var L10n
*/
private $l10n;
/**
* @var Database
*/
private $dba;
protected function getHelp() protected function getHelp()
{ {
$help = <<<HELP $help = <<<HELP
@ -37,10 +51,17 @@ HELP;
return $help; return $help;
} }
public function __construct(App\Mode $appMode, L10n $l10n, Database $dba, array $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
$this->l10n = $l10n;
$this->dba = $dba;
}
protected function doExecute() protected function doExecute()
{ {
$a = \get_app();
if ($this->getOption('v')) { if ($this->getOption('v')) {
$this->out('Class: ' . __CLASS__); $this->out('Class: ' . __CLASS__);
$this->out('Arguments: ' . var_export($this->args, true)); $this->out('Arguments: ' . var_export($this->args, true));
@ -56,31 +77,31 @@ HELP;
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
} }
if ($a->getMode()->isInstall()) { if ($this->appMode->isInstall()) {
throw new RuntimeException('Database isn\'t ready or populated yet'); throw new RuntimeException('Database isn\'t ready or populated yet');
} }
$nick = $this->getArgument(0); $nick = $this->getArgument(0);
$user = DBA::selectFirst('user', ['uid'], ['nickname' => $nick]); $user = $this->dba->selectFirst('user', ['uid'], ['nickname' => $nick]);
if (!DBA::isResult($user)) { if (!$this->dba->isResult($user)) {
throw new RuntimeException(L10n::t('User not found')); throw new RuntimeException($this->l10n->t('User not found'));
} }
$password = $this->getArgument(1); $password = $this->getArgument(1);
if (is_null($password)) { if (is_null($password)) {
$this->out(L10n::t('Enter new password: '), false); $this->out($this->l10n->t('Enter new password: '), false);
$password = \Seld\CliPrompt\CliPrompt::hiddenPrompt(true); $password = \Seld\CliPrompt\CliPrompt::hiddenPrompt(true);
} }
try { try {
$result = User::updatePassword($user['uid'], $password); $result = User::updatePassword($user['uid'], $password);
if (!DBA::isResult($result)) { if (!$this->dba->isResult($result)) {
throw new \Exception(L10n::t('Password update failed. Please try again.')); throw new \Exception($this->l10n->t('Password update failed. Please try again.'));
} }
$this->out(L10n::t('Password changed.')); $this->out($this->l10n->t('Password changed.'));
} catch (\Exception $e) { } catch (\Exception $e) {
throw new RuntimeException($e->getMessage(), $e->getCode(), $e); throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
} }

View file

@ -2,8 +2,9 @@
namespace Friendica\Console; namespace Friendica\Console;
use Friendica\Core\Config; use Friendica\App;
use Friendica\Core\L10n; use Friendica\Core\Config\Configuration;
use Friendica\Core\L10n\L10n;
use Friendica\Core\Update; use Friendica\Core\Update;
/** /**
@ -18,6 +19,19 @@ class PostUpdate extends \Asika\SimpleConsole\Console
{ {
protected $helpOptions = ['h', 'help', '?']; protected $helpOptions = ['h', 'help', '?'];
/**
* @var App\Mode
*/
private $appMode;
/**
* @var Configuration
*/
private $config;
/**
* @var L10n
*/
private $l10n;
protected function getHelp() protected function getHelp()
{ {
$help = <<<HELP $help = <<<HELP
@ -32,6 +46,15 @@ HELP;
return $help; return $help;
} }
public function __construct(App\Mode $appMode, Configuration $config, L10n $l10n, array $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
$this->config = $config;
$this->l10n = $l10n;
}
protected function doExecute() protected function doExecute()
{ {
$a = \Friendica\BaseObject::getApp(); $a = \Friendica\BaseObject::getApp();
@ -46,26 +69,26 @@ HELP;
$this->out($this->getHelp()); $this->out($this->getHelp());
return 0; return 0;
} elseif ($reset_version) { } elseif ($reset_version) {
Config::set('system', 'post_update_version', $reset_version); $this->config->set('system', 'post_update_version', $reset_version);
echo L10n::t('Post update version number has been set to %s.', $reset_version) . "\n"; echo $this->l10n->t('Post update version number has been set to %s.', $reset_version) . "\n";
return 0; return 0;
} }
if ($a->getMode()->isInstall()) { if ($this->appMode->isInstall()) {
throw new \RuntimeException('Database isn\'t ready or populated yet'); throw new \RuntimeException('Database isn\'t ready or populated yet');
} }
echo L10n::t('Check for pending update actions.') . "\n"; echo $this->l10n->t('Check for pending update actions.') . "\n";
Update::run($a->getBasePath(), true, false, true, false); Update::run($a->getBasePath(), true, false, true, false);
echo L10n::t('Done.') . "\n"; echo $this->l10n->t('Done.') . "\n";
echo L10n::t('Execute pending post updates.') . "\n"; echo $this->l10n->t('Execute pending post updates.') . "\n";
while (!\Friendica\Database\PostUpdate::update()) { while (!\Friendica\Database\PostUpdate::update()) {
echo '.'; echo '.';
} }
echo "\n" . L10n::t('All pending post updates are done.') . "\n"; echo "\n" . $this->l10n->t('All pending post updates are done.') . "\n";
return 0; return 0;
} }

View file

@ -5,7 +5,6 @@ namespace Friendica\Console;
use Asika\SimpleConsole\CommandArgsException; use Asika\SimpleConsole\CommandArgsException;
use Asika\SimpleConsole\Console; use Asika\SimpleConsole\Console;
use Console_Table; use Console_Table;
use Friendica\BaseObject;
use Friendica\Core\Config\Configuration; use Friendica\Core\Config\Configuration;
/** /**
@ -20,6 +19,11 @@ class ServerBlock extends Console
protected $helpOptions = ['h', 'help', '?']; protected $helpOptions = ['h', 'help', '?'];
/**
* @var Configuration
*/
private $config;
protected function getHelp() protected function getHelp()
{ {
$help = <<<HELP $help = <<<HELP
@ -45,20 +49,25 @@ HELP;
return $help; return $help;
} }
public function __construct(Configuration $config, $argv = null)
{
parent::__construct($argv);
$this->config = $config;
}
protected function doExecute() protected function doExecute()
{ {
$a = BaseObject::getApp();
if (count($this->args) == 0) { if (count($this->args) == 0) {
$this->printBlockedServers($a->getConfig()); $this->printBlockedServers($this->config);
return 0; return 0;
} }
switch ($this->getArgument(0)) { switch ($this->getArgument(0)) {
case 'add': case 'add':
return $this->addBlockedServer($a->getConfig()); return $this->addBlockedServer($this->config);
case 'remove': case 'remove':
return $this->removeBlockedServer($a->getConfig()); return $this->removeBlockedServer($this->config);
default: default:
throw new CommandArgsException('Unknown command.'); throw new CommandArgsException('Unknown command.');
break; break;
@ -74,7 +83,7 @@ HELP;
{ {
$table = new Console_Table(); $table = new Console_Table();
$table->setHeaders(['Domain', 'Reason']); $table->setHeaders(['Domain', 'Reason']);
$blocklist = $config->get('system', 'blocklist'); $blocklist = $config->get('system', 'blocklist', []);
foreach ($blocklist as $domain) { foreach ($blocklist as $domain) {
$table->addRow($domain); $table->addRow($domain);
} }
@ -99,7 +108,7 @@ HELP;
$update = false; $update = false;
$currBlocklist = $config->get('system', 'blocklist'); $currBlocklist = $config->get('system', 'blocklist', []);
$newBlockList = []; $newBlockList = [];
foreach ($currBlocklist as $blocked) { foreach ($currBlocklist as $blocked) {
if ($blocked['domain'] === $domain) { if ($blocked['domain'] === $domain) {
@ -150,7 +159,7 @@ HELP;
$found = false; $found = false;
$currBlocklist = $config->get('system', 'blocklist'); $currBlocklist = $config->get('system', 'blocklist', []);
$newBlockList = []; $newBlockList = [];
foreach ($currBlocklist as $blocked) { foreach ($currBlocklist as $blocked) {
if ($blocked['domain'] === $domain) { if ($blocked['domain'] === $domain) {

View file

@ -2,7 +2,7 @@
namespace Friendica\Console; namespace Friendica\Console;
use Friendica\BaseObject; use Friendica\Core\Config\Configuration;
/** /**
* Tired of chasing typos and finding them after a commit. * Tired of chasing typos and finding them after a commit.
@ -14,6 +14,11 @@ class Typo extends \Asika\SimpleConsole\Console
{ {
protected $helpOptions = ['h', 'help', '?']; protected $helpOptions = ['h', 'help', '?'];
/**
* @var Configuration
*/
private $config;
protected function getHelp() protected function getHelp()
{ {
$help = <<<HELP $help = <<<HELP
@ -31,6 +36,13 @@ HELP;
return $help; return $help;
} }
public function __construct(Configuration $config, array $argv = null)
{
parent::__construct($argv);
$this->config = $config;
}
protected function doExecute() protected function doExecute()
{ {
if ($this->getOption('v')) { if ($this->getOption('v')) {
@ -43,7 +55,7 @@ HELP;
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
} }
$php_path = BaseObject::getApp()->getConfig()->get('config', 'php_path', 'php'); $php_path = $this->config->get('config', 'php_path', 'php');
if ($this->getOption('v')) { if ($this->getOption('v')) {
$this->out('Directory: src'); $this->out('Directory: src');

View file

@ -2,6 +2,7 @@
namespace Friendica\Core; namespace Friendica\Core;
use Dice\Dice;
use Friendica; use Friendica;
/** /**
@ -15,6 +16,11 @@ class Console extends \Asika\SimpleConsole\Console
protected $helpOptions = []; protected $helpOptions = [];
protected $customHelpOptions = ['h', 'help', '?']; protected $customHelpOptions = ['h', 'help', '?'];
/**
* @var Dice The DI library
*/
protected $dice;
protected function getHelp() protected function getHelp()
{ {
$help = <<<HELP $help = <<<HELP
@ -69,6 +75,19 @@ HELP;
'storage' => Friendica\Console\Storage::class, 'storage' => Friendica\Console\Storage::class,
]; ];
/**
* CliInput Friendica constructor.
*
* @param Dice $dice The DI library
* @param array $argv
*/
public function __construct(Dice $dice, array $argv = null)
{
parent::__construct($argv);
$this->dice = $dice;
}
protected function doExecute() protected function doExecute()
{ {
if ($this->getOption('v')) { if ($this->getOption('v')) {
@ -125,8 +144,10 @@ HELP;
$className = $this->subConsoles[$command]; $className = $this->subConsoles[$command];
Friendica\BaseObject::setDependencyInjection($this->dice);
/** @var Console $subconsole */ /** @var Console $subconsole */
$subconsole = new $className($subargs); $subconsole = $this->dice->create($className, [$subargs]);
foreach ($this->options as $name => $value) { foreach ($this->options as $name => $value) {
$subconsole->setOption($name, $value); $subconsole->setOption($name, $value);

View file

@ -7,7 +7,7 @@ namespace Friendica\Core;
use DOMDocument; use DOMDocument;
use Exception; use Exception;
use Friendica\Core\Config\Cache\ConfigCache; use Friendica\Core\Config\Cache\ConfigCache;
use Friendica\Database\DBA; use Friendica\Database\Database;
use Friendica\Database\DBStructure; use Friendica\Database\DBStructure;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\Network; use Friendica\Util\Network;
@ -597,11 +597,11 @@ class Installer
* @return bool true if the check was successful, otherwise false * @return bool true if the check was successful, otherwise false
* @throws Exception * @throws Exception
*/ */
public function checkDB(ConfigCache $configCache, Profiler $profiler) public function checkDB(Database $dba)
{ {
DBA::reconnect(); $dba->reconnect();
if (DBA::connected()) { if ($dba->isConnected()) {
if (DBStructure::existsTable('user')) { if (DBStructure::existsTable('user')) {
$this->addCheck(L10n::t('Database already in use.'), false, true, ''); $this->addCheck(L10n::t('Database already in use.'), false, true, '');

View file

@ -64,7 +64,6 @@ return [
], ],
], ],
Config\Configuration::class => [ Config\Configuration::class => [
'shared' => true,
'instanceOf' => Factory\ConfigFactory::class, 'instanceOf' => Factory\ConfigFactory::class,
'call' => [ 'call' => [
['createConfig', [], Dice::CHAIN_CALL], ['createConfig', [], Dice::CHAIN_CALL],

View file

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

View file

@ -2,35 +2,38 @@
namespace Friendica\Test\src\Console; namespace Friendica\Test\src\Console;
use Friendica\App;
use Friendica\App\Mode; use Friendica\App\Mode;
use Friendica\Console\Config; use Friendica\Console\Config;
use Friendica\Core\Config\Configuration;
use Mockery\MockInterface;
/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
* @requires PHP 7.0
*/
class ConfigConsoleTest extends ConsoleTest class ConfigConsoleTest extends ConsoleTest
{ {
/**
* @var App\Mode|MockInterface $appMode
*/
private $appMode;
protected function setUp() protected function setUp()
{ {
parent::setUp(); parent::setUp();
$this->mockApp($this->root);
\Mockery::getConfiguration()->setConstantsMap([ \Mockery::getConfiguration()->setConstantsMap([
Mode::class => [ Mode::class => [
'DBCONFIGAVAILABLE' => 0 'DBCONFIGAVAILABLE' => 0
] ]
]); ]);
$this->mode $this->appMode = \Mockery::mock(App\Mode::class);
->shouldReceive('has') $this->appMode->shouldReceive('has')
->andReturn(true); ->andReturn(true);
$this->configMock = \Mockery::mock(Configuration::class);
} }
function testSetGetKeyValue() { function testSetGetKeyValue()
{
$this->configMock $this->configMock
->shouldReceive('set') ->shouldReceive('set')
->with('config', 'test', 'now') ->with('config', 'test', 'now')
@ -42,7 +45,7 @@ class ConfigConsoleTest extends ConsoleTest
->andReturn('now') ->andReturn('now')
->twice(); ->twice();
$console = new Config($this->consoleArgv); $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
$console->setArgument(0, 'config'); $console->setArgument(0, 'config');
$console->setArgument(1, 'test'); $console->setArgument(1, 'test');
$console->setArgument(2, 'now'); $console->setArgument(2, 'now');
@ -55,7 +58,7 @@ class ConfigConsoleTest extends ConsoleTest
->andReturn('now') ->andReturn('now')
->once(); ->once();
$console = new Config($this->consoleArgv); $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
$console->setArgument(0, 'config'); $console->setArgument(0, 'config');
$console->setArgument(1, 'test'); $console->setArgument(1, 'test');
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
@ -67,7 +70,7 @@ class ConfigConsoleTest extends ConsoleTest
->andReturn(null) ->andReturn(null)
->once(); ->once();
$console = new Config($this->consoleArgv); $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
$console->setArgument(0, 'config'); $console->setArgument(0, 'config');
$console->setArgument(1, 'test'); $console->setArgument(1, 'test');
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
@ -82,7 +85,7 @@ class ConfigConsoleTest extends ConsoleTest
->andReturn($testArray) ->andReturn($testArray)
->once(); ->once();
$console = new Config($this->consoleArgv); $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
$console->setArgument(0, 'config'); $console->setArgument(0, 'config');
$console->setArgument(1, 'test'); $console->setArgument(1, 'test');
$console->setArgument(2, 'now'); $console->setArgument(2, 'now');
@ -92,7 +95,7 @@ class ConfigConsoleTest extends ConsoleTest
} }
function testTooManyArguments() { function testTooManyArguments() {
$console = new Config($this->consoleArgv); $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
$console->setArgument(0, 'config'); $console->setArgument(0, 'config');
$console->setArgument(1, 'test'); $console->setArgument(1, 'test');
$console->setArgument(2, 'it'); $console->setArgument(2, 'it');
@ -109,7 +112,7 @@ class ConfigConsoleTest extends ConsoleTest
->with('test', 'it') ->with('test', 'it')
->andReturn('now') ->andReturn('now')
->once(); ->once();
$console = new Config($this->consoleArgv); $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
$console->setArgument(0, 'test'); $console->setArgument(0, 'test');
$console->setArgument(1, 'it'); $console->setArgument(1, 'it');
$console->setOption('v', 1); $console->setOption('v', 1);
@ -142,7 +145,7 @@ CONF;
->with('test', 'it') ->with('test', 'it')
->andReturn(NULL) ->andReturn(NULL)
->once(); ->once();
$console = new Config(); $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
$console->setArgument(0, 'test'); $console->setArgument(0, 'test');
$console->setArgument(1, 'it'); $console->setArgument(1, 'it');
$console->setArgument(2, 'now'); $console->setArgument(2, 'now');
@ -183,7 +186,7 @@ Options
-v Show more debug information. -v Show more debug information.
HELP; HELP;
$console = new Config($this->consoleArgv); $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
$console->setOption('help', true); $console->setOption('help', true);
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);

View file

@ -4,15 +4,10 @@ namespace Friendica\Test\src\Console;
use Asika\SimpleConsole\Console; use Asika\SimpleConsole\Console;
use Friendica\Test\MockedTest; use Friendica\Test\MockedTest;
use Friendica\Test\Util\AppMockTrait;
use Friendica\Test\Util\Intercept; use Friendica\Test\Util\Intercept;
use Friendica\Test\Util\VFSTrait;
abstract class ConsoleTest extends MockedTest abstract class ConsoleTest extends MockedTest
{ {
use VFSTrait;
use AppMockTrait;
/** /**
* @var array The default argv for a Console Instance * @var array The default argv for a Console Instance
*/ */
@ -23,8 +18,6 @@ abstract class ConsoleTest extends MockedTest
parent::setUp(); parent::setUp();
Intercept::setUp(); Intercept::setUp();
$this->setUpVfsDir();
} }
/** /**

View file

@ -3,11 +3,8 @@
namespace Friendica\Test\src\Console; namespace Friendica\Test\src\Console;
use Friendica\Console\ServerBlock; use Friendica\Console\ServerBlock;
use Friendica\Core\Config\Configuration;
/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class ServerBlockConsoleTest extends ConsoleTest class ServerBlockConsoleTest extends ConsoleTest
{ {
protected $defaultBlockList = [ protected $defaultBlockList = [
@ -25,7 +22,7 @@ class ServerBlockConsoleTest extends ConsoleTest
{ {
parent::setUp(); parent::setUp();
$this->mockApp($this->root); $this->configMock = \Mockery::mock(Configuration::class);
} }
/** /**
@ -35,11 +32,11 @@ class ServerBlockConsoleTest extends ConsoleTest
{ {
$this->configMock $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'blocklist') ->with('system', 'blocklist', [])
->andReturn($this->defaultBlockList) ->andReturn($this->defaultBlockList)
->once(); ->once();
$console = new ServerBlock($this->consoleArgv); $console = new ServerBlock($this->configMock, $this->consoleArgv);
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
$output = <<<CONS $output = <<<CONS
@ -63,7 +60,7 @@ CONS;
{ {
$this->configMock $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'blocklist') ->with('system', 'blocklist', [])
->andReturn($this->defaultBlockList) ->andReturn($this->defaultBlockList)
->once(); ->once();
@ -79,7 +76,7 @@ CONS;
->andReturn(true) ->andReturn(true)
->once(); ->once();
$console = new ServerBlock($this->consoleArgv); $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'add'); $console->setArgument(0, 'add');
$console->setArgument(1, 'testme.now'); $console->setArgument(1, 'testme.now');
$console->setArgument(2, 'I like it!'); $console->setArgument(2, 'I like it!');
@ -95,7 +92,7 @@ CONS;
{ {
$this->configMock $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'blocklist') ->with('system', 'blocklist', [])
->andReturn($this->defaultBlockList) ->andReturn($this->defaultBlockList)
->once(); ->once();
@ -111,7 +108,7 @@ CONS;
->andReturn(true) ->andReturn(true)
->once(); ->once();
$console = new ServerBlock($this->consoleArgv); $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'add'); $console->setArgument(0, 'add');
$console->setArgument(1, 'testme.now'); $console->setArgument(1, 'testme.now');
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
@ -126,7 +123,7 @@ CONS;
{ {
$this->configMock $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'blocklist') ->with('system', 'blocklist', [])
->andReturn($this->defaultBlockList) ->andReturn($this->defaultBlockList)
->once(); ->once();
@ -147,7 +144,7 @@ CONS;
->andReturn(true) ->andReturn(true)
->once(); ->once();
$console = new ServerBlock($this->consoleArgv); $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'add'); $console->setArgument(0, 'add');
$console->setArgument(1, 'pod.ordoevangelistarum.com'); $console->setArgument(1, 'pod.ordoevangelistarum.com');
$console->setArgument(2, 'Other reason'); $console->setArgument(2, 'Other reason');
@ -163,7 +160,7 @@ CONS;
{ {
$this->configMock $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'blocklist') ->with('system', 'blocklist', [])
->andReturn($this->defaultBlockList) ->andReturn($this->defaultBlockList)
->once(); ->once();
@ -180,7 +177,7 @@ CONS;
->andReturn(true) ->andReturn(true)
->once(); ->once();
$console = new ServerBlock($this->consoleArgv); $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'remove'); $console->setArgument(0, 'remove');
$console->setArgument(1, 'pod.ordoevangelistarum.com'); $console->setArgument(1, 'pod.ordoevangelistarum.com');
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
@ -193,7 +190,7 @@ CONS;
*/ */
public function testBlockedServersWrongCommand() public function testBlockedServersWrongCommand()
{ {
$console = new ServerBlock($this->consoleArgv); $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'wrongcommand'); $console->setArgument(0, 'wrongcommand');
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
@ -207,11 +204,11 @@ CONS;
{ {
$this->configMock $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'blocklist') ->with('system', 'blocklist', [])
->andReturn($this->defaultBlockList) ->andReturn($this->defaultBlockList)
->once(); ->once();
$console = new ServerBlock($this->consoleArgv); $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'remove'); $console->setArgument(0, 'remove');
$console->setArgument(1, 'not.exiting'); $console->setArgument(1, 'not.exiting');
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
@ -224,7 +221,7 @@ CONS;
*/ */
public function testAddBlockedServerMissingArgument() public function testAddBlockedServerMissingArgument()
{ {
$console = new ServerBlock($this->consoleArgv); $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'add'); $console->setArgument(0, 'add');
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
@ -238,7 +235,7 @@ CONS;
{ {
$this->configMock $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'blocklist') ->with('system', 'blocklist', [])
->andReturn($this->defaultBlockList) ->andReturn($this->defaultBlockList)
->once(); ->once();
@ -254,7 +251,7 @@ CONS;
->andReturn(false) ->andReturn(false)
->once(); ->once();
$console = new ServerBlock($this->consoleArgv); $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'add'); $console->setArgument(0, 'add');
$console->setArgument(1, 'testme.now'); $console->setArgument(1, 'testme.now');
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
@ -269,7 +266,7 @@ CONS;
{ {
$this->configMock $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('system', 'blocklist') ->with('system', 'blocklist', [])
->andReturn($this->defaultBlockList) ->andReturn($this->defaultBlockList)
->once(); ->once();
@ -286,7 +283,7 @@ CONS;
->andReturn(false) ->andReturn(false)
->once(); ->once();
$console = new ServerBlock($this->consoleArgv); $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'remove'); $console->setArgument(0, 'remove');
$console->setArgument(1, 'pod.ordoevangelistarum.com'); $console->setArgument(1, 'pod.ordoevangelistarum.com');
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
@ -299,7 +296,7 @@ CONS;
*/ */
public function testRemoveBlockedServerMissingArgument() public function testRemoveBlockedServerMissingArgument()
{ {
$console = new ServerBlock($this->consoleArgv); $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'remove'); $console->setArgument(0, 'remove');
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
@ -311,7 +308,7 @@ CONS;
*/ */
public function testBlockedServersHelp() public function testBlockedServersHelp()
{ {
$console = new ServerBlock($this->consoleArgv); $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setOption('help', true); $console->setOption('help', true);
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);