Merge remote-tracking branch 'upstream/develop' into blocked-server

This commit is contained in:
Michael 2023-01-17 19:25:09 +00:00
commit 259fe7fcf2
30 changed files with 530 additions and 391 deletions

View file

@ -357,8 +357,6 @@ class App
$this->profiler->reset();
if ($this->mode->has(App\Mode::DBAVAILABLE)) {
$this->profiler->update($this->config);
Core\Hook::loadHooks();
$loader = (new Config())->createConfigFileManager($this->getBasePath(), $_SERVER);
Core\Hook::callAll('load_config', $loader);

View file

@ -22,9 +22,8 @@
namespace Friendica\App;
use Detection\MobileDetect;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Database\Database;
use Friendica\Util\BasePath;
/**
* Mode of the current Friendica Node
@ -129,15 +128,13 @@ class Mode
*
* @throws \Exception
*/
public function determine(BasePath $basepath, Database $database, Cache $configCache): Mode
public function determine(string $basePath, Database $database, IManageConfigValues $config): Mode
{
$mode = 0;
$basepathName = $basepath->getPath();
if (!file_exists($basepathName . '/config/local.config.php')
&& !file_exists($basepathName . '/config/local.ini.php')
&& !file_exists($basepathName . '/.htconfig.php')) {
if (!file_exists($basePath . '/config/local.config.php') &&
!file_exists($basePath . '/config/local.ini.php') &&
!file_exists($basePath . '/.htconfig.php')) {
return new Mode($mode);
}
@ -149,7 +146,7 @@ class Mode
$mode |= Mode::DBAVAILABLE;
if (!empty($configCache->get('system', 'maintenance'))) {
if (!empty($config->get('system', 'maintenance'))) {
return new Mode($mode);
}

View file

@ -21,7 +21,7 @@
namespace Friendica\Console;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Update;
use Friendica\Database\Database;
use Friendica\Database\DBStructure;
@ -43,8 +43,8 @@ class DatabaseStructure extends \Asika\SimpleConsole\Console
/** @var Database */
private $dba;
/** @var Cache */
private $configCache;
/** @var IManageConfigValues */
private $config;
/** @var DbaDefinition */
private $dbaDefinition;
@ -83,14 +83,14 @@ HELP;
return $help;
}
public function __construct(Database $dba, DbaDefinition $dbaDefinition, ViewDefinition $viewDefinition, BasePath $basePath, Cache $configCache, $argv = null)
public function __construct(Database $dba, DbaDefinition $dbaDefinition, ViewDefinition $viewDefinition, BasePath $basePath, IManageConfigValues $config, $argv = null)
{
parent::__construct($argv);
$this->dba = $dba;
$this->dbaDefinition = $dbaDefinition;
$this->viewDefinition = $viewDefinition;
$this->configCache = $configCache;
$this->config = $config;
$this->basePath = $basePath->getPath();
}
@ -117,7 +117,7 @@ HELP;
throw new RuntimeException('Unable to connect to database');
}
$basePath = $this->configCache->get('system', 'basepath');
$basePath = $this->config->get('system', 'basepath');
switch ($this->getArgument(0)) {
case "dryrun":

View file

@ -26,67 +26,201 @@ namespace Friendica\Core\Config\Util;
*/
class ConfigFileTransformer
{
/**
* This method takes an array of config values and applies some standard rules for formatting on it
*
* Beware that the applied rules follow some basic formatting principles for node.config.php
* and doesn't support any custom formatting rules.
*
* f.e. associative array and list formatting are very complex with newlines and indentations, thus there are
* three hardcoded types of formatting for them.
*
* a negative example, what's NOT working:
* key => [ value1, [inner_value1, inner_value2], value2]
* Since this isn't necessary for config values, there's no further logic handling such complex-list-in-list scenarios
*
* @param array $data A full config array
*
* @return string The config stream, which can be saved
*/
public static function encode(array $data): string
{
// Add the typical header values
$dataString = '<?php' . PHP_EOL . PHP_EOL;
$dataString .= 'return [' . PHP_EOL;
$dataString .= 'return ';
$categories = array_keys($data);
$dataString .= static::extractArray($data);
foreach ($categories as $category) {
if (is_null($data[$category])) {
$dataString .= "\t'$category' => null," . PHP_EOL;
continue;
}
$dataString .= "\t'$category' => [" . PHP_EOL;
if (is_array($data[$category])) {
$keys = array_keys($data[$category]);
foreach ($keys as $key) {
$dataString .= static::mapConfigValue($key, $data[$category][$key]);
}
}
$dataString .= "\t]," . PHP_EOL;
}
$dataString .= "];" . PHP_EOL;
// the last array line, close it with a semicolon
$dataString .= ";" . PHP_EOL;
return $dataString;
}
protected static function extractArray(array $config, int $level = 0): string
/**
* Extracts an inner config array.
* Either as an associative array or as a list
*
* @param array $config The config array which should get extracted
* @param int $level The current level of recursion (necessary for tab-indentation calculation)
* @param bool $inList If true, the current array resides inside another list. Different rules may be applicable
*
* @return string The config string
*/
protected static function extractArray(array $config, int $level = 0, bool $inList = false): string
{
if (array_values($config) === $config) {
return self::extractList($config, $level, $inList);
} else {
return self::extractAssociativeArray($config, $level, $inList);
}
}
/**
* Extracts a key-value array and save it into a string
* output:
* [
* 'key' => value,
* 'key' => value,
* ...
* ]
*
* @param array $config The associative/key-value array
* @param int $level The current level of recursion (necessary for tab-indentation calculation)
* @param bool $inList If true, the current array resides inside another list. Different rules may be applicable
*
* @return string The config string
*/
protected static function extractAssociativeArray(array $config, int $level = 0, bool $inList = false): string
{
$string = '';
// Because we're in a list, we have to add a line-break first
if ($inList) {
$string .= PHP_EOL . str_repeat("\t", $level);
}
// Add a typical Line break for a taxative list of key-value pairs
$string .= '[' . PHP_EOL;
foreach ($config as $configKey => $configValue) {
$string .= static::mapConfigValue($configKey, $configValue, $level);
$string .= str_repeat("\t", $level + 1) .
"'$configKey' => " .
static::transformConfigValue($configValue, $level) .
',' . PHP_EOL;
}
$string .= str_repeat("\t", $level) . ']';
return $string;
}
protected static function mapConfigValue(string $key, $value, $level = 0): string
/**
* Extracts a list and save it into a string
* output1 - simple:
* [ value, value, value ]
*
* output2 - complex:
* [
* [ value, value, value ],
* value,
* [
* key => value,
* key => value,
* ],
* ]
*
* @param array $config The list
* @param int $level The current level of recursion (necessary for tab-indentation calculation)
* @param bool $inList If true, the current array resides inside another list. Different rules may be applicable
*
* @return string The config string
*/
protected static function extractList(array $config, int $level = 0, bool $inList = false): string
{
$string = str_repeat("\t", $level + 2) . "'$key' => ";
$string = '[';
if (is_null($value)) {
$string .= "null,";
} elseif (is_array($value)) {
$string .= "[" . PHP_EOL;
$string .= static::extractArray($value, ++$level);
$string .= str_repeat("\t", $level + 1) . '],';
} elseif (is_bool($value)) {
$string .= ($value ? 'true' : 'false') . ",";
} elseif (is_numeric($value)) {
$string .= $value . ",";
} else {
$string .= sprintf('\'%s\',', addcslashes($value, '\'\\'));
$countConfigValues = count($config);
// multiline defines, if each entry uses a new line
$multiline = false;
// Search if any value is an array, because then other formatting rules are applicable
foreach ($config as $item) {
if (is_array($item)) {
$multiline = true;
break;
}
}
$string .= PHP_EOL;
for ($i = 0; $i < $countConfigValues; $i++) {
$isArray = is_array($config[$i]);
/**
* In case this is an array in an array, directly extract this array again and continue
* Skip any other logic since this isn't applicable for an array in an array
*/
if ($isArray) {
$string .= PHP_EOL . str_repeat("\t", $level + 1);
$string .= static::extractArray($config[$i], $level + 1, $inList) . ',';
continue;
}
if ($multiline) {
$string .= PHP_EOL . str_repeat("\t", $level + 1);
}
$string .= static::transformConfigValue($config[$i], $level, true);
// add trailing commas or whitespaces for certain config entries
if (($i < ($countConfigValues - 1))) {
$string .= ',';
if (!$multiline) {
$string .= ' ';
}
}
}
// Add a new line for the last bracket as well
if ($multiline) {
$string .= PHP_EOL . str_repeat("\t", $level);
}
$string .= ']';
return $string;
}
/**
* Transforms one config value and returns the corresponding text-representation
*
* @param mixed $value Any value to transform
* @param int $level The current level of recursion (necessary for tab-indentation calculation)
* @param bool $inList If true, the current array resides inside another list. Different rules may be applicable
*
* @return string
*/
protected static function transformConfigValue($value, int $level = 0, bool $inList = false): string
{
switch (gettype($value)) {
case "boolean":
return ($value ? 'true' : 'false');
case "integer":
case "double":
return $value;
case "string":
return sprintf('\'%s\'', addcslashes($value, '\'\\'));
case "array":
return static::extractArray($value, ++$level, $inList);
case "NULL":
return "null";
case "object":
case "resource":
case "resource (closed)":
throw new \InvalidArgumentException(sprintf('%s in configs are not supported yet.', gettype($value)));
case "unknown type":
throw new \InvalidArgumentException(sprintf('%s is an unknown value', $value));
default:
throw new \InvalidArgumentException(sprintf('%s is currently unsupported', $value));
}
}
}

View file

@ -21,7 +21,7 @@
namespace Friendica\Core\PConfig\Factory;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\PConfig\Repository;
use Friendica\Core\PConfig\Type;
@ -30,15 +30,15 @@ use Friendica\Core\PConfig\ValueObject;
class PConfig
{
/**
* @param Cache $configCache The config cache
* @param IManageConfigValues $config The config
* @param ValueObject\Cache $pConfigCache The personal config cache
* @param Repository\PConfig $configRepo The configuration model
*
* @return IManagePersonalConfigValues
*/
public function create(Cache $configCache, ValueObject\Cache $pConfigCache, Repository\PConfig $configRepo): IManagePersonalConfigValues
public function create(IManageConfigValues $config, ValueObject\Cache $pConfigCache, Repository\PConfig $configRepo): IManagePersonalConfigValues
{
if ($configCache->get('system', 'config_adapter') === 'preload') {
if ($config->get('system', 'config_adapter') === 'preload') {
$configuration = new Type\PreloadPConfig($pConfigCache, $configRepo);
} else {
$configuration = new Type\JitPConfig($pConfigCache, $configRepo);

View file

@ -21,7 +21,7 @@
namespace Friendica\Database;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\System;
use Friendica\Database\Definition\DbaDefinition;
use Friendica\Database\Definition\ViewDefinition;
@ -53,9 +53,9 @@ class Database
protected $connected = false;
/**
* @var \Friendica\Core\Config\ValueObject\Cache
* @var IManageConfigValues
*/
protected $configCache;
protected $config;
/**
* @var Profiler
*/
@ -81,10 +81,10 @@ class Database
/** @var ViewDefinition */
protected $viewDefinition;
public function __construct(Cache $configCache, Profiler $profiler, DbaDefinition $dbaDefinition, ViewDefinition $viewDefinition)
public function __construct(IManageConfigValues $config, Profiler $profiler, DbaDefinition $dbaDefinition, ViewDefinition $viewDefinition)
{
// We are storing these values for being able to perform a reconnect
$this->configCache = $configCache;
$this->config = $config;
$this->profiler = $profiler;
$this->dbaDefinition = $dbaDefinition;
$this->viewDefinition = $viewDefinition;
@ -110,32 +110,32 @@ class Database
$this->connected = false;
$port = 0;
$serveraddr = trim($this->configCache->get('database', 'hostname') ?? '');
$serveraddr = trim($this->config->get('database', 'hostname') ?? '');
$serverdata = explode(':', $serveraddr);
$host = trim($serverdata[0]);
if (count($serverdata) > 1) {
$port = trim($serverdata[1]);
}
if (trim($this->configCache->get('database', 'port') ?? 0)) {
$port = trim($this->configCache->get('database', 'port') ?? 0);
if (trim($this->config->get('database', 'port') ?? 0)) {
$port = trim($this->config->get('database', 'port') ?? 0);
}
$user = trim($this->configCache->get('database', 'username'));
$pass = trim($this->configCache->get('database', 'password'));
$database = trim($this->configCache->get('database', 'database'));
$charset = trim($this->configCache->get('database', 'charset'));
$socket = trim($this->configCache->get('database', 'socket'));
$user = trim($this->config->get('database', 'username'));
$pass = trim($this->config->get('database', 'password'));
$database = trim($this->config->get('database', 'database'));
$charset = trim($this->config->get('database', 'charset'));
$socket = trim($this->config->get('database', 'socket'));
if (!$host && !$socket || !$user) {
return false;
}
$persistent = (bool)$this->configCache->get('database', 'persistent');
$persistent = (bool)$this->config->get('database', 'persistent');
$this->pdo_emulate_prepares = (bool)$this->configCache->get('database', 'pdo_emulate_prepares');
$this->pdo_emulate_prepares = (bool)$this->config->get('database', 'pdo_emulate_prepares');
if (!$this->configCache->get('database', 'disable_pdo') && class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
if (!$this->config->get('database', 'disable_pdo') && class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
$this->driver = self::PDO;
if ($socket) {
$connect = 'mysql:unix_socket=' . $socket;
@ -317,7 +317,7 @@ class Database
private function logIndex(string $query)
{
if (!$this->configCache->get('system', 'db_log_index')) {
if (!$this->config->get('system', 'db_log_index')) {
return;
}
@ -336,18 +336,18 @@ class Database
return;
}
$watchlist = explode(',', $this->configCache->get('system', 'db_log_index_watch'));
$denylist = explode(',', $this->configCache->get('system', 'db_log_index_denylist'));
$watchlist = explode(',', $this->config->get('system', 'db_log_index_watch'));
$denylist = explode(',', $this->config->get('system', 'db_log_index_denylist'));
while ($row = $this->fetch($r)) {
if ((intval($this->configCache->get('system', 'db_loglimit_index')) > 0)) {
if ((intval($this->config->get('system', 'db_loglimit_index')) > 0)) {
$log = (in_array($row['key'], $watchlist) &&
($row['rows'] >= intval($this->configCache->get('system', 'db_loglimit_index'))));
($row['rows'] >= intval($this->config->get('system', 'db_loglimit_index'))));
} else {
$log = false;
}
if ((intval($this->configCache->get('system', 'db_loglimit_index_high')) > 0) && ($row['rows'] >= intval($this->configCache->get('system', 'db_loglimit_index_high')))) {
if ((intval($this->config->get('system', 'db_loglimit_index_high')) > 0) && ($row['rows'] >= intval($this->config->get('system', 'db_loglimit_index_high')))) {
$log = true;
}
@ -358,7 +358,7 @@ class Database
if ($log) {
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
@file_put_contents(
$this->configCache->get('system', 'db_log_index'),
$this->config->get('system', 'db_log_index'),
DateTimeFormat::utcNow() . "\t" .
$row['key'] . "\t" . $row['rows'] . "\t" . $row['Extra'] . "\t" .
basename($backtrace[1]["file"]) . "\t" .
@ -533,7 +533,7 @@ class Database
$orig_sql = $sql;
if ($this->configCache->get('system', 'db_callstack') !== null) {
if ($this->config->get('system', 'db_callstack') !== null) {
$sql = "/*" . System::callstack() . " */ " . $sql;
}
@ -738,16 +738,16 @@ class Database
$this->profiler->stopRecording();
if ($this->configCache->get('system', 'db_log')) {
if ($this->config->get('system', 'db_log')) {
$stamp2 = microtime(true);
$duration = (float)($stamp2 - $stamp1);
if (($duration > $this->configCache->get('system', 'db_loglimit'))) {
if (($duration > $this->config->get('system', 'db_loglimit'))) {
$duration = round($duration, 3);
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
@file_put_contents(
$this->configCache->get('system', 'db_log'),
$this->config->get('system', 'db_log'),
DateTimeFormat::utcNow() . "\t" . $duration . "\t" .
basename($backtrace[1]["file"]) . "\t" .
$backtrace[1]["line"] . "\t" . $backtrace[2]["function"] . "\t" .

View file

@ -102,7 +102,7 @@ class Details extends BaseAdmin
if (array_key_exists($addon, $addons_admin)) {
require_once "addon/$addon/$addon.php";
$func = $addon . '_addon_admin';
$func($a, $admin_form);
$func($admin_form);
}
$t = Renderer::getMarkupTemplate('admin/addons/details.tpl');

View file

@ -25,14 +25,12 @@ use Friendica\App;
use Friendica\Core\Addon;
use Friendica\Core\Config\Util\ConfigFileManager;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Core\Update;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\DI;
use Friendica\Core\Config\Factory\Config;
use Friendica\Model\Register;
use Friendica\Module\BaseAdmin;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPException\ServiceUnavailableException;

View file

@ -376,11 +376,11 @@ class Feed
}
if ($published != '') {
$item['created'] = $published;
$item['created'] = trim($published);
}
if ($updated != '') {
$item['edited'] = $updated;
$item['edited'] = trim($updated);
}
if (!$dryRun) {

View file

@ -21,7 +21,6 @@
namespace Friendica\Util;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\System;
use Psr\Container\ContainerExceptionInterface;
@ -66,30 +65,10 @@ class Profiler implements ContainerInterface
return $this->rendertime;
}
/**
* Updates the enabling of the current profiler
*
* Note: The reason there are two different ways of updating the configuration of this class is because it can
* be used even with no available database connection which IManageConfigValues doesn't ensure.
*
* @param IManageConfigValues $config
*/
public function update(IManageConfigValues $config)
public function __construct(IManageConfigValues $config)
{
$this->enabled = (bool)$config->get('system', 'profiler') ?? false;
$this->rendertime = (bool)$config->get('rendertime', 'callstack') ?? false;
}
/**
* Note: The reason we are using a Config Cache object to initialize this class is to ensure it'll work even with no
* available database connection.
*
* @param \Friendica\Core\Config\ValueObject\Cache $configCache The configuration cache
*/
public function __construct(Cache $configCache)
{
$this->enabled = (bool) $configCache->get('system', 'profiler') ?? false;
$this->rendertime = (bool) $configCache->get('rendertime', 'callstack') ?? false;
$this->reset();
}
@ -213,7 +192,6 @@ class Profiler implements ContainerInterface
$this->performance['file'] = 0;
$this->performance['rendering'] = 0;
$this->performance['session'] = 0;
$this->performance['marktime'] = 0;
$this->performance['marktime'] = microtime(true);
$this->performance['classcreate'] = 0;
$this->performance['classinit'] = 0;
@ -241,6 +219,7 @@ class Profiler implements ContainerInterface
/**
* Returns the rendertime string
*
* @param float $limit Minimal limit for displaying the execution duration
*
* @return string the rendertime
@ -355,10 +334,10 @@ class Profiler implements ContainerInterface
*
* @param string $id Identifier of the entry to look for.
*
* @throws NotFoundExceptionInterface No entry was found for **this** identifier.
* @return float Entry.
* @throws ContainerExceptionInterface Error while retrieving the entry.
*
* @return float Entry.
* @throws NotFoundExceptionInterface No entry was found for **this** identifier.
*/
public function get(string $id): float
{

View file

@ -94,7 +94,9 @@ return [
App\Mode::class => [
'call' => [
['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
['determine', [], Dice::CHAIN_CALL],
['determine', [
[Dice::INSTANCE => '$basepath']
], Dice::CHAIN_CALL],
],
],
Config\Capability\IManageConfigValues::class => [

View file

@ -25,9 +25,9 @@ namespace Friendica\Test;
use Dice\Dice;
use Friendica\App\Arguments;
use Friendica\App\Router;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Config\Factory\Config;
use Friendica\Core\Config\Util\ConfigFileManager;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Session\Capability\IHandleSessions;
use Friendica\Core\Session\Type\Memory;
use Friendica\Database\Database;
@ -74,8 +74,8 @@ abstract class FixtureTest extends DatabaseTest
]);
DI::init($this->dice);
$configCache = $this->dice->create(Cache::class);
$configCache->set('database', 'disable_pdo', true);
$config = $this->dice->create(IManageConfigValues::class);
$config->set('database', 'disable_pdo', true);
/** @var Database $dba */
$dba = $this->dice->create(Database::class);

View file

@ -0,0 +1,53 @@
<?php
/**
* @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Test\Util;
use Friendica\Core\Config\Model\Config;
use Friendica\Core\Config\Util\ConfigFileManager;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Database\Database;
use Friendica\Database\Definition\DbaDefinition;
use Friendica\Database\Definition\ViewDefinition;
use Friendica\Test\DatabaseTestTrait;
use Friendica\Test\Util\Database\StaticDatabase;
use Friendica\Util\Profiler;
trait CreateDatabaseTrait
{
use DatabaseTestTrait;
use VFSTrait;
public function getDbInstance(): Database
{
$configFileManager = new ConfigFileManager($this->root->url(), $this->root->url() . '/config/', $this->root->url() . '/static/');
$config = new Config($configFileManager, new Cache([
'database' => [
'disable_pdo' => true
],
]));
$database = new StaticDatabase($config, new Profiler($config), (new DbaDefinition($this->root->url()))->load(), (new ViewDefinition($this->root->url()))->load());
$database->setTestmode(true);
return $database;
}
}

View file

@ -23,9 +23,13 @@ return [
'string2' => 'false',
],
],
'v' => true,
'v3' => 1,
'bool_true' => true,
'bool_false' => false,
'int_1_not_true' => 1,
'int_0_not_false' => 0,
'v4' => 5.6443,
'string_1_not_true' => '1',
'string_0_not_false' => '0',
],
],
'system' => [

View file

@ -0,0 +1,8 @@
<?php
return [
'string_int_values' => [
'string_1_not_true' => '1',
'string_0_not_false' => '0',
],
];

View file

@ -0,0 +1,7 @@
<?php
return [
'object' => [
'objects_not_supported' => new stdClass(),
],
];

View file

@ -0,0 +1,7 @@
<?php
return [
'ressource' => [
'ressources_not_allowed' => new \GuzzleHttp\Psr7\AppendStream(),
],
];

View file

@ -0,0 +1,12 @@
<?php
return [
'small_cat' => [
[
'key' => 'value',
],
[
'key2' => 'value2',
],
],
];

View file

@ -0,0 +1,75 @@
<?php
return [
'type_test' => [
'bool_true' => true,
'bool_false' => false,
'int_1' => 1,
'int_0' => 2,
'int_12345' => 12345,
'float' => 1.234,
'double_E+' => 1.24E+20,
'double_E-' => 7.0E-10,
'null' => null,
'array' => [1, '2', '3', 4.0E-10, 12345, 0, false, 'true', true],
'array_keys' => [
'int_1' => 1,
'string_2' => '2',
'string_3' => '3',
'double' => 4.0E-10,
'int' => 12345,
'int_0' => 0,
'false' => false,
'string_true' => 'true',
'true' => true,
],
'array_extended' => [
[
'key_1' => 'value_1',
'key_2' => 'value_2',
'key_3' => [
'inner_key' => 'inner_value',
],
],
[
'key_2' => false,
'0' => [
'is_that' => true,
'0' => [
'working' => '?',
],
],
'inner_array' => [
[
'key' => 'value',
'key2' => 12,
],
],
'key_3' => true,
],
['value', 'value2'],
[
[
'key' => 123,
],
'test',
'test52',
'test23',
[
'key' => 456,
],
],
],
],
'other_cat' => [
'key' => 'value',
],
'other_cat2' => [
[
'key' => 'value',
],
[
'key2' => 'value2',
],
],
];

View file

@ -25,6 +25,7 @@ use Dice\Dice;
use Friendica\App;
use Friendica\Core\Cache\Capability\ICanCache;
use Friendica\Core\Cache\Capability\ICanCacheInMemory;
use Friendica\Core\Config\Model\Config;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Lock\Capability\ICanLock;
@ -86,33 +87,6 @@ class DependencyCheckTest extends TestCase
self::assertArrayHasKey('system', $configCache->getAll());
}
/**
* Test the construction of a profiler class with DI
*/
public function testProfiler()
{
/** @var Profiler $profiler */
$profiler = $this->dice->create(Profiler::class);
self::assertInstanceOf(Profiler::class, $profiler);
$configCache = new Cache([
'system' => [
'profiler' => true,
],
'rendertime' => [
'callstack' => true,
]
]);
// create new DI-library because of shared instance rule (so the Profiler wouldn't get created twice)
$this->dice = new Dice();
$profiler = $this->dice->create(Profiler::class, [$configCache]);
self::assertInstanceOf(Profiler::class, $profiler);
self::assertTrue($profiler->isRendertime());
}
public function testDatabase()
{
// PDO needs to be disabled for PHP 7.2, see https://jira.mariadb.org/browse/MDEV-24121

View file

@ -24,7 +24,7 @@ namespace Friendica\Test\src\App;
use Detection\MobileDetect;
use Friendica\App\Arguments;
use Friendica\App\Mode;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Database\Database;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\VFSTrait;
@ -47,9 +47,9 @@ class ModeTest extends MockedTest
private $databaseMock;
/**
* @var Cache|MockInterface
* @var IManageConfigValues|MockInterface
*/
private $configCacheMock;
private $configMock;
protected function setUp(): void
{
@ -57,9 +57,8 @@ class ModeTest extends MockedTest
$this->setUpVfsDir();
$this->basePathMock = Mockery::mock(BasePath::class);
$this->databaseMock = Mockery::mock(Database::class);
$this->configCacheMock = Mockery::mock(Cache::class);
$this->configMock = Mockery::mock(IManageConfigValues::class);
}
public function testItEmpty()
@ -71,15 +70,13 @@ class ModeTest extends MockedTest
public function testWithoutConfig()
{
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
self::assertTrue($this->root->hasChild('config/local.config.php'));
$this->delConfigFile('local.config.php');
self::assertFalse($this->root->hasChild('config/local.config.php'));
$mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$mode = (new Mode())->determine($this->root->url(), $this->databaseMock, $this->configMock);
self::assertTrue($mode->isInstall());
self::assertFalse($mode->isNormal());
@ -89,11 +86,9 @@ class ModeTest extends MockedTest
public function testWithoutDatabase()
{
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
$this->databaseMock->shouldReceive('connected')->andReturn(false)->once();
$mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$mode = (new Mode())->determine($this->root->url(), $this->databaseMock, $this->configMock);
self::assertFalse($mode->isNormal());
self::assertTrue($mode->isInstall());
@ -104,13 +99,11 @@ class ModeTest extends MockedTest
public function testWithMaintenanceMode()
{
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
$this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
$this->configCacheMock->shouldReceive('get')->with('system', 'maintenance')
$this->configMock->shouldReceive('get')->with('system', 'maintenance')
->andReturn(true)->once();
$mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$mode = (new Mode())->determine($this->root->url(), $this->databaseMock, $this->configMock);
self::assertFalse($mode->isNormal());
self::assertFalse($mode->isInstall());
@ -120,13 +113,11 @@ class ModeTest extends MockedTest
public function testNormalMode()
{
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
$this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
$this->configCacheMock->shouldReceive('get')->with('system', 'maintenance')
$this->configMock->shouldReceive('get')->with('system', 'maintenance')
->andReturn(false)->once();
$mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$mode = (new Mode())->determine($this->root->url(), $this->databaseMock, $this->configMock);
self::assertTrue($mode->isNormal());
self::assertFalse($mode->isInstall());
@ -139,13 +130,11 @@ class ModeTest extends MockedTest
*/
public function testDisabledMaintenance()
{
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
$this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
$this->configCacheMock->shouldReceive('get')->with('system', 'maintenance')
$this->configMock->shouldReceive('get')->with('system', 'maintenance')
->andReturn(false)->once();
$mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$mode = (new Mode())->determine($this->root->url(), $this->databaseMock, $this->configMock);
self::assertTrue($mode->isNormal());
self::assertFalse($mode->isInstall());
@ -158,11 +147,9 @@ class ModeTest extends MockedTest
*/
public function testImmutable()
{
$this->basePathMock->shouldReceive('getPath')->andReturn(null)->once();
$mode = new Mode();
$modeNew = $mode->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$modeNew = $mode->determine('', $this->databaseMock, $this->configMock);
self::assertNotSame($modeNew, $mode);
}

View file

@ -57,11 +57,12 @@ class DatabaseCacheTest extends CacheTest
$configFactory = new Config();
$configFileManager = (new Config())->createConfigFileManager($this->root->url(), []);
$configCache = $configFactory->createCache($configFileManager);
$config = new \Friendica\Core\Config\Model\Config($configFileManager, $configCache);
$dbaDefinition = (new DbaDefinition($configCache->get('system', 'basepath')))->load();
$viewDefinition = (new ViewDefinition($configCache->get('system', 'basepath')))->load();
$dba = new StaticDatabase($configCache, $profiler, $dbaDefinition, $viewDefinition);
$dba = new StaticDatabase($config, $profiler, $dbaDefinition, $viewDefinition);
$this->cache = new Cache\Type\DatabaseCache('database', $dba);
return $this->cache;

View file

@ -36,8 +36,25 @@ class ConfigFileTransformerTest extends MockedTest
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/B.node.config.php'),
],
'friendica.local' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/C.node.config.php'),
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/C.node.config.php'),
],
'friendica.local.2' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/D.node.config.php'),
],
'object_invalid' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/object.node.config.php'),
'assertException' => true,
],
'ressource_invalid' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/ressource.node.config.php'),
'assertException' => true,
],
'test_types' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/types.node.config.php'),
],
'small_types' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/small_types.node.config.php'),
]
];
}
@ -46,10 +63,14 @@ class ConfigFileTransformerTest extends MockedTest
*
* @dataProvider dataTests
*/
public function testConfigFile(string $configFile)
public function testConfigFile(string $configFile, bool $assertException = false)
{
$dataArray = include $configFile;
if ($assertException) {
self::expectException(\InvalidArgumentException::class);
}
$newConfig = ConfigFileTransformer::encode($dataArray);
self::assertEquals(file_get_contents($configFile), $newConfig);

View file

@ -21,20 +21,14 @@
namespace Friendica\Test\src\Core\KeyValueStorage;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs;
use Friendica\Core\KeyValueStorage\Type\DBKeyValueStorage;
use Friendica\Database\Database;
use Friendica\Database\Definition\DbaDefinition;
use Friendica\Database\Definition\ViewDefinition;
use Friendica\Test\DatabaseTestTrait;
use Friendica\Test\Util\Database\StaticDatabase;
use Friendica\Util\BasePath;
use Friendica\Util\Profiler;
use Friendica\Test\Util\CreateDatabaseTrait;
class DBKeyValueStorageTest extends KeyValueStorageTest
{
use DatabaseTestTrait;
use CreateDatabaseTrait;
/** @var Database */
protected $database;
@ -43,6 +37,7 @@ class DBKeyValueStorageTest extends KeyValueStorageTest
{
parent::setUp();
$this->setUpVfsDir();
$this->setUpDb();
}
@ -55,13 +50,7 @@ class DBKeyValueStorageTest extends KeyValueStorageTest
public function getInstance(): IManageKeyValuePairs
{
$cache = new Cache();
$cache->set('database', 'disable_pdo', true);
$basePath = new BasePath(dirname(__FILE__, 5), $_SERVER);
$this->database = new StaticDatabase($cache, new Profiler($cache), (new DbaDefinition($basePath->getPath()))->load(), (new ViewDefinition($basePath->getPath()))->load());
$this->database->setTestmode(true);
$this->database = $this->getDbInstance();
return new DBKeyValueStorage($this->database);
}

View file

@ -21,27 +21,15 @@
namespace Friendica\Test\src\Core\Lock;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Lock\Type\DatabaseLock;
use Friendica\Database\Database;
use Friendica\Database\Definition\DbaDefinition;
use Friendica\Database\Definition\ViewDefinition;
use Friendica\Test\DatabaseTestTrait;
use Friendica\Test\Util\Database\StaticDatabase;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\BasePath;
use Friendica\Util\Profiler;
use Friendica\Test\Util\CreateDatabaseTrait;
class DatabaseLockDriverTest extends LockTest
{
use VFSTrait;
use DatabaseTestTrait;
use CreateDatabaseTrait;
protected $pid = 123;
/** @var Database */
protected $database;
protected function setUp(): void
{
$this->setUpVfsDir();
@ -53,21 +41,13 @@ class DatabaseLockDriverTest extends LockTest
protected function getInstance()
{
$cache = new Cache();
$cache->set('database', 'disable_pdo', true);
$basePath = new BasePath(dirname(__FILE__, 5), $_SERVER);
$this->database = new StaticDatabase($cache, new Profiler($cache), (new DbaDefinition($basePath->getPath()))->load(), (new ViewDefinition($basePath->getPath()))->load());
$this->database->setTestmode(true);
return new DatabaseLock($this->database, $this->pid);
return new DatabaseLock($this->getDbInstance(), $this->pid);
}
protected function tearDown(): void
{
$this->tearDownDb();
parent::tearDown();
$this->tearDownDb();
}
}

View file

@ -21,20 +21,12 @@
namespace Friendica\Test\src\Core\Storage;
use Friendica\Core\Config\Factory\Config;
use Friendica\Core\Storage\Type\Database;
use Friendica\Database\Definition\DbaDefinition;
use Friendica\Database\Definition\ViewDefinition;
use Friendica\Test\DatabaseTestTrait;
use Friendica\Test\Util\Database\StaticDatabase;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\Profiler;
use Psr\Log\NullLogger;
use Friendica\Test\Util\CreateDatabaseTrait;
class DatabaseStorageTest extends StorageTest
{
use DatabaseTestTrait;
use VFSTrait;
use CreateDatabaseTrait;
protected function setUp(): void
{
@ -47,28 +39,13 @@ class DatabaseStorageTest extends StorageTest
protected function getInstance()
{
$profiler = \Mockery::mock(Profiler::class);
$profiler->shouldReceive('startRecording');
$profiler->shouldReceive('stopRecording');
$profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
// load real config to avoid mocking every config-entry which is related to the Database class
$configFactory = new Config();
$configFileManager = (new Config())->createConfigFileManager($this->root->url());
$configCache = $configFactory->createCache($configFileManager);
$dbaDefinition = (new DbaDefinition($configCache->get('system', 'basepath')))->load();
$viewDefinition = (new ViewDefinition($configCache->get('system', 'basepath')))->load();
$dba = new StaticDatabase($configCache, $profiler, $dbaDefinition, $viewDefinition);
return new Database($dba);
return new Database($this->getDbInstance());
}
protected function tearDown(): void
{
$this->tearDownDb();
parent::tearDown();
$this->tearDownDb();
}
}

View file

@ -41,6 +41,7 @@ use Friendica\DI;
use Friendica\Core\Config\Factory\Config;
use Friendica\Core\Storage\Type;
use Friendica\Test\DatabaseTest;
use Friendica\Test\Util\CreateDatabaseTrait;
use Friendica\Test\Util\Database\StaticDatabase;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\Profiler;
@ -51,10 +52,8 @@ use Friendica\Test\Util\SampleStorageBackend;
class StorageManagerTest extends DatabaseTest
{
use VFSTrait;
use CreateDatabaseTrait;
/** @var Database */
private $dba;
/** @var IManageConfigValues */
private $config;
/** @var LoggerInterface */
@ -62,37 +61,33 @@ class StorageManagerTest extends DatabaseTest
/** @var L10n */
private $l10n;
/** @var Database */
protected $database;
protected function setUp(): void
{
parent::setUp();
$this->setUpVfsDir();
$this->setUpDb();
vfsStream::newDirectory(Type\FilesystemConfig::DEFAULT_BASE_FOLDER, 0777)->at($this->root);
$this->logger = new NullLogger();
$profiler = \Mockery::mock(Profiler::class);
$profiler->shouldReceive('startRecording');
$profiler->shouldReceive('stopRecording');
$profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
// load real config to avoid mocking every config-entry which is related to the Database class
$configFactory = new Config();
$configFileManager = $configFactory->createConfigFileManager($this->root->url());
$configCache = $configFactory->createCache($configFileManager);
$dbaDefinition = (new DbaDefinition($configCache->get('system', 'basepath')))->load();
$viewDefinition = (new ViewDefinition($configCache->get('system', 'basepath')))->load();
$this->dba = new StaticDatabase($configCache, $profiler, $dbaDefinition, $viewDefinition);
$this->config = new \Friendica\Core\Config\Model\Config($configFileManager, $configCache);
$this->config->set('storage', 'name', 'Database');
$this->config->set('storage', 'filesystem_path', $this->root->getChild(Type\FilesystemConfig::DEFAULT_BASE_FOLDER)
->url());
$this->l10n = \Mockery::mock(L10n::class);
$this->database = $this->getDbInstance();
}
protected function tearDown(): void
@ -107,7 +102,7 @@ class StorageManagerTest extends DatabaseTest
*/
public function testInstance()
{
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
self::assertInstanceOf(StorageManager::class, $storageManager);
}
@ -169,7 +164,7 @@ class StorageManagerTest extends DatabaseTest
$this->config->set('storage', 'name', $name);
}
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
if ($interface === ICanWriteToStorage::class) {
$storage = $storageManager->getWritableStorageByName($name);
@ -189,7 +184,7 @@ class StorageManagerTest extends DatabaseTest
*/
public function testIsValidBackend($name, $valid, $interface, $assert, $assertName)
{
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
// true in every of the backends
self::assertEquals(!empty($assertName), $storageManager->isValidBackend($name));
@ -203,7 +198,7 @@ class StorageManagerTest extends DatabaseTest
*/
public function testListBackends()
{
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
self::assertEquals(StorageManager::DEFAULT_BACKENDS, $storageManager->listBackends());
}
@ -219,7 +214,7 @@ class StorageManagerTest extends DatabaseTest
static::markTestSkipped('only works for ICanWriteToStorage');
}
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
$selBackend = $storageManager->getWritableStorageByName($name);
$storageManager->setBackend($selBackend);
@ -239,7 +234,7 @@ class StorageManagerTest extends DatabaseTest
$this->expectException(InvalidClassStorageException::class);
}
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
self::assertInstanceOf($assert, $storageManager->getBackend());
}
@ -260,7 +255,7 @@ class StorageManagerTest extends DatabaseTest
->addRule(IHandleSessions::class, ['instanceOf' => Memory::class, 'shared' => true, 'call' => null]);
DI::init($dice);
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
self::assertTrue($storageManager->register(SampleStorageBackend::class));
@ -288,7 +283,7 @@ class StorageManagerTest extends DatabaseTest
->addRule(IHandleSessions::class, ['instanceOf' => Memory::class, 'shared' => true, 'call' => null]);
DI::init($dice);
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
self::assertTrue($storageManager->register(SampleStorageBackend::class));
@ -325,15 +320,15 @@ class StorageManagerTest extends DatabaseTest
self::markTestSkipped("No user backend");
}
$this->loadFixture(__DIR__ . '/../../../../datasets/storage/database.fixture.php', $this->dba);
$this->loadFixture(__DIR__ . '/../../../../datasets/storage/database.fixture.php', $this->database);
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
$storage = $storageManager->getWritableStorageByName($name);
$storageManager->move($storage);
$photos = $this->dba->select('photo', ['backend-ref', 'backend-class', 'id', 'data']);
$photos = $this->database->select('photo', ['backend-ref', 'backend-class', 'id', 'data']);
while ($photo = $this->dba->fetch($photos)) {
while ($photo = $this->database->fetch($photos)) {
self::assertEmpty($photo['data']);
$storage = $storageManager->getByName($photo['backend-class']);
@ -351,7 +346,7 @@ class StorageManagerTest extends DatabaseTest
$this->expectException(InvalidClassStorageException::class);
$this->expectExceptionMessage('Backend SystemResource is not valid');
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
$storage = $storageManager->getWritableStorageByName(SystemResource::getName());
$storageManager->move($storage);
}

View file

@ -23,9 +23,7 @@ namespace Friendica\Test\src\Util;
use Friendica\App\BaseURL;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Config\Capability\ISetConfigValuesTransactionally;
use Friendica\Core\Config\Model\Config;
use Friendica\Core\Config\Model\ConfigTransaction;
use Friendica\Core\Config\Util\ConfigFileManager;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Test\MockedTest;

View file

@ -21,7 +21,6 @@
namespace Friendica\Test\src\Util;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Test\MockedTest;
use Friendica\Util\Profiler;
@ -47,12 +46,12 @@ class ProfilerTest extends MockedTest
*/
public function testSetUp()
{
$configCache = \Mockery::mock(Cache::class);
$configCache->shouldReceive('get')
$config = \Mockery::mock(IManageConfigValues::class);
$config->shouldReceive('get')
->withAnyArgs()
->andReturn(true)
->twice();
$profiler = new Profiler($configCache);
$profiler = new Profiler($config);
self::assertInstanceOf(Profiler::class, $profiler);
}
@ -124,13 +123,13 @@ class ProfilerTest extends MockedTest
*/
public function testSaveTimestamp($timestamp, $name, array $functions)
{
$configCache = \Mockery::mock(Cache::class);
$configCache->shouldReceive('get')
$config = \Mockery::mock(IManageConfigValues::class);
$config->shouldReceive('get')
->withAnyArgs()
->andReturn(true)
->twice();
$profiler = new Profiler($configCache);
$profiler = new Profiler($config);
foreach ($functions as $function) {
$profiler->saveTimestamp($timestamp, $name, $function);
@ -145,13 +144,13 @@ class ProfilerTest extends MockedTest
*/
public function testReset($timestamp, $name)
{
$configCache = \Mockery::mock(Cache::class);
$configCache->shouldReceive('get')
$config = \Mockery::mock(IManageConfigValues::class);
$config->shouldReceive('get')
->withAnyArgs()
->andReturn(true)
->twice();
$profiler = new Profiler($configCache);
$profiler = new Profiler($config);
$profiler->saveTimestamp($timestamp, $name);
$profiler->reset();
@ -208,13 +207,13 @@ class ProfilerTest extends MockedTest
->shouldReceive('info')
->once();
$configCache = \Mockery::mock(Cache::class);
$configCache->shouldReceive('get')
$config = \Mockery::mock(IManageConfigValues::class);
$config->shouldReceive('get')
->withAnyArgs()
->andReturn(true)
->twice();
$profiler = new Profiler($configCache);
$profiler = new Profiler($config);
foreach ($data as $perf => $items) {
foreach ($items['functions'] as $function) {
@ -233,60 +232,4 @@ class ProfilerTest extends MockedTest
}
}
}
/**
* Test different enable and disable states of the profiler
*/
public function testEnableDisable()
{
$configCache = \Mockery::mock(Cache::class);
$configCache->shouldReceive('get')
->with('system', 'profiler')
->andReturn(true)
->once();
$configCache->shouldReceive('get')
->with('rendertime', 'callstack')
->andReturn(false)
->once();
$profiler = new Profiler($configCache);
self::assertFalse($profiler->isRendertime());
self::assertEmpty($profiler->getRendertimeString());
$profiler->saveTimestamp(time(), 'network', 'test1');
$config = \Mockery::mock(IManageConfigValues::class);
$config->shouldReceive('get')
->with('system', 'profiler')
->andReturn(false)
->once();
$config->shouldReceive('get')
->with('rendertime', 'callstack')
->andReturn(false)
->once();
$profiler->update($config);
self::assertFalse($profiler->isRendertime());
self::assertEmpty($profiler->getRendertimeString());
$config->shouldReceive('get')
->with('system', 'profiler')
->andReturn(true)
->once();
$config->shouldReceive('get')
->with('rendertime', 'callstack')
->andReturn(true)
->once();
$profiler->update($config);
$profiler->saveTimestamp(time(), 'database', 'test2');
self::assertTrue($profiler->isRendertime());
$output = $profiler->getRendertimeString();
self::assertMatchesRegularExpression('/test1: \d+/', $output);
self::assertMatchesRegularExpression('/test2: \d+/', $output);
}
}