Changing Friendica\App\Mode from static methods to public methods

- Changing from static methods to public methods
- Adding dev-composer-dependency Mockery for static method mocking (f.e. Config, DBA)
- Adding ModeTest with Mocking
- removing bootstrap from phpunit.xml because of double loading tests\bootstrap.php
This commit is contained in:
Philipp Holzer 2018-10-06 16:27:20 +02:00
parent 5014779052
commit 31148e25cf
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
21 changed files with 498 additions and 106 deletions

View file

@ -11,6 +11,7 @@ use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Network\HTTPException\InternalServerErrorException;
require_once 'boot.php';
require_once 'include/dba.php';
@ -83,6 +84,11 @@ class App
public $stylesheets = [];
public $footerScripts = [];
/**
* @var App\Mode The Mode of the Application
*/
private $mode;
/**
* Register a stylesheet file path to be included in the <head> tag of every page.
* Inclusion is done in App->initHead().
@ -193,6 +199,8 @@ class App
$this->callstack['rendering'] = [];
$this->callstack['parser'] = [];
$this->mode = new App\Mode($basepath);
$this->reload();
set_time_limit(0);
@ -300,6 +308,22 @@ class App
$this->register_template_engine('Friendica\Render\FriendicaSmartyEngine');
}
/**
* Returns the Mode of the Application
*
* @return App\Mode The Application Mode
*
* @throws InternalServerErrorException when the mode isn't created
*/
public function getMode()
{
if (empty($this->mode)) {
throw new InternalServerErrorException('Mode of the Application is not defined');
}
return $this->mode;
}
/**
* Reloads the whole app instance
*/
@ -310,13 +334,13 @@ class App
$this->loadDatabase();
App\Mode::determine($this->basepath);
$this->getMode()->determine($this->basepath);
$this->determineUrlPath();
Config::load();
if (App\Mode::has(App\Mode::DBAVAILABLE)) {
if ($this->getMode()->has(App\Mode::DBAVAILABLE)) {
Core\Addon::loadHooks();
$this->loadAddonConfig();
@ -1402,7 +1426,7 @@ class App
*/
public function getCurrentTheme()
{
if (App\Mode::isInstall()) {
if ($this->getMode()->isInstall()) {
return '';
}