Browse Source

Fix a lot of notices/warnings/deprecation notes in the test directory

pull/9436/head
Philipp 1 year ago
parent
commit
d55ecb9288
No known key found for this signature in database GPG Key ID: 9A28B7D4FF5667BD
  1. 1
      src/Database/Database.php
  2. 5
      tests/Util/AppMockTrait.php
  3. 76
      tests/Util/DBAMockTrait.php
  4. 10
      tests/Util/DBStructureMockTrait.php
  5. 2
      tests/Util/Database/ExtendedPDO.php
  6. 11
      tests/Util/Database/StaticDatabase.php
  7. 103
      tests/Util/DbaCacheMockTrait.php
  8. 136
      tests/Util/DbaLockMockTrait.php
  9. 12
      tests/Util/EmailerSpy.php
  10. 2
      tests/Util/HookMockTrait.php
  11. 1
      tests/Util/Intercept.php
  12. 12
      tests/Util/RendererMockTrait.php
  13. 14
      tests/Util/StaticCookie.php
  14. 8
      tests/Util/VFSTrait.php
  15. 2
      tests/functional/DependencyCheckTest.php
  16. 17
      tests/src/App/ModeTest.php
  17. 7
      tests/src/App/ModuleTest.php
  18. 5
      tests/src/App/RouterTest.php
  19. 17
      tests/src/Console/AutomaticInstallationConsoleTest.php
  20. 38
      tests/src/Console/ConfigConsoleTest.php
  21. 2
      tests/src/Console/ConsoleTest.php
  22. 7
      tests/src/Console/LockConsoleTest.php
  23. 7
      tests/src/Console/ServerBlockConsoleTest.php
  24. 2
      tests/src/Content/ItemTest.php
  25. 4
      tests/src/Content/PageInfoMock.php
  26. 7
      tests/src/Content/SmiliesTest.php
  27. 30
      tests/src/Content/Text/BBCodeTest.php
  28. 12
      tests/src/Content/Text/HTMLTest.php
  29. 11
      tests/src/Content/Text/MarkdownTest.php
  30. 4
      tests/src/Core/Cache/APCuCacheTest.php
  31. 2
      tests/src/Core/Cache/ArrayCacheTest.php
  32. 19
      tests/src/Core/Cache/CacheTest.php
  33. 5
      tests/src/Core/Cache/DatabaseCacheTest.php
  34. 12
      tests/src/Core/Cache/MemcacheCacheTest.php
  35. 12
      tests/src/Core/Cache/MemcachedCacheTest.php
  36. 15
      tests/src/Core/Cache/MemoryCacheTest.php
  37. 10
      tests/src/Core/Cache/RedisCacheTest.php
  38. 3
      tests/src/Core/Config/CacheTest.php
  39. 9
      tests/src/Core/Config/ConfigTest.php
  40. 11
      tests/src/Core/Config/JitConfigTest.php
  41. 14
      tests/src/Core/Config/PreloadConfigTest.php
  42. 37
      tests/src/Core/InstallerTest.php
  43. 2
      tests/src/Core/Lock/APCuCacheLockTest.php
  44. 3
      tests/src/Core/Lock/DatabaseLockDriverTest.php
  45. 7
      tests/src/Core/Lock/LockTest.php
  46. 12
      tests/src/Core/Lock/MemcacheCacheLockTest.php
  47. 12
      tests/src/Core/Lock/MemcachedCacheLockTest.php
  48. 8
      tests/src/Core/Lock/RedisCacheLockTest.php
  49. 12
      tests/src/Core/Lock/SemaphoreLockTest.php
  50. 4
      tests/src/Core/PConfig/CacheTest.php
  51. 1
      tests/src/Core/PConfig/JitPConfigTest.php
  52. 5
      tests/src/Core/PConfig/PConfigTest.php
  53. 1
      tests/src/Core/PConfig/PreloadPConfigTest.php
  54. 9
      tests/src/Core/StorageManagerTest.php
  55. 8
      tests/src/Core/SystemTest.php
  56. 2
      tests/src/Database/DBATest.php
  57. 2
      tests/src/Database/DBStructureTest.php
  58. 4
      tests/src/Model/ProcessTest.php
  59. 14
      tests/src/Model/Storage/FilesystemStorageTest.php
  60. 2
      tests/src/Model/User/CookieTest.php
  61. 4
      tests/src/Module/Api/Twitter/ContactEndpointMock.php
  62. 3
      tests/src/Module/Api/Twitter/ContactEndpointTest.php
  63. 1
      tests/src/Util/ACLFormaterTest.php
  64. 5
      tests/src/Util/BasePathTest.php
  65. 8
      tests/src/Util/BaseURLTest.php
  66. 5
      tests/src/Util/Config/ConfigFileLoaderTest.php
  67. 5
      tests/src/Util/CryptoTest.php
  68. 5
      tests/src/Util/EMailerTest.php
  69. 16
      tests/src/Util/Emailer/MailBuilderTest.php
  70. 7
      tests/src/Util/Emailer/SystemMailBuilderTest.php
  71. 45
      tests/src/Util/Logger/StreamLoggerTest.php
  72. 15
      tests/src/Util/Logger/SyslogLoggerTest.php
  73. 1
      tests/src/Util/Logger/SyslogLoggerWrapper.php
  74. 4
      tests/src/Util/Logger/WorkerLoggerTest.php
  75. 4
      tests/src/Util/ProfilerTest.php
  76. 4
      tests/src/Util/StringsTest.php
  77. 32
      tests/src/Util/XmlTest.php

1
src/Database/Database.php

@ -58,6 +58,7 @@ class Database
protected $connection;
protected $driver;
protected $emulate_prepares = false;
protected $pdo_emulate_prepares = false;
private $error = false;
private $errorno = 0;
private $affected_rows = 0;

5
tests/Util/AppMockTrait.php

@ -25,6 +25,7 @@ use Dice\Dice;
use Friendica\App;
use Friendica\Core\Config;
use Friendica\DI;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Render\FriendicaSmartyEngine;
use Friendica\Util\Profiler;
use Mockery\MockInterface;
@ -64,7 +65,9 @@ trait AppMockTrait
* Mock the App
*
* @param vfsStreamDirectory $root The root directory
* @param bool $raw If true, no config mocking will be done
* @param bool $raw If true, no config mocking will be done
*
* @throws InternalServerErrorException
*/
public function mockApp(vfsStreamDirectory $root, $raw = false)
{

76
tests/Util/DBAMockTrait.php

@ -81,11 +81,11 @@ trait DBAMockTrait
/**
* Mocking DBA::fetchFirst()
*
* @param string $arg The argument of fetchFirst
* @param bool $return True, if the DB is connected, otherwise false
* @param null|int $times How often the method will get used
* @param string $arg The argument of fetchFirst
* @param bool $return True, if the DB is connected, otherwise false
* @param null|int $times How often the method will get used
*/
public function mockFetchFirst($arg, $return = true, $times = null)
public function mockFetchFirst(string $arg, bool $return = true, int $times = null)
{
$this->checkMock();
@ -139,13 +139,13 @@ trait DBAMockTrait
/**
* Mocking DBA::select()
*
* @param string $tableName The name of the table
* @param array $select The Select Array (Default is [])
* @param array $where The Where Array (Default is [])
* @param object $return The array to return (Default is [])
* @param null|int $times How often the method will get used
* @param string $tableName The name of the table
* @param array $select The Select Array (Default is [])
* @param array $where The Where Array (Default is [])
* @param object $return The array to return (Default is [])
* @param null|int $times How often the method will get used
*/
public function mockSelect($tableName, $select = [], $where = [], $return = null, $times = null)
public function mockSelect(string $tableName, array $select = [], array $where = [], $return = null, int $times = null)
{
$this->checkMock();
@ -159,12 +159,12 @@ trait DBAMockTrait
/**
* Mocking DBA::delete()
*
* @param string $tableName The name of the table
* @param array $where The Where Array (Default is [])
* @param bool $return The array to return (Default is true)
* @param null|int $times How often the method will get used
* @param string $tableName The name of the table
* @param array $where The Where Array (Default is [])
* @param bool $return The array to return (Default is true)
* @param null|int $times How often the method will get used
*/
public function mockDBADelete($tableName, $where = [], $return = true, $times = null)
public function mockDBADelete(string $tableName, array $where = [], bool $return = true, int $times = null)
{
$this->checkMock();
@ -178,14 +178,14 @@ trait DBAMockTrait
/**
* Mocking DBA::update()
*
* @param string $expTableName The name of the table
* @param array $expFields The Fields Array
* @param array $expCondition The Condition Array
* @param array $expOld_fields The Old Fieldnames (Default is [])
* @param bool $return true if the update was successful
* @param null|int $times How often the method will get used
* @param string $expTableName The name of the table
* @param array $expFields The Fields Array
* @param array $expCondition The Condition Array
* @param array $expOld_fields The Old Fieldnames (Default is [])
* @param bool $return true if the update was successful
* @param null|int $times How often the method will get used
*/
public function mockDBAUpdate($expTableName, $expFields, $expCondition, $expOld_fields = [], $return = true, $times = null)
public function mockDBAUpdate(string $expTableName, array $expFields, array $expCondition, array $expOld_fields = [], bool $return = true, int $times = null)
{
$this->checkMock();
@ -207,13 +207,13 @@ trait DBAMockTrait
/**
* Mocking DBA::insert()
*
* @param string $expTableName The name of the table
* @param array $expParam The Parameters Array
* @param bool $expOnDuplUpdate Update on a duplicated entry
* @param bool $return True if the insert was successful
* @param null|int $times How often the method will get used
* @param string $expTableName The name of the table
* @param array $expParam The Parameters Array
* @param bool $expOnDuplUpdate Update on a duplicated entry
* @param bool $return True if the insert was successful
* @param null|int $times How often the method will get used
*/
public function mockDBAInsert($expTableName, $expParam, $expOnDuplUpdate = false, $return = true, $times = null)
public function mockDBAInsert(string $expTableName, array $expParam, bool $expOnDuplUpdate = false, bool $return = true, int $times = null)
{
$this->checkMock();
@ -234,13 +234,13 @@ trait DBAMockTrait
/**
* Mocking DBA::selectFirst()
*
* @param string $expTableName The name of the table
* @param array $expSelect The Select Array (Default is [])
* @param array $expWhere The Where Array (Default is [])
* @param array $return The array to return (Default is [])
* @param null|int $times How often the method will get used
* @param string $expTableName The name of the table
* @param array $expSelect The Select Array (Default is [])
* @param array $expWhere The Where Array (Default is [])
* @param array $return The array to return (Default is [])
* @param null|int $times How often the method will get used
*/
public function mockSelectFirst($expTableName, $expSelect = [], $expWhere = [], $return = [], $times = null)
public function mockSelectFirst(string $expTableName, array $expSelect = [], array $expWhere = [], array $return = [], int $times = null)
{
$this->checkMock();
@ -321,11 +321,11 @@ trait DBAMockTrait
/**
* Mocking DBA::lock()
*
* @param string $table The table to lock
* @param bool $return True, if the lock is set successful
* @param null|int $times How often the method will get used
* @param string $table The table to lock
* @param bool $return True, if the lock is set successful
* @param null|int $times How often the method will get used
*/
public function mockDbaLock($table, $return = true, $times = null)
public function mockDbaLock(string $table, bool $return = true, int $times = null)
{
$this->checkMock();

10
tests/Util/DBStructureMockTrait.php

@ -42,7 +42,7 @@ trait DBStructureMockTrait
* @param bool $return True, if the connect was successful, otherwise false
* @param null|int $times How often the method will get used
*/
public function mockUpdate($args = [], $return = true, $times = null)
public function mockUpdate(array $args = [], bool $return = true, int $times = null)
{
if (!isset($this->dbStructure)) {
$this->dbStructure = \Mockery::mock('alias:' . DBStructure::class);
@ -58,11 +58,11 @@ trait DBStructureMockTrait
/**
* Mocking DBStructure::existsTable()
*
* @param string $tableName The name of the table to check
* @param bool $return True, if the connect was successful, otherwise false
* @param null|int $times How often the method will get used
* @param string $tableName The name of the table to check
* @param bool $return True, if the connect was successful, otherwise false
* @param null|int $times How often the method will get used
*/
public function mockExistsTable($tableName, $return = true, $times = null)
public function mockExistsTable(string $tableName, bool $return = true, int $times = null)
{
if (!isset($this->dbStructure)) {
$this->dbStructure = \Mockery::mock('alias:' . DBStructure::class);

2
tests/Util/Database/ExtendedPDO.php

@ -33,7 +33,7 @@ class ExtendedPDO extends PDO
/**
* @var array Database drivers that support SAVEPOINT * statements.
*/
protected static $_supportedDrivers = array("pgsql", "mysql");
protected static $_supportedDrivers = ["pgsql", "mysql"];
/**
* @var int the current transaction depth

11
tests/Util/Database/StaticDatabase.php

@ -22,6 +22,7 @@
namespace Friendica\Test\Util\Database;
use Friendica\Database\Database;
use Friendica\Database\DatabaseException;
use PDO;
use PDOException;
@ -80,7 +81,7 @@ class StaticDatabase extends Database
/**
* Does a commit
*
* @return boolean Was the command executed successfully?
* @return bool Was the command executed successfully?
*/
public function commit()
{
@ -96,6 +97,8 @@ class StaticDatabase extends Database
* Either through explicit calling or through implicit using the Database
*
* @param array $server $_SERVER variables
*
* @throws \Exception
*/
public static function statConnect(array $server)
{
@ -119,6 +122,10 @@ class StaticDatabase extends Database
$db_data = $server['MYSQL_DATABASE'];
}
if (empty($db_host) || empty($db_user) || empty($db_data)) {
throw new DatabaseException('Either one of the following settings are missing: Host, User or Database', 999, 'CONNECT');
}
$port = 0;
$serveraddr = trim($db_host);
$serverdata = explode(':', $serveraddr);
@ -128,7 +135,7 @@ class StaticDatabase extends Database
}
$server = trim($server);
$user = trim($db_user);
$pass = trim($db_pw);
$pass = trim($db_pw ?? '');
$db = trim($db_data);
if (!(strlen($server) && strlen($user))) {

103
tests/Util/DbaCacheMockTrait.php

@ -1,103 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2020, Friendica
*
* @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\Cache\Duration;
trait DbaCacheMockTrait
{
/**
* @var
*/
protected $dba;
public function __construct()
{
}
protected function mockDelete($key, $return = true, $times = null)
{
$this->mockDBADelete('cache', ['k' => $key], $return, $times);
}
protected function mockGet($key, $return = null, $time = null, $times = null)
{
if ($time === null) {
$time = time();
}
$value = @serialize($return);
$this->mockSelectFirst('cache', ['v'], ['`k` = ? AND (`expires` >= ? OR `expires` = -1)', $key, $time], ['v' => $value], $times);
$this->mockIsResult(['v' => $value], isset($return), $times);
}
protected function mockSet($key, $value, $ttl = Duration::FIVE_MINUTES, $time = null, $return = true, $times = null)
{
if ($time === null) {
$time = time();
}
if ($ttl > 0) {
$this->mockUtc('now + ' . $ttl . 'seconds', $time + $ttl, $times);
$fields = [
'v' => serialize($value),
'expires' => $time + $ttl,
'updated' => $time
];
} else {
$fields = [
'v' => serialize($value),
'expires' => -1,
'updated' => $time
];
}
$this->mockDBAUpdate('cache', $fields, ['k' => $key], true, $return, $times);
}
protected function mockClear($outdated = true, $return = true, $times = null)
{
if ($outdated) {
$this->mockDBADelete('cache', ['`expires` < NOW()'], $return, $times);
} else {
$this->mockDBADelete('cache', ['`k` IS NOT NULL '], $return, $times);
}
}
protected function mockGetAllKeys($prefix = null, $return = [], $time = null, $times = null)
{
if ($time === null) {
$time = time();
}
if (empty($prefix)) {
$where = ['`expires` >= ?', $time];
} else {
$where = ['`expires` >= ? AND `k` LIKE CONCAT(?, \'%\')', $time, $prefix];
}
$this->mockSelect('cache', ['k'], $where, $return, $times);
$this->mockFetchLoop($return, $times);
$this->mockDbaClose(true, $times);
}
}

136
tests/Util/DbaLockMockTrait.php

@ -1,136 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2020, Friendica
*
* @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\Cache\Duration;
use Friendica\Core\Lock\DatabaseLock;
trait DbaLockMockTrait
{
use DBAMockTrait;
use DateTimeFormatMockTrait;
/**
* Mocking acquireLock with DBA-backend
*
* @param mixed $key The key to lock
* @param int $ttl The TimeToLive
*
* @param bool $locked Was the lock already set?
* @param null $pid The PID which was set
* @param bool $rowExists True, if a row already exists in the lock table
* @param null $time The current timestamp
* @param null|int $times How often the method will get used
*
*@see DatabaseLock::acquire()
*
*/
public function mockAcquireLock($key, $ttl = Duration::FIVE_MINUTES, $locked = false, $pid = null, $rowExists = true, $time = null, $times = null)
{
if ($time === null) {
$time = time();
}
if ($pid === null) {
$pid = getmypid();
}
$this->mockDbaLock('locks', true, $times);
$this->mockUtcNow($time, $times);
$result = ['locked' => $locked, 'pid' => $pid];
$this->mockSelectFirst('locks', ['locked', 'pid'], ['`name` = ? AND `expires` >= ?', $key, $time], $result, $times);
$this->mockIsResult($result, $rowExists, $times);
if ($rowExists) {
if (!$locked ) {
$this->mockUtc('now + ' . $ttl . 'seconds', $time, $times);
$this->mockDBAUpdate('locks', ['locked' => true, 'pid' => $pid, 'expires' => $time], ['name' => $key], [], true, $times);
}
} else {
$this->mockUtc('now + ' . $ttl . 'seconds', $time, $times);
$this->mockDBAInsert('locks', ['name' => $key, 'locked' => true, 'pid' => $pid, 'expires' => $time], false, true, $times);
}
$this->mockDbaUnlock($times);
}
/**
* Mocking isLocked with DBA-backend
*
* @param mixed $key The key of the lock
* @param null|bool $return True, if the key is already locked
* @param null $time The current timestamp
* @param null|int $times How often the method will get used
*
*@see DatabaseLock::isLocked()
*
*/
public function mockIsLocked($key, $return = true, $time = null, $times = null)
{
if ($time === null) {
$time = time();
}
$this->mockUtcNow($time, $times);
$return = ((isset($return)) ? ['locked' => $return] : null);
$this->mockSelectFirst('locks', ['locked'], ['`name` = ? AND `expires` >= ?', $key, $time], $return, $times);
$this->mockIsResult($return, (isset($return) && $return), $times);
}
/**
* Mocking releaseAll with DBA-backend
*
* @param null $pid The PID which was set
* @param null|int $times How often the method will get used
*
*@see DatabaseLock::releaseAll()
*
*/
public function mockReleaseAll($pid = null, $times = null)
{
if ($pid === null) {
$pid = getmypid();
}
$this->mockDBADelete('locks', ['pid' => $pid], true, $times);
}
/**
* Mocking ReleaseLock with DBA-backend
*
* @param mixed $key The key to release
* @param null|int $pid The PID which was set
* @param null|int $times How often the method will get used
*
*@see DatabaseLock::release()
*
*/
public function mockReleaseLock($key, $pid = null, $times = null)
{
if ($pid === null) {
$pid = getmypid();
}
$this->mockDBADelete('locks', ['name' => $key, 'pid' => $pid], true, $times);
}
}

12
tests/Util/EmailerSpy.php

@ -8,6 +8,18 @@ class EmailerSpy extends Emailer
{
public static $MAIL_DATA;
/**
* Wrapper around the mail() method (mainly used to overwrite for tests)
* @see mail()
*
* @param string $to Recipient of this mail
* @param string $subject Subject of this mail
* @param string $body Message body of this mail
* @param string $headers Headers of this mail
* @param string $parameters Additional (sendmail) parameters of this mail
*
* @return bool true if the mail was successfully accepted for delivery, false otherwise.
*/
protected function mail(string $to, string $subject, string $body, string $headers, string $parameters)
{
self::$MAIL_DATA = [

2
tests/Util/HookMockTrait.php

@ -16,6 +16,8 @@ trait HookMockTrait
/**
* Mocking a method 'Hook::call()' call
*
* @param string $name
* @param mixed $capture
*/
public function mockHookCallAll(string $name, &$capture)
{

1
tests/Util/Intercept.php

@ -36,6 +36,7 @@ class Intercept extends php_user_filter
*/
public static $cache = '';
/** @noinspection PhpMissingParentCallCommonInspection */
public function filter($in, $out, &$consumed, $closing)
{
while ($bucket = stream_bucket_make_writeable($in)) {

12
tests/Util/RendererMockTrait.php

@ -38,7 +38,7 @@ trait RendererMockTrait
* @param string $return the return value of the mock (should be defined to have it later for followUp use)
* @param null|int $times How often the method will get used
*/
public function mockGetMarkupTemplate($templateName, $return = '', $times = null)
public function mockGetMarkupTemplate(string $templateName, string $return = '', int $times = null)
{
if (!isset($this->rendererMock)) {
$this->rendererMock = \Mockery::mock('alias:' . Renderer::class);
@ -54,12 +54,12 @@ trait RendererMockTrait
/**
* Mocking the method 'Renderer::replaceMacros()'
*
* @param string $template The template to use (normally, it is the mock result of 'mockGetMarkupTemplate()'
* @param array|\Closure|null $args The arguments to pass to the macro
* @param string $return the return value of the mock
* @param null|int $times How often the method will get used
* @param string $template The template to use (normally, it is the mock result of 'mockGetMarkupTemplate()'
* @param array|\Closure|null $args The arguments to pass to the macro
* @param string $return the return value of the mock
* @param null|int $times How often the method will get used
*/
public function mockReplaceMacros($template, $args = null, $return = '', $times = null)
public function mockReplaceMacros(string $template, $args = null, string $return = '', int $times = null)
{
if (!isset($this->rendererMock)) {
$this->rendererMock = \Mockery::mock('alias:' . Renderer::class);

14
tests/Util/StaticCookie.php

@ -33,6 +33,20 @@ class StaticCookie extends Cookie
/** @var int The last expire time set */
public static $_EXPIRE;
/**
* Send a cookie - protected, internal function for test-mocking possibility
* @see Cookie::setCookie()
*
* @link https://php.net/manual/en/function.setcookie.php
*
* @param string $name
* @param string $value [optional]
* @param int $expire [optional]
* @param bool $secure [optional]
*
* @noinspection PhpMissingParentCallCommonInspection
*
*/
protected function setCookie(string $name, string $value = null, int $expire = null, bool $secure = null)
{
self::$_COOKIE[$name] = $value;

8
tests/Util/VFSTrait.php

@ -58,9 +58,9 @@ trait VFSTrait
* Copying a config file from the file system to the Virtual File System
*
* @param string $filename The filename of the config file
* @param bool $static True, if the folder `static` instead of `config` should be used
* @param bool $static True, if the folder `static` instead of `config` should be used
*/
protected function setConfigFile($filename, bool $static = false)
protected function setConfigFile(string $filename, bool $static = false)
{
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
@ -78,9 +78,9 @@ trait VFSTrait
* Delets a config file from the Virtual File System
*
* @param string $filename The filename of the config file
* @param bool $static True, if the folder `static` instead of `config` should be used
* @param bool $static True, if the folder `static` instead of `config` should be used
*/
protected function delConfigFile($filename, bool $static = false)
protected function delConfigFile(string $filename, bool $static = false)
{
if ($this->root->hasChild(($static ? 'static' : 'config') . '/' . $filename)) {
$this->root->getChild(($static ? 'static' : 'config'))->removeChild($filename);

2
tests/functional/DependencyCheckTest.php

@ -36,7 +36,7 @@ use Friendica\Util\Profiler;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
class dependencyCheck extends TestCase
class DependencyCheckTest extends TestCase
{
use VFSTrait;

17
tests/src/App/ModeTest.php

@ -24,12 +24,13 @@ namespace Friendica\Test\src\App;
use Detection\MobileDetect;
use Friendica\App\Mode;
use Friendica\App\Module;
use Friendica\Core\Config;
use Friendica\Core\Config\Cache;
use Friendica\Database\Database;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\DBAMockTrait;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\BasePath;
use Mockery;
use Mockery\MockInterface;
class ModeTest extends MockedTest
@ -48,19 +49,19 @@ class ModeTest extends MockedTest
private $databaseMock;
/**
* @var \Friendica\Core\Config\Cache|MockInterface
* @var Cache|MockInterface
*/
private $configCacheMock;
public function setUp()
protected function setUp()
{
parent::setUp();
$this->setUpVfsDir();
$this->basePathMock = \Mockery::mock(BasePath::class);
$this->databaseMock = \Mockery::mock(Database::class);
$this->configCacheMock = \Mockery::mock(Config\Cache::class);
$this->basePathMock = Mockery::mock(BasePath::class);
$this->databaseMock = Mockery::mock(Database::class);
$this->configCacheMock = Mockery::mock(Cache::class);
}
public function testItEmpty()
@ -280,7 +281,7 @@ class ModeTest extends MockedTest
{
$server = [];
$module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, [], false);
$mobileDetect = \Mockery::mock(MobileDetect::class);
$mobileDetect = Mockery::mock(MobileDetect::class);
$mobileDetect->shouldReceive('isMobile')->andReturn(true);
$mobileDetect->shouldReceive('isTablet')->andReturn(true);
@ -298,7 +299,7 @@ class ModeTest extends MockedTest
{
$server = [];
$module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, [], false);
$mobileDetect = \Mockery::mock(MobileDetect::class);
$mobileDetect = Mockery::mock(MobileDetect::class);
$mobileDetect->shouldReceive('isMobile')->andReturn(false);
$mobileDetect->shouldReceive('isTablet')->andReturn(false);

7
tests/src/App/ModuleTest.php

@ -29,6 +29,7 @@ use Friendica\LegacyModule;
use Friendica\Module\HTTPException\PageNotFound;
use Friendica\Module\WellKnown\HostMeta;
use Friendica\Test\DatabaseTest;
use Mockery;
class ModuleTest extends DatabaseTest
{
@ -170,13 +171,13 @@ class ModuleTest extends DatabaseTest
*/
public function testModuleClass($assert, string $name, string $command, bool $privAdd)
{
$config = \Mockery::mock(IConfig::class);
$config = Mockery::mock(IConfig::class);
$config->shouldReceive('get')->with('config', 'private_addons', false)->andReturn($privAdd)->atMost()->once();
$l10n = \Mockery::mock(L10n::class);
$l10n = Mockery::mock(L10n::class);
$l10n->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
$cache = \Mockery::mock(ICache::class);
$cache = Mockery::mock(ICache::class);
$cache->shouldReceive('get')->with('routerDispatchData')->andReturn('')->atMost()->once();
$cache->shouldReceive('get')->with('lastRoutesFileModifiedTime')->andReturn('')->atMost()->once();
$cache->shouldReceive('set')->withAnyArgs()->andReturn(false)->atMost()->twice();

5
tests/src/App/RouterTest.php

@ -27,6 +27,7 @@ use Friendica\Core\L10n;
use Friendica\Module;
use Friendica\Network\HTTPException\MethodNotAllowedException;
use Friendica\Network\HTTPException\NotFoundException;
use Mockery;
use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;
@ -43,10 +44,10 @@ class RouterTest extends TestCase
{
parent::setUp();
$this->l10n = \Mockery::mock(L10n::class);
$this->l10n = Mockery::mock(L10n::class);
$this->l10n->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
$this->cache = \Mockery::mock(ICache::class);
$this->cache = Mockery::mock(ICache::class);
$this->cache->shouldReceive('get')->andReturn(null);
$this->cache->shouldReceive('set')->andReturn(false);
}

17
tests/src/Console/AutomaticInstallationConsoleTest.php

@ -35,6 +35,7 @@ use Friendica\Test\Util\DBStructureMockTrait;
use Friendica\Test\Util\RendererMockTrait;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\Logger\VoidLogger;
use Mockery;
use Mockery\MockInterface;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamFile;
@ -77,7 +78,7 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
public function setUp()
{
$this->markTestSkipped('Needs class \'Installer\' as constructing argument for console tests');
static::markTestSkipped('Needs class \'Installer\' as constructing argument for console tests');
parent::setUp();
@ -87,9 +88,9 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
$this->root->getChild('config')
->removeChild('local.config.php');
}
$this->dice = \Mockery::mock(Dice::class)->makePartial();
$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; });
$this->dice->shouldReceive('create')
@ -400,7 +401,7 @@ FIN;
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
$this->mockReplaceMacros('testTemplate', Mockery::any(), '', 1);
$console = new AutomaticInstallation($this->consoleArgv);
$console->setOption('url', 'http://friendica.local');
@ -502,7 +503,7 @@ CONF;
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
$this->mockReplaceMacros('testTemplate', Mockery::any(), '', 1);
self::assertTrue(putenv('MYSQL_HOST=' . $data['database']['hostname']));
self::assertTrue(putenv('MYSQL_PORT=' . $data['database']['port']));
@ -540,7 +541,7 @@ CONF;
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
$this->mockReplaceMacros('testTemplate', Mockery::any(), '', 1);
self::assertTrue(putenv('MYSQL_HOST=' . $data['database']['hostname']));
self::assertTrue(putenv('MYSQL_PORT=' . $data['database']['port']));
@ -576,7 +577,7 @@ CONF;
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
$this->mockReplaceMacros('testTemplate', Mockery::any(), '', 1);
$console = new AutomaticInstallation($this->consoleArgv);
@ -611,7 +612,7 @@ CONF;
$this->mockConnect(false, 1);
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
$this->mockReplaceMacros('testTemplate', Mockery::any(), '', 1);
$console = new AutomaticInstallation($this->consoleArgv);
$console->setOption('url', 'http://friendica.local');

38
tests/src/Console/ConfigConsoleTest.php

@ -25,6 +25,8 @@ use Friendica\App;
use Friendica\App\Mode;
use Friendica\Console\Config;
use Friendica\Core\Config\IConfig;
use Mockery;
use Mockery\LegacyMockInterface;
use Mockery\MockInterface;
class ConfigConsoleTest extends ConsoleTest
@ -33,27 +35,27 @@ class ConfigConsoleTest extends ConsoleTest
* @var App\Mode|MockInterface $appMode
*/
private $appMode;
/** @var IConfig|\Mockery\LegacyMockInterface|MockInterface */
/** @var IConfig|LegacyMockInterface|MockInterface */
private $configMock;
protected function setUp()
{
parent::setUp();
\Mockery::getConfiguration()->setConstantsMap([
Mockery::getConfiguration()->setConstantsMap([
Mode::class => [
'DBCONFIGAVAILABLE' => 0
]
'DBCONFIGAVAILABLE' => 0,
],
]);
$this->appMode = \Mockery::mock(App\Mode::class);
$this->appMode = Mockery::mock(App\Mode::class);
$this->appMode->shouldReceive('has')
->andReturn(true);
->andReturn(true);
$this->configMock = \Mockery::mock(IConfig::class);
$this->configMock = Mockery::mock(IConfig::class);
}
function testSetGetKeyValue()
public function testSetGetKeyValue()
{
$this->configMock
->shouldReceive('set')
@ -98,7 +100,8 @@ class ConfigConsoleTest extends ConsoleTest
self::assertEquals("config.test => \n", $txt);
}
function testSetArrayValue() {
public function testSetArrayValue()
{
$testArray = [1, 2, 3];
$this->configMock
->shouldReceive('get')
@ -115,19 +118,21 @@ class ConfigConsoleTest extends ConsoleTest
self::assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt);
}
function testTooManyArguments() {
public function testTooManyArguments()
{
$console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
$console->setArgument(0, 'config');
$console->setArgument(1, 'test');
$console->setArgument(2, 'it');
$console->setArgument(3, 'now');
$txt = $this->dumpExecute($console);
$txt = $this->dumpExecute($console);
$assertion = '[Warning] Too many arguments';
$firstline = substr($txt, 0, strlen($assertion));
self::assertEquals($assertion, $firstline);
}
function testVerbose() {
public function testVerbose()
{
$this->configMock
->shouldReceive('get')
->with('test', 'it')
@ -138,7 +143,7 @@ class ConfigConsoleTest extends ConsoleTest
$console->setArgument(1, 'it');
$console->setOption('v', 1);
$executable = $this->consoleArgv[0];
$assertion = <<<CONF
$assertion = <<<CONF
Executable: {$executable}
Class: Friendica\Console\Config
Arguments: array (
@ -151,11 +156,12 @@ Options: array (
test.it => now
CONF;
$txt = $this->dumpExecute($console);
$txt = $this->dumpExecute($console);
self::assertEquals($assertion, $txt);
}
function testUnableToSet() {
public function testUnableToSet()
{
$this->configMock
->shouldReceive('set')
->with('test', 'it', 'now')
@ -164,7 +170,7 @@ CONF;
$this->configMock
->shouldReceive('get')
->with('test', 'it')
->andReturn(NULL)
->andReturn(null)
->once();
$console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
$console->setArgument(0, 'test');

2
tests/src/Console/ConsoleTest.php

@ -46,7 +46,7 @@ abstract class ConsoleTest extends MockedTest
*
* @return string the output of the execution
*/
protected function dumpExecute($console)
protected function dumpExecute(Console $console)
{
Intercept::reset();
$console->execute();

7
tests/src/Console/LockConsoleTest.php

@ -25,6 +25,7 @@ use Friendica\App;
use Friendica\App\Mode;
use Friendica\Console\Lock;
use Friendica\Core\Lock\ILock;
use Mockery;
use Mockery\MockInterface;
class LockConsoleTest extends ConsoleTest
@ -43,17 +44,17 @@ class LockConsoleTest extends ConsoleTest
{
parent::setUp();
\Mockery::getConfiguration()->setConstantsMap([
Mockery::getConfiguration()->setConstantsMap([
Mode::class => [
'DBCONFIGAVAILABLE' => 0
]
]);
$this->appMode = \Mockery::mock(App\Mode::class);
$this->appMode = Mockery::mock(App\Mode::class);
$this->appMode->shouldReceive('has')
->andReturn(true);
$this->lockMock = \Mockery::mock(ILock::class);
$this->lockMock = Mockery::mock(ILock::class);
}
public function testList()

7
tests/src/Console/ServerBlockConsoleTest.php

@ -23,6 +23,7 @@ namespace Friendica\Test\src\Console;
use Friendica\Console\ServerBlock;
use Friendica\Core\Config\IConfig;
use Mockery;
class ServerBlockConsoleTest extends ConsoleTest
{
@ -36,12 +37,16 @@ class ServerBlockConsoleTest extends ConsoleTest
'reason' => 'Illegal content',
]
];
/**
* @var IConfig|Mockery\LegacyMockInterface|Mockery\MockInterface
*/
private $configMock;
protected function setUp()
{
parent::setUp();
$this->configMock = \Mockery::mock(IConfig::class);
$this->configMock = Mockery::mock(IConfig::class);
}
/**

2
tests/src/Content/ItemTest.php

@ -27,6 +27,6 @@ class ItemTest extends MockedTest
{
public function testDetermineCategoriesTerms()
{
$this->markTestIncomplete('Test data needed.');
static::markTestIncomplete('Test data needed.');
}
}

4
tests/src/Content/PageInfoMock.php

@ -21,6 +21,8 @@
namespace Friendica\Test\src\Content;
use Friendica\Content\PageInfo;
/**
* Class PageInfoMock
*
@ -29,7 +31,7 @@ namespace Friendica\Test\src\Content;
* @method static string|null getRelevantUrlFromBody(string $body, $searchNakedUrls = false)
* @method static string stripTrailingUrlFromBody(string $body, string $url)
*/
class PageInfoMock extends \Friendica\Content\PageInfo
class PageInfoMock extends PageInfo
{
public static function __callStatic($name, $arguments)
{

7
tests/src/Content/SmiliesTest.php

@ -9,6 +9,7 @@
namespace Friendica\Test\src\Content;
use Friendica\Content\Smilies;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\AppMockTrait;
use Friendica\Test\Util\VFSTrait;
@ -52,14 +53,16 @@ class SmiliesTest extends MockedTest
/**
* Test replace smilies in different texts
*
* @dataProvider dataLinks
*
* @param string $text Test string
* @param array $smilies List of smilies to replace
* @param string $expected Expected result
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*
* @throws InternalServerErrorException
*/
public function testReplaceFromArray($text, $smilies, $expected)
public function testReplaceFromArray(string $text, array $smilies, string $expected)
{
$output = Smilies::replaceFromArray($text, $smilies);
self::assertEquals($expected, $output);

30
tests/src/Content/Text/BBCodeTest.php

@ -24,9 +24,11 @@ namespace Friendica\Test\src\Content\Text;
use Friendica\App\BaseURL;
use Friendica\Content\Text\BBCode;
use Friendica\Core\L10n;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\AppMockTrait;
use Friendica\Test\Util\VFSTrait;
use Mockery;
class BBCodeTest extends MockedTest
{
@ -62,13 +64,13 @@ class BBCodeTest extends MockedTest
->with('system', 'big_emojis')
->andReturn(false);
$l10nMock = \Mockery::mock(L10n::class);
$l10nMock = Mockery::mock(L10n::class);
$l10nMock->shouldReceive('t')->withAnyArgs()->andReturnUsing(function ($args) { return $args; });
$this->dice->shouldReceive('create')
->with(L10n::class)
->andReturn($l10nMock);
$baseUrlMock = \Mockery::mock(BaseURL::class);
$baseUrlMock = Mockery::mock(BaseURL::class);
$baseUrlMock->shouldReceive('get')->withAnyArgs()->andReturn('friendica.local');
$this->dice->shouldReceive('create')
->with(BaseURL::class)
@ -158,13 +160,15 @@ class BBCodeTest extends MockedTest
/**
* Test convert different links inside a text
*
* @dataProvider dataLinks
*
* @param string $data The data to text
* @param bool $assertHTML True, if the link is a HTML link (<a href...>...</a>)
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @param string $data The data to text
* @param bool $assertHTML True, if the link is a HTML link (<a href...>...</a>)
*
* @throws InternalServerErrorException
*/
public function testAutoLinking($data, $assertHTML)
public function testAutoLinking(string $data, bool $assertHTML)
{
$output = BBCode::convert($data);
$assert = '<a href="' . $data . '" target="_blank" rel="noopener noreferrer">' . $data . '</a>';
@ -258,9 +262,10 @@ class BBCodeTest extends MockedTest
* @param bool $try_oembed Whether to convert multimedia BBCode tag
* @param int $simpleHtml BBCode::convert method $simple_html parameter value, optional.
* @param bool $forPlaintext BBCode::convert method $for_plaintext parameter value, optional.
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*
* @throws InternalServerErrorException
*/
public function testConvert($expectedHtml, $text, $try_oembed = false, $simpleHtml = 0, $forPlaintext = false)
public function testConvert(string $expectedHtml, string $text, $try_oembed = false, int $simpleHtml = 0, bool $forPlaintext = false)
{
$actual = BBCode::convert($text, $try_oembed, $simpleHtml, $forPlaintext);
@ -290,12 +295,13 @@ class BBCodeTest extends MockedTest
*
* @dataProvider dataBBCodesToMarkdown
*
* @param string $expected Expected Markdown output
* @param string $text BBCode text
* @param string $expected Expected Markdown output
* @param string $text BBCode text
* @param bool $for_diaspora
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*
* @throws InternalServerErrorException
*/
public function testToMarkdown($expected, $text, $for_diaspora = false)
public function testToMarkdown(string $expected, string $text, $for_diaspora = false)
{
$actual = BBCode::toMarkdown($text, $for_diaspora);

12
tests/src/Content/Text/HTMLTest.php

@ -21,7 +21,9 @@
namespace Friendica\Test\src\Content\Text;
use Exception;
use Friendica\Content\Text\HTML;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\AppMockTrait;
use Friendica\Test\Util\VFSTrait;
@ -61,9 +63,10 @@ class HTMLTest extends MockedTest
*
* @param string $input The Markdown text to test
* @param string $expected The expected HTML output
* @throws \Exception
*
* @throws Exception
*/
public function testToPlaintext($input, $expected)
public function testToPlaintext(string $input, string $expected)
{
$output = HTML::toPlaintext($input, 0);
@ -91,9 +94,10 @@ class HTMLTest extends MockedTest
*
* @param string $expectedBBCode Expected BBCode output
* @param string $html HTML text
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*
* @throws InternalServerErrorException
*/
public function testToBBCode($expectedBBCode, $html)
public function testToBBCode(string $expectedBBCode, string $html)
{
$actual = HTML::toBBCode($html);

11
tests/src/Content/Text/MarkdownTest.php

@ -21,7 +21,7 @@
namespace Friendica\Test\src\Content\Text;
use Friendica\Content\Text\HTML;
use Exception;
use Friendica\Content\Text\Markdown;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\AppMockTrait;
@ -57,13 +57,15 @@ class MarkdownTest extends MockedTest
/**
* Test convert different input Markdown text into HTML
*
* @dataProvider dataMarkdown
*
* @param string $input The Markdown text to test
* @param string $expected The expected HTML output
* @throws \Exception
*
* @throws Exception
*/
public function testConvert($input, $expected)
public function testConvert(string $input, string $expected)
{
$output = Markdown::convert($input);
@ -87,9 +89,8 @@ class MarkdownTest extends MockedTest
*
* @param string $expectedBBCode Expected BBCode output
* @param string $html Markdown text
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function testToBBCode($expectedBBCode, $html)
public function testToBBCode(string $expectedBBCode, string $html)
{
$actual = Markdown::toBBCode($html);

4
tests/src/Core/Cache/APCuCacheTest.php

@ -31,7 +31,7 @@ class APCuCacheTest extends MemoryCacheTest
protected function setUp()
{
if (!APCuCache::isAvailable()) {
$this->markTestSkipped('APCu is not available');
static::markTestSkipped('APCu is not available');
}
parent::setUp();
@ -43,7 +43,7 @@ class APCuCacheTest extends MemoryCacheTest
return $this->cache;
}
public function tearDown()
protected function tearDown()
{
$this->cache->clear(false);
parent::tearDown();

2
tests/src/Core/Cache/ArrayCacheTest.php

@ -31,7 +31,7 @@ class ArrayCacheTest extends MemoryCacheTest
return $this->cache;
}
public function tearDown()
protected function tearDown()
{
$this->cache->clear(false);
parent::tearDown();

19
tests/src/Core/Cache/CacheTest.php

@ -21,6 +21,8 @@
namespace Friendica\Test\src\Core\Cache;
use Friendica\Core\Cache\ICache;
use Friendica\Core\Cache\IMemoryCache;
use Friendica\Test\MockedTest;
use Friendica\Util\PidFile;
@ -32,12 +34,12 @@ abstract class CacheTest extends MockedTest
protected $startTime = 1417011228;
/**
* @var \Friendica\Core\Cache\ICache
* @var ICache
*/
protected $instance;
/**
* @var \Friendica\Core\Cache\IMemoryCache
* @var IMemoryCache
*/
protected $cache;
@ -95,7 +97,7 @@ abstract class CacheTest extends MockedTest
* @param mixed $value1 a first
* @param mixed $value2 a second
*/
function testSimple($value1, $value2)
public function testSimple($value1, $value2)
{
self::assertNull($this->instance->get('value1'));
@ -127,9 +129,8 @@ abstract class CacheTest extends MockedTest
* @param mixed $value3 a third
* @param mixed $value4 a fourth
*/
function testClear($value1, $value2, $value3, $value4)
public function testClear($value1, $value2, $value3, $value4)
{
$value = 'ipsum lorum';
$this->instance->set('1_value1', $value1);
$this->instance->set('1_value2', $value2);
$this->instance->set('2_value1', $value3);
@ -179,9 +180,9 @@ abstract class CacheTest extends MockedTest
/**
* @medium
*/
function testTTL()
public function testTTL()
{
$this->markTestSkipped('taking too much time without mocking');
static::markTestSkipped('taking too much time without mocking');
self::assertNull($this->instance->get('value1'));
@ -198,11 +199,11 @@ abstract class CacheTest extends MockedTest
/**
* @small
*
* @param $data mixed the data to store in the cache
* @param mixed $data the data to store in the cache
*
* @dataProvider dataTypesInCache
*/
function testDifferentTypesInCache($data)
public function testDifferentTypesInCache($data)
{
$this->instance->set('val', $data);
$received = $this->instance->get('val');

5
tests/src/Core/Cache/DatabaseCacheTest.php

@ -28,6 +28,7 @@ use Friendica\Test\Util\Database\StaticDatabase;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\ConfigFileLoader;
use Friendica\Util\Profiler;
use Mockery;
use Psr\Log\NullLogger;
class DatabaseCacheTest extends CacheTest
@ -45,7 +46,7 @@ class DatabaseCacheTest extends CacheTest
protected function getInstance()
{
$logger = new NullLogger();
$profiler = \Mockery::mock(Profiler::class);
$profiler = Mockery::mock(Profiler::class);
$profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
// load real config to avoid mocking every config-entry which is related to the Database class
@ -59,7 +60,7 @@ class DatabaseCacheTest extends CacheTest
return $this->cache;
}
public function tearDown()
protected function tearDown()
{
$this->cache->clear(false);
parent::tearDown();

12
tests/src/Core/Cache/MemcacheCacheTest.php

@ -21,8 +21,10 @@
namespace Friendica\Test\src\Core\Cache;
use Exception;
use Friendica\Core\Cache\MemcacheCache;
use Friendica\Core\Config\IConfig;
use Mockery;
/**
* @requires extension memcache
@ -32,7 +34,7 @@ class MemcacheCacheTest extends MemoryCacheTest
{
protected function getInstance()
{
$configMock = \Mockery::mock(IConfig::class);
$configMock = Mockery::mock(IConfig::class);
$host = $_SERVER['MEMCACHE_HOST'] ?? 'localhost';
$port = $_SERVER['MEMCACHE_PORT'] ?? '11211';
@ -48,13 +50,13 @@ class MemcacheCacheTest extends MemoryCacheTest
try {
$this->cache = new MemcacheCache($host, $configMock);
} catch (\Exception $e) {
$this->markTestSkipped('Memcache is not available');
} catch (Exception $e) {
static::markTestSkipped('Memcache is not available');
}
return $this->cache;
}
public function tearDown()
protected function tearDown()
{
$this->cache->clear(false);
parent::tearDown();
@ -67,6 +69,6 @@ class MemcacheCacheTest extends MemoryCacheTest
*/
public function testGetAllKeys($value1, $value2, $value3)
{
$this->markTestIncomplete('Race condition because of too fast getAllKeys() which uses a workaround');
static::markTestIncomplete('Race condition because of too fast getAllKeys() which uses a workaround');
}
}

12
tests/src/Core/Cache/MemcachedCacheTest.php

@ -21,8 +21,10 @@
namespace Friendica\Test\src\Core\Cache;
use Exception;
use Friendica\Core\Cache\MemcachedCache;
use Friendica\Core\Config\IConfig;
use Mockery;
use Psr\Log\NullLogger;
/**
@ -33,7 +35,7 @@ class MemcachedCacheTest extends MemoryCacheTest
{
protected function getInstance()
{
$configMock = \Mockery::mock(IConfig::class);
$configMock = Mockery::mock(IConfig::class);
$host = $_SERVER['MEMCACHED_HOST'] ?? 'localhost';
$port = $_SERVER['MEMCACHED_PORT'] ?? '11211';
@ -47,13 +49,13 @@ class MemcachedCacheTest extends MemoryCacheTest
try {
$this->cache = new MemcachedCache($host, $configMock, $logger);
} catch (\Exception $exception) {
$this->markTestSkipped('Memcached is not available');
} catch (Exception $exception) {
static::markTestSkipped('Memcached is not available');
}
return $this->cache;
}
public function tearDown()
protected function tearDown()
{
$this->cache->clear(false);
parent::tearDown();
@ -66,6 +68,6 @@ class MemcachedCacheTest extends MemoryCacheTest
*/
public function testGetAllKeys($value1, $value2, $value3)
{
$this->markTestIncomplete('Race condition because of too fast getAllKeys() which uses a workaround');
static::markTestIncomplete('Race condition because of too fast getAllKeys() which uses a workaround');
}
}

15
tests/src/Core/Cache/MemoryCacheTest.php

@ -21,12 +21,13 @@
namespace Friendica\Test\src\Core\Cache;
use Exception;
use Friendica\Core\Cache\IMemoryCache;
abstract class MemoryCacheTest extends CacheTest
{
/**
* @var \Friendica\Core\Cache\IMemoryCache
* @var IMemoryCache
*/
protected $instance;
@ -35,7 +36,7 @@ abstract class MemoryCacheTest extends CacheTest
parent::setUp();
if (!($this->instance instanceof IMemoryCache)) {
throw new \Exception('MemoryCacheTest unsupported');
throw new Exception('MemoryCacheTest unsupported');
}
}
@ -43,7 +44,7 @@ abstract class MemoryCacheTest extends CacheTest
* @small
* @dataProvider dataSimple
*/
function testCompareSet($value1, $value2)
public function testCompareSet($value1, $value2)
{
self::assertNull($this->instance->get('value1'));
@ -60,7 +61,7 @@ abstract class MemoryCacheTest extends CacheTest
* @small
* @dataProvider dataSimple
*/
function testNegativeCompareSet($value1, $value2)
public function testNegativeCompareSet($value1, $value2)
{
self::assertNull($this->instance->get('value1'));
@ -78,7 +79,7 @@ abstract class MemoryCacheTest extends CacheTest
* @small
* @dataProvider dataSimple
*/
function testCompareDelete($data)
public function testCompareDelete($data)
{
self::assertNull($this->instance->get('value1'));
@ -93,7 +94,7 @@ abstract class MemoryCacheTest extends CacheTest
* @small
* @dataProvider dataSimple
*/
function testNegativeCompareDelete($data)
public function testNegativeCompareDelete($data)
{
self::assertNull($this->instance->get('value1'));