Skip to content

Commit

Permalink
Changing Friendica\App\Mode from static methods to public methods
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
nupplaphil committed Oct 6, 2018
1 parent 5014779 commit 31148e2
Show file tree
Hide file tree
Showing 21 changed files with 498 additions and 106 deletions.
4 changes: 2 additions & 2 deletions bin/auth_ejabberd.php
Expand Up @@ -54,7 +54,7 @@

$a = new App(dirname(__DIR__));

if (App\Mode::isNormal()) {
if ($a->getMode()->isNormal()) {
$oAuth = new ExAuth();
$oAuth->readStdin();
}
}
2 changes: 1 addition & 1 deletion bin/daemon.php
Expand Up @@ -34,7 +34,7 @@

$a = new App(dirname(__DIR__));

if (App\Mode::isInstall()) {
if ($a->getMode()->isInstall()) {
die("Friendica isn't properly installed yet.\n");
}

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -75,7 +75,8 @@
"phpunit/dbunit": "^2.0",
"phpdocumentor/reflection-docblock": "^3.0.2",
"phpunit/php-token-stream": "^1.4.2",
"mikey179/vfsStream": "^1.6"
"mikey179/vfsStream": "^1.6",
"mockery/mockery": "^1.2"
},
"scripts": {
"test": "phpunit"
Expand Down
203 changes: 197 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions index.php
Expand Up @@ -36,7 +36,7 @@
require_once "include/dba.php";

// Missing DB connection: ERROR
if (App\Mode::has(App\Mode::LOCALCONFIGPRESENT) && !App\Mode::has(App\Mode::DBAVAILABLE)) {
if ($a->getMode()->has(App\Mode::LOCALCONFIGPRESENT) && !$a->getMode()->has(App\Mode::DBAVAILABLE)) {
System::httpExit(500, ['title' => 'Error 500 - Internal Server Error', 'description' => 'Apologies but the website is unavailable at the moment.']);
}

Expand All @@ -48,7 +48,7 @@
System::httpExit(503, ['title' => 'Error 503 - Service Temporarily Unavailable', 'description' => 'System is currently overloaded. Please try again later.']);
}

if (!App\Mode::isInstall()) {
if (!$a->getMode()->isInstall()) {
if (Config::get('system', 'force_ssl') && ($a->get_scheme() == "http")
&& (intval(Config::get('system', 'ssl_policy')) == SSL_POLICY_FULL)
&& (substr(System::baseUrl(), 0, 8) == "https://")
Expand Down Expand Up @@ -107,7 +107,7 @@
L10n::loadTranslationTable($lang);
}

if (!empty($_GET['zrl']) && App\Mode::isNormal()) {
if (!empty($_GET['zrl']) && $a->getMode()->isNormal()) {
$a->query_string = Profile::stripZrls($a->query_string);
if (!local_user()) {
// Only continue when the given profile link seems valid
Expand All @@ -130,7 +130,7 @@
}
}

if (!empty($_GET['owt']) && App\Mode::isNormal()) {
if (!empty($_GET['owt']) && $a->getMode()->isNormal()) {
$token = $_GET['owt'];
$a->query_string = Profile::stripQueryParam($a->query_string, 'owt');
Profile::openWebAuthInit($token);
Expand Down Expand Up @@ -165,9 +165,9 @@

// in install mode, any url loads install module
// but we need "view" module for stylesheet
if (App\Mode::isInstall() && $a->module != 'view') {
if ($a->getMode()->isInstall() && $a->module != 'view') {
$a->module = 'install';
} elseif (!App\Mode::has(App\Mode::MAINTENANCEDISABLED) && $a->module != 'view') {
} elseif (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED) && $a->module != 'view') {
$a->module = 'maintenance';
} else {
check_url($a);
Expand Down Expand Up @@ -320,7 +320,7 @@

/* initialise content region */

if (App\Mode::isNormal()) {
if ($a->getMode()->isNormal()) {
Addon::callHooks('page_content_top', $a->page['content']);
}

Expand Down
1 change: 0 additions & 1 deletion phpunit.xml
@@ -1,6 +1,5 @@
<?xml version="1.0"?>
<phpunit
bootstrap="tests/bootstrap.php"
verbose="true">
<testsuites>
<testsuite>
Expand Down

0 comments on commit 31148e2

Please sign in to comment.