Fix a lot of notices/warnings/deprecation notes in the test directory
This commit is contained in:
parent
efaec26b1d
commit
d55ecb9288
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
@ -65,6 +66,8 @@ trait AppMockTrait
|
|||
*
|
||||
* @param vfsStreamDirectory $root The root directory
|
||||
* @param bool $raw If true, no config mocking will be done
|
||||
*
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public function mockApp(vfsStreamDirectory $root, $raw = false)
|
||||
{
|
||||
|
|
|
@ -85,7 +85,7 @@ trait DBAMockTrait
|
|||
* @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();
|
||||
|
||||
|
@ -145,7 +145,7 @@ trait DBAMockTrait
|
|||
* @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();
|
||||
|
||||
|
@ -164,7 +164,7 @@ trait DBAMockTrait
|
|||
* @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();
|
||||
|
||||
|
@ -185,7 +185,7 @@ trait DBAMockTrait
|
|||
* @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();
|
||||
|
||||
|
@ -213,7 +213,7 @@ trait DBAMockTrait
|
|||
* @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();
|
||||
|
||||
|
@ -240,7 +240,7 @@ trait DBAMockTrait
|
|||
* @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();
|
||||
|
||||
|
@ -325,7 +325,7 @@ trait DBAMockTrait
|
|||
* @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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
@ -62,7 +62,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 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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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 = [
|
||||
|
|
|
@ -16,6 +16,8 @@ trait HookMockTrait
|
|||
/**
|
||||
* Mocking a method 'Hook::call()' call
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $capture
|
||||
*/
|
||||
public function mockHookCallAll(string $name, &$capture)
|
||||
{
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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);
|
||||
|
@ -59,7 +59,7 @@ trait RendererMockTrait
|
|||
* @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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -60,7 +60,7 @@ trait VFSTrait
|
|||
* @param string $filename The filename of the config file
|
||||
* @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 .
|
||||
|
@ -80,7 +80,7 @@ trait VFSTrait
|
|||
* @param string $filename The filename of the config file
|
||||
* @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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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);
|
||||
|
||||
$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,7 +118,8 @@ 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');
|
||||
|
@ -127,7 +131,8 @@ class ConfigConsoleTest extends ConsoleTest
|
|||
self::assertEquals($assertion, $firstline);
|
||||
}
|
||||
|
||||
function testVerbose() {
|
||||
public function testVerbose()
|
||||
{
|
||||
$this->configMock
|
||||
->shouldReceive('get')
|
||||
->with('test', 'it')
|
||||
|
@ -155,7 +160,8 @@ CONF;
|
|||
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');
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,6 +27,6 @@ class ItemTest extends MockedTest
|
|||
{
|
||||
public function testDetermineCategoriesTerms()
|
||||
{
|
||||
$this->markTestIncomplete('Test data needed.');
|
||||
static::markTestIncomplete('Test data needed.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
@ -293,9 +298,10 @@ class BBCodeTest extends MockedTest
|
|||
* @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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -31,7 +31,7 @@ class ArrayCacheTest extends MemoryCacheTest
|
|||
return $this->cache;
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->cache->clear(false);
|
||||
parent::tearDown();
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'));
|
||||
|
||||
|
@ -111,7 +112,7 @@ abstract class MemoryCacheTest extends CacheTest
|
|||
* @small
|
||||
* @dataProvider dataSimple
|
||||
*/
|
||||
function testAdd($value1, $value2)
|
||||
public function testAdd($value1, $value2)
|
||||
{
|
||||
self::assertNull($this->instance->get('value1'));
|
||||
|
||||
|
|
|
@ -21,8 +21,10 @@
|
|||
|
||||
namespace Friendica\Test\src\Core\Cache;
|
||||
|
||||
use Exception;
|
||||
use Friendica\Core\Cache\RedisCache;
|
||||
use Friendica\Core\Config\IConfig;
|
||||
use Mockery;
|
||||
|
||||
/**
|
||||
* @requires extension redis
|
||||
|
@ -32,7 +34,7 @@ class RedisCacheTest extends MemoryCacheTest
|
|||
{
|
||||
protected function getInstance()
|
||||
{
|
||||
$configMock = \Mockery::mock(IConfig::class);
|
||||
$configMock = Mockery::mock(IConfig::class);
|
||||
|
||||
$host = $_SERVER['REDIS_HOST'] ?? 'localhost';
|
||||
$port = $_SERVER['REDIS_PORT'] ?? null;
|
||||
|
@ -57,13 +59,13 @@ class RedisCacheTest extends MemoryCacheTest
|
|||
|
||||
try {
|
||||
$this->cache = new RedisCache($host, $configMock);
|
||||
} catch (\Exception $e) {
|
||||
$this->markTestSkipped('Redis is not available.');
|
||||
} catch (Exception $e) {
|
||||
static::markTestSkipped('Redis is not available.');
|
||||
}
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->cache->clear(false);
|
||||
parent::tearDown();
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace Friendica\Test\src\Core\Config;
|
|||
use Friendica\Core\Config\Cache;
|
||||
use Friendica\Test\MockedTest;
|
||||
use ParagonIE\HiddenString\HiddenString;
|
||||
use stdClass;
|
||||
|
||||
class CacheTest extends MockedTest
|
||||
{
|
||||
|
@ -300,7 +301,7 @@ class CacheTest extends MockedTest
|
|||
{
|
||||
$configCache = new Cache([
|
||||
'database' => [
|
||||
'password' => new \stdClass(),
|
||||
'password' => new stdClass(),
|
||||
'username' => '',
|
||||
]
|
||||
]);
|
||||
|
|
|
@ -67,7 +67,7 @@ abstract class ConfigTest extends MockedTest
|
|||
/**
|
||||
* @return IConfig
|
||||
*/
|
||||
public abstract function getInstance();
|
||||
abstract public function getInstance();
|
||||
|
||||
public function dataTests()
|
||||
{
|
||||
|
@ -169,8 +169,11 @@ abstract class ConfigTest extends MockedTest
|
|||
|
||||
/**
|
||||
* Test the configuration load() method
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $load
|
||||
*/
|
||||
public function testLoad(array $data, array $possibleCats, array $load)
|
||||
public function testLoad(array $data, array $load)
|
||||
{
|
||||
$this->testedConfig = $this->getInstance();
|
||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
||||
|
@ -251,7 +254,7 @@ abstract class ConfigTest extends MockedTest
|
|||
/**
|
||||
* Test the configuration load() method with overwrite
|
||||
*/
|
||||
public function testCacheLoadDouble(array $data1, array $data2, array $expect)
|
||||
public function testCacheLoadDouble(array $data1, array $data2, array $expect = [])
|
||||
{
|
||||
$this->testedConfig = $this->getInstance();
|
||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
||||
|
|
|
@ -45,8 +45,11 @@ class JitConfigTest extends ConfigTest
|
|||
|
||||
/**
|
||||
* @dataProvider dataConfigLoad
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $load
|
||||
*/
|
||||
public function testLoad(array $data, array $possibleCats, array $load)
|
||||
public function testLoad(array $data, array $load)
|
||||
{
|
||||
$this->configModel->shouldReceive('isConnected')
|
||||
->andReturn(true)
|
||||
|
@ -64,13 +67,13 @@ class JitConfigTest extends ConfigTest
|
|||
->once();
|
||||
}
|
||||
|
||||
parent::testLoad($data, $possibleCats, $load);
|
||||
parent::testLoad($data, $load);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataDoubleLoad
|
||||
*/
|
||||
public function testCacheLoadDouble(array $data1, array $data2, array $expect)
|
||||
public function testCacheLoadDouble(array $data1, array $data2, array $expect = [])
|
||||
{
|
||||
$this->configModel->shouldReceive('isConnected')
|
||||
->andReturn(true)
|
||||
|
@ -96,7 +99,7 @@ class JitConfigTest extends ConfigTest
|
|||
->once();
|
||||
}
|
||||
|
||||
parent::testCacheLoadDouble($data1, $data2, $expect);
|
||||
parent::testCacheLoadDouble($data1, $data2);
|
||||
|
||||
// Assert the expected categories
|
||||
foreach ($data2 as $cat => $data) {
|
||||
|
|
|
@ -44,8 +44,11 @@ class PreloadConfigTest extends ConfigTest
|
|||
|
||||
/**
|
||||
* @dataProvider dataConfigLoad
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $load
|
||||
*/
|
||||
public function testLoad(array $data, array $possibleCats, array $load)
|
||||
public function testLoad(array $data, array $load)
|
||||
{
|
||||
$this->configModel->shouldReceive('isConnected')
|
||||
->andReturn(true)
|
||||
|
@ -55,7 +58,7 @@ class PreloadConfigTest extends ConfigTest
|
|||
->andReturn($data)
|
||||
->once();
|
||||
|
||||
parent::testLoad($data, $possibleCats, $load);
|
||||
parent::testLoad($data, $load);
|
||||
|
||||
// Assert that every category is loaded everytime
|
||||
foreach ($data as $cat => $values) {
|
||||
|
@ -65,8 +68,11 @@ class PreloadConfigTest extends ConfigTest
|
|||
|
||||
/**
|
||||
* @dataProvider dataDoubleLoad
|
||||
*
|
||||
* @param array $data1
|
||||
* @param array $data2
|
||||
*/
|
||||
public function testCacheLoadDouble(array $data1, array $data2, array $expect)
|
||||
public function testCacheLoadDouble(array $data1, array $data2, array $expect = [])
|
||||
{
|
||||
$this->configModel->shouldReceive('isConnected')
|
||||
->andReturn(true)
|
||||
|
@ -76,7 +82,7 @@ class PreloadConfigTest extends ConfigTest
|
|||
->andReturn($data1)
|
||||
->once();
|
||||
|
||||
parent::testCacheLoadDouble($data1, $data2, $expect);
|
||||
parent::testCacheLoadDouble($data1, $data2);
|
||||
|
||||
// Assert that every category is loaded everytime and is NOT overwritten
|
||||
foreach ($data1 as $cat => $values) {
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
// this is in the same namespace as Install for mocking 'function_exists'
|
||||
/// @todo this is in the same namespace as Install for mocking 'function_exists'
|
||||
namespace Friendica\Core;
|
||||
|
||||
use Dice\Dice;
|
||||
|
@ -29,6 +29,7 @@ use Friendica\Network\CurlResult;
|
|||
use Friendica\Network\IHTTPRequest;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use Mockery;
|
||||
use Mockery\MockInterface;
|
||||
|
||||
class InstallerTest extends MockedTest
|
||||
|
@ -36,7 +37,7 @@ class InstallerTest extends MockedTest
|
|||
use VFSTrait;
|
||||
|
||||
/**
|
||||
* @var \Friendica\Core\L10n|MockInterface
|
||||
* @var L10n|MockInterface
|
||||
*/
|
||||
private $l10nMock;
|
||||
/**
|
||||
|
@ -44,20 +45,20 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
private $dice;
|
||||
|
||||
public function setUp()
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->setUpVfsDir();
|
||||
|
||||
$this->l10nMock = \Mockery::mock(\Friendica\Core\L10n::class);
|
||||
$this->l10nMock = Mockery::mock(L10n::class);
|
||||
|
||||
/** @var Dice|MockInterface $dice */
|
||||
$this->dice = \Mockery::mock(Dice::class)->makePartial();
|
||||
$this->dice = Mockery::mock(Dice::class)->makePartial();
|
||||
$this->dice = $this->dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php');
|
||||
|
||||
$this->dice->shouldReceive('create')
|
||||
->with(\Friendica\Core\L10n::class)
|
||||
->with(L10n::class)
|
||||
->andReturn($this->l10nMock);
|
||||
|
||||
DI::init($this->dice);
|
||||
|
@ -112,7 +113,7 @@ class InstallerTest extends MockedTest
|
|||
*
|
||||
* @param array $functions a list from function names and their result
|
||||
*/
|
||||
private function setFunctions($functions)
|
||||
private function setFunctions(array $functions)
|
||||
{
|
||||
global $phpMock;
|
||||
$phpMock['function_exists'] = function($function) use ($functions) {
|
||||
|
@ -130,7 +131,7 @@ class InstallerTest extends MockedTest
|
|||
*
|
||||
* @param array $classes a list from class names and their results
|
||||
*/
|
||||
private function setClasses($classes)
|
||||
private function setClasses(array $classes)
|
||||
{
|
||||
global $phpMock;
|
||||
$phpMock['class_exists'] = function($class) use ($classes) {
|
||||
|
@ -297,7 +298,7 @@ class InstallerTest extends MockedTest
|
|||
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
||||
|
||||
// Mocking the CURL Response
|
||||
$curlResult = \Mockery::mock(CurlResult::class);
|
||||
$curlResult = Mockery::mock(CurlResult::class);
|
||||
$curlResult
|
||||
->shouldReceive('getReturnCode')
|
||||
->andReturn('404');
|
||||
|
@ -309,7 +310,7 @@ class InstallerTest extends MockedTest
|
|||
->andReturn('test Error');
|
||||
|
||||
// Mocking the CURL Request
|
||||
$networkMock = \Mockery::mock(IHTTPRequest::class);
|
||||
$networkMock = Mockery::mock(IHTTPRequest::class);
|
||||
$networkMock
|
||||
->shouldReceive('fetchFull')
|
||||
->with('https://test/install/testrewrite')
|
||||
|
@ -344,19 +345,19 @@ class InstallerTest extends MockedTest
|
|||
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
||||
|
||||
// Mocking the failed CURL Response
|
||||
$curlResultF = \Mockery::mock(CurlResult::class);
|
||||
$curlResultF = Mockery::mock(CurlResult::class);
|
||||
$curlResultF
|
||||
->shouldReceive('getReturnCode')
|
||||
->andReturn('404');
|
||||
|
||||
// Mocking the working CURL Response
|
||||
$curlResultW = \Mockery::mock(CurlResult::class);
|
||||
$curlResultW = Mockery::mock(CurlResult::class);
|
||||
$curlResultW
|
||||
->shouldReceive('getReturnCode')
|
||||
->andReturn('204');
|
||||
|
||||
// Mocking the CURL Request
|
||||
$networkMock = \Mockery::mock(IHTTPRequest::class);
|
||||
$networkMock = Mockery::mock(IHTTPRequest::class);
|
||||
$networkMock
|
||||
->shouldReceive('fetchFull')
|
||||
->with('https://test/install/testrewrite')
|
||||
|
@ -387,7 +388,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testImagick()
|
||||
{
|
||||
$this->markTestIncomplete('needs adapted class_exists() mock');
|
||||
static::markTestIncomplete('needs adapted class_exists() mock');
|
||||
|
||||
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
||||
|
||||
|
@ -413,7 +414,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testImagickNotFound()
|
||||
{
|
||||
$this->markTestIncomplete('Disabled due not working/difficult mocking global functions - needs more care!');
|
||||
static::markTestIncomplete('Disabled due not working/difficult mocking global functions - needs more care!');
|
||||
|
||||
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
||||
|
||||
|
@ -456,8 +457,8 @@ class InstallerTest extends MockedTest
|
|||
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
||||
|
||||
$install = new Installer();
|
||||
$configCache = \Mockery::mock(Cache::class);
|
||||
$configCache->shouldReceive('set')->with('config', 'php_path', \Mockery::any())->once();
|
||||
$configCache = Mockery::mock(Cache::class);
|
||||
$configCache->shouldReceive('set')->with('config', 'php_path', Mockery::any())->once();
|
||||
$configCache->shouldReceive('set')->with('system', 'basepath', '/test/')->once();
|
||||
|
||||
$install->setUpCache($configCache, '/test/');
|
||||
|
@ -471,7 +472,7 @@ class InstallerTest extends MockedTest
|
|||
*
|
||||
* @return bool true or false
|
||||
*/
|
||||
function function_exists($function_name)
|
||||
function function_exists(string $function_name)
|
||||
{
|
||||
global $phpMock;
|
||||
if (isset($phpMock['function_exists'])) {
|
||||
|
|
|
@ -32,7 +32,7 @@ class APCuCacheLockTest extends LockTest
|
|||
protected function setUp()
|
||||
{
|
||||
if (!APCuCache::isAvailable()) {
|
||||
$this->markTestSkipped('APCu is not available');
|
||||
static::markTestSkipped('APCu is not available');
|
||||
}
|
||||
|
||||
parent::setUp();
|
||||
|
|
|
@ -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 DatabaseLockDriverTest extends LockTest
|
||||
|
@ -47,7 +48,7 @@ class DatabaseLockDriverTest extends LockTest
|
|||
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
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
namespace Friendica\Test\src\Core\Lock;
|
||||
|
||||
use Friendica\Core\Lock\ILock;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
abstract class LockTest extends MockedTest
|
||||
|
@ -31,7 +32,7 @@ abstract class LockTest extends MockedTest
|
|||
protected $startTime = 1417011228;
|
||||
|
||||
/**
|
||||
* @var \Friendica\Core\Lock\ILock
|
||||
* @var ILock
|
||||
*/
|
||||
protected $instance;
|
||||
|
||||
|
@ -185,9 +186,9 @@ abstract class LockTest extends MockedTest
|
|||
/**
|
||||
* @medium
|
||||
*/
|
||||
function testLockTTL()
|
||||
public function testLockTTL()
|
||||
{
|
||||
$this->markTestSkipped('taking too much time without mocking');
|
||||
static::markTestSkipped('taking too much time without mocking');
|
||||
|
||||
self::assertFalse($this->instance->isLocked('foo'));
|
||||
self::assertFalse($this->instance->isLocked('bar'));
|
||||
|
|
|
@ -21,9 +21,11 @@
|
|||
|
||||
namespace Friendica\Test\src\Core\Lock;
|
||||
|
||||
use Exception;
|
||||
use Friendica\Core\Cache\MemcacheCache;
|
||||
use Friendica\Core\Config\IConfig;
|
||||
use Friendica\Core\Lock\CacheLock;
|
||||
use Mockery;
|
||||
|
||||
/**
|
||||
* @requires extension Memcache
|
||||
|
@ -33,7 +35,7 @@ class MemcacheCacheLockTest extends LockTest
|
|||
{
|
||||
protected function getInstance()
|
||||
{
|
||||
$configMock = \Mockery::mock(IConfig::class);
|
||||
$configMock = Mockery::mock(IConfig::class);
|
||||
|
||||
$host = $_SERVER['MEMCACHE_HOST'] ?? 'localhost';
|
||||
$port = $_SERVER['MEMCACHE_PORT'] ?? '11211';
|
||||
|
@ -52,8 +54,8 @@ class MemcacheCacheLockTest extends LockTest
|
|||
try {
|
||||
$cache = new MemcacheCache($host, $configMock);
|
||||
$lock = new CacheLock($cache);
|
||||
} catch (\Exception $e) {
|
||||
$this->markTestSkipped('Memcache is not available');
|
||||
} catch (Exception $e) {
|
||||
static::markTestSkipped('Memcache is not available');
|
||||
}
|
||||
|
||||
return $lock;
|
||||
|
@ -64,7 +66,7 @@ class MemcacheCacheLockTest extends LockTest
|
|||
*/
|
||||
public function testGetLocks()
|
||||
{
|
||||
$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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,6 +74,6 @@ class MemcacheCacheLockTest extends LockTest
|
|||
*/
|
||||
public function testGetLocksWithPrefix()
|
||||
{
|
||||
$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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,11 @@
|
|||
|
||||
namespace Friendica\Test\src\Core\Lock;
|
||||
|
||||
use Exception;
|
||||
use Friendica\Core\Cache\MemcachedCache;
|
||||
use Friendica\Core\Config\IConfig;
|
||||
use Friendica\Core\Lock\CacheLock;
|
||||
use Mockery;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
/**
|
||||
|
@ -34,7 +36,7 @@ class MemcachedCacheLockTest extends LockTest
|
|||
{
|
||||
protected function getInstance()
|
||||
{
|
||||
$configMock = \Mockery::mock(IConfig::class);
|
||||
$configMock = Mockery::mock(IConfig::class);
|
||||
|
||||
$host = $_SERVER['MEMCACHED_HOST'] ?? 'localhost';
|
||||
$port = $_SERVER['MEMCACHED_PORT'] ?? '11211';
|
||||
|
@ -51,8 +53,8 @@ class MemcachedCacheLockTest extends LockTest
|
|||
try {
|
||||
$cache = new MemcachedCache($host, $configMock, $logger);
|
||||
$lock = new CacheLock($cache);
|
||||
} catch (\Exception $e) {
|
||||
$this->markTestSkipped('Memcached is not available');
|
||||
} catch (Exception $e) {
|
||||
static::markTestSkipped('Memcached is not available');
|
||||
}
|
||||
|
||||
return $lock;
|
||||
|
@ -60,11 +62,11 @@ class MemcachedCacheLockTest extends LockTest
|
|||
|
||||
public function testGetLocks()
|
||||
{
|
||||
$this->markTestIncomplete('Race condition because of too fast getLocks() which uses a workaround');
|
||||
static::markTestIncomplete('Race condition because of too fast getLocks() which uses a workaround');
|
||||
}
|
||||
|
||||
public function testGetLocksWithPrefix()
|
||||
{
|
||||
$this->markTestIncomplete('Race condition because of too fast getLocks() which uses a workaround');
|
||||
static::markTestIncomplete('Race condition because of too fast getLocks() which uses a workaround');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,11 @@
|
|||
|
||||
namespace Friendica\Test\src\Core\Lock;
|
||||
|
||||
use Exception;
|
||||
use Friendica\Core\Cache\RedisCache;
|
||||
use Friendica\Core\Config\IConfig;
|
||||
use Friendica\Core\Lock\CacheLock;
|
||||
use Mockery;
|
||||
|
||||
/**
|
||||
* @requires extension redis
|
||||
|
@ -33,7 +35,7 @@ class RedisCacheLockTest extends LockTest
|
|||
{
|
||||
protected function getInstance()
|
||||
{
|
||||
$configMock = \Mockery::mock(IConfig::class);
|
||||
$configMock = Mockery::mock(IConfig::class);
|
||||
|
||||
$host = $_SERVER['REDIS_HOST'] ?? 'localhost';
|
||||
$port = $_SERVER['REDIS_PORT'] ?? null;
|
||||
|
@ -61,8 +63,8 @@ class RedisCacheLockTest extends LockTest
|
|||
try {
|
||||
$cache = new RedisCache($host, $configMock);
|
||||
$lock = new CacheLock($cache);
|
||||
} catch (\Exception $e) {
|
||||
$this->markTestSkipped('Redis is not available');
|
||||
} catch (Exception $e) {
|
||||
static::markTestSkipped('Redis is not available');
|
||||
}
|
||||
|
||||
return $lock;
|
||||
|
|
|
@ -27,20 +27,21 @@ use Friendica\Core\Config\IConfig;
|
|||
use Friendica\Core\Config\JitConfig;
|
||||
use Friendica\Core\Lock\SemaphoreLock;
|
||||
use Friendica\DI;
|
||||
use Mockery;
|
||||
use Mockery\MockInterface;
|
||||
|
||||
class SemaphoreLockTest extends LockTest
|
||||
{
|
||||
public function setUp()
|
||||
protected function setUp()
|
||||
{
|
||||
/** @var MockInterface|Dice $dice */
|
||||
$dice = \Mockery::mock(Dice::class)->makePartial();
|
||||
$dice = Mockery::mock(Dice::class)->makePartial();
|
||||
|
||||
$app = \Mockery::mock(App::class);
|
||||
$app = Mockery::mock(App::class);
|
||||
$app->shouldReceive('getHostname')->andReturn('friendica.local');
|
||||
$dice->shouldReceive('create')->with(App::class)->andReturn($app);
|
||||
|
||||
$configMock = \Mockery::mock(JitConfig::class);
|
||||
$configMock = Mockery::mock(JitConfig::class);
|
||||
$configMock
|
||||
->shouldReceive('get')
|
||||
->with('system', 'temppath')
|
||||
|
@ -58,7 +59,7 @@ class SemaphoreLockTest extends LockTest
|
|||
return new SemaphoreLock();
|
||||
}
|
||||
|
||||
function testLockTTL()
|
||||
public function testLockTTL()
|
||||
{
|
||||
// Semaphore doesn't work with TTL
|
||||
return true;
|
||||
|
@ -83,6 +84,7 @@ class SemaphoreLockTest extends LockTest
|
|||
* This test proves that semaphore locks cannot get released by other instances except themselves
|
||||
*
|
||||
* Check for Bug https://github.com/friendica/friendica/issues/7298#issuecomment-521996540
|
||||
*
|
||||
* @see https://github.com/friendica/friendica/issues/7298#issuecomment-521996540
|
||||
*/
|
||||
public function testMissingFileOverriding()
|
||||
|
|
|
@ -133,10 +133,8 @@ class CacheTest extends MockedTest
|
|||
|
||||
/**
|
||||
* Test the keyDiff() method with result
|
||||
*
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testKeyDiffWithResult($data)
|
||||
public function testKeyDiffWithResult()
|
||||
{
|
||||
$configCache = new Cache();
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
namespace Friendica\Test\src\Core\PConfig;
|
||||
|
||||
use Friendica\Core\PConfig\JitPConfig;
|
||||
use Friendica\Test\src\Core\PConfig\PConfigTest;
|
||||
|
||||
class JitPConfigTest extends PConfigTest
|
||||
{
|
||||
|
|
|
@ -69,7 +69,7 @@ abstract class PConfigTest extends MockedTest
|
|||
/**
|
||||
* @return BasePConfig
|
||||
*/
|
||||
public abstract function getInstance();
|
||||
abstract public function getInstance();
|
||||
|
||||
public function dataTests()
|
||||
{
|
||||
|
@ -159,9 +159,8 @@ abstract class PConfigTest extends MockedTest
|
|||
|
||||
/**
|
||||
* Test the configuration initialization
|
||||
* @dataProvider dataConfigLoad
|
||||
*/
|
||||
public function testSetUp(int $uid, array $data)
|
||||
public function testSetUp()
|
||||
{
|
||||
$this->testedConfig = $this->getInstance();
|
||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
namespace Friendica\Test\src\Core\PConfig;
|
||||
|
||||
use Friendica\Core\PConfig\PreloadPConfig;
|
||||
use Friendica\Test\src\Core\PConfig\PConfigTest;
|
||||
|
||||
class PreloadPConfigTest extends PConfigTest
|
||||
{
|
||||
|
|
|
@ -34,6 +34,7 @@ use Friendica\Factory\ConfigFactory;
|
|||
use Friendica\Model\Config\Config;
|
||||
use Friendica\Model\Storage;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Model\Storage\StorageException;
|
||||
use Friendica\Test\DatabaseTest;
|
||||
use Friendica\Test\Util\Database\StaticDatabase;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
|
@ -56,7 +57,7 @@ class StorageManagerTest extends DatabaseTest
|
|||
|
||||
use VFSTrait;
|
||||
|
||||
public function setUp()
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -319,12 +320,12 @@ class StorageManagerTest extends DatabaseTest
|
|||
|
||||
/**
|
||||
* Test moving data to a WRONG storage
|
||||
*
|
||||
* @expectedException \Friendica\Model\Storage\StorageException
|
||||
* @expectedExceptionMessage Can't move to storage backend 'SystemResource'
|
||||
*/
|
||||
public function testMoveStorageWrong()
|
||||
{
|
||||
$this->expectExceptionMessage("Can't move to storage backend 'SystemResource'");
|
||||
$this->expectException(StorageException::class);
|
||||
|
||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
||||
$storage = $storageManager->getByName(Storage\SystemResource::getName());
|
||||
$storageManager->move($storage);
|
||||
|
|
|
@ -45,28 +45,28 @@ class SystemTest extends TestCase
|
|||
self::assertRegExp("/^" . $prefix . "[a-z0-9]{" . $length . "}?$/", $guid);
|
||||
}
|
||||
|
||||
function testGuidWithoutParameter()
|
||||
public function testGuidWithoutParameter()
|
||||
{
|
||||
$this->useBaseUrl();
|
||||
$guid = System::createGUID();
|
||||
self::assertGuid($guid, 16);
|
||||
}
|
||||
|
||||
function testGuidWithSize32()
|
||||
public function testGuidWithSize32()
|
||||
{
|
||||
$this->useBaseUrl();
|
||||
$guid = System::createGUID(32);
|
||||
self::assertGuid($guid, 32);
|
||||
}
|
||||
|
||||
function testGuidWithSize64()
|
||||
public function testGuidWithSize64()
|
||||
{
|
||||
$this->useBaseUrl();
|
||||
$guid = System::createGUID(64);
|
||||
self::assertGuid($guid, 64);
|
||||
}
|
||||
|
||||
function testGuidWithPrefix()
|
||||
public function testGuidWithPrefix()
|
||||
{
|
||||
$guid = System::createGUID(23, 'test');
|
||||
self::assertGuid($guid, 23, 'test');
|
||||
|
|
|
@ -10,7 +10,7 @@ use Friendica\Test\Util\Database\StaticDatabase;
|
|||
|
||||
class DBATest extends DatabaseTest
|
||||
{
|
||||
public function setUp()
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ class DBStructureTest extends DatabaseTest
|
|||
* @small
|
||||
*/
|
||||
public function testChangePrimaryKey() {
|
||||
$this->markTestSkipped('rename primary key with autoincrement and foreign key support necessary first');
|
||||
static::markTestSkipped('rename primary key with autoincrement and foreign key support necessary first');
|
||||
$oldID = 'client_id';
|
||||
$newID = 'pw';
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ class ProcessTest extends DatabaseTest
|
|||
|
||||
$this->setUpVfsDir();
|
||||
|
||||
$this->logger = new NullLogger();
|
||||
$logger = new NullLogger();
|
||||
|
||||
$profiler = \Mockery::mock(Profiler::class);
|
||||
$profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
|
||||
|
@ -34,7 +34,7 @@ class ProcessTest extends DatabaseTest
|
|||
$loader = new ConfigFileLoader($this->root->url());
|
||||
$configCache = $configFactory->createCache($loader);
|
||||
|
||||
$this->dba = new StaticDatabase($configCache, $profiler, $this->logger);
|
||||
$this->dba = new StaticDatabase($configCache, $profiler, $logger);
|
||||
}
|
||||
|
||||
public function testInsertDelete()
|
||||
|
|
|
@ -25,12 +25,12 @@ use Friendica\Core\Config\IConfig;
|
|||
use Friendica\Core\L10n;
|
||||
use Friendica\Model\Storage\Filesystem;
|
||||
use Friendica\Model\Storage\IStorage;
|
||||
use Friendica\Model\Storage\StorageException;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use Friendica\Util\Profiler;
|
||||
use Mockery\MockInterface;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
use Psr\Log\NullLogger;
|
||||
use function GuzzleHttp\Psr7\uri_for;
|
||||
|
||||
class FilesystemStorageTest extends StorageTest
|
||||
{
|
||||
|
@ -77,12 +77,11 @@ class FilesystemStorageTest extends StorageTest
|
|||
|
||||
/**
|
||||
* Test the exception in case of missing directorsy permissions
|
||||
*
|
||||
* @expectedException \Friendica\Model\Storage\StorageException
|
||||
* @expectedExceptionMessageRegExp /Filesystem storage failed to create \".*\". Check you write permissions./
|
||||
*/
|
||||
public function testMissingDirPermissions()
|
||||
{
|
||||
$this->expectException(StorageException::class);
|
||||
$this->expectExceptionMessageRegExp("/Filesystem storage failed to create \".*\". Check you write permissions./");
|
||||
$this->root->getChild('storage')->chmod(000);
|
||||
|
||||
$instance = $this->getInstance();
|
||||
|
@ -92,12 +91,13 @@ class FilesystemStorageTest extends StorageTest
|
|||
/**
|
||||
* Test the exception in case of missing file permissions
|
||||
*
|
||||
* @expectedException \Friendica\Model\Storage\StorageException
|
||||
* @expectedExceptionMessageRegExp /Filesystem storage failed to save data to \".*\". Check your write permissions/
|
||||
*/
|
||||
public function testMissingFilePermissions()
|
||||
{
|
||||
$this->markTestIncomplete("Cannot catch file_put_content() error due vfsStream failure");
|
||||
static::markTestIncomplete("Cannot catch file_put_content() error due vfsStream failure");
|
||||
|
||||
$this->expectException(StorageException::class);
|
||||
$this->expectExceptionMessageRegExp("/Filesystem storage failed to save data to \".*\". Check your write permissions/");
|
||||
|
||||
vfsStream::create(['storage' => ['f0' => ['c0' => ['k0i0' => '']]]], $this->root);
|
||||
|
||||
|
|
|
@ -48,6 +48,8 @@ class CookieTest extends MockedTest
|
|||
protected function tearDown()
|
||||
{
|
||||
StaticCookie::clearStatic();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Friendica\Test\src\Module\Api\Twitter;
|
||||
|
||||
use Friendica\Module\Api\Twitter\ContactEndpoint;
|
||||
|
||||
/**
|
||||
* Class ContactEndpointMock
|
||||
*
|
||||
|
@ -13,7 +15,7 @@ namespace Friendica\Test\src\Module\Api\Twitter;
|
|||
*
|
||||
* @package Friendica\Test\Mock\Module\Api\Twitter
|
||||
*/
|
||||
class ContactEndpointMock extends \Friendica\Module\Api\Twitter\ContactEndpoint
|
||||
class ContactEndpointMock extends ContactEndpoint
|
||||
{
|
||||
public static function __callStatic($name, $arguments)
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Friendica\Test\src\Module\Api\Twitter;
|
|||
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Module\Api\Twitter\ContactEndpoint;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Friendica\Object\Api\Twitter\User;
|
||||
use Friendica\Test\FixtureTest;
|
||||
|
@ -172,7 +173,7 @@ class ContactEndpointTest extends FixtureTest
|
|||
* @depends testIds
|
||||
*
|
||||
* @throws NotFoundException
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public function testList()
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
namespace Friendica\Test\src\Util;
|
||||
|
||||
use Error;
|
||||
use Friendica\Model\Group;
|
||||
use Friendica\Util\ACLFormatter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
|
|
@ -64,11 +64,12 @@ class BasePathTest extends MockedTest
|
|||
|
||||
/**
|
||||
* Test the basepath determination with a complete wrong path
|
||||
* @expectedException \Exception
|
||||
* @expectedExceptionMessageRegExp /(.*) is not a valid basepath/
|
||||
*/
|
||||
public function testFailedBasePath()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessageRegExp("/(.*) is not a valid basepath/");
|
||||
|
||||
$basepath = new BasePath('/now23452sgfgas', []);
|
||||
$basepath->getPath();
|
||||
}
|
||||
|
|
|
@ -534,9 +534,9 @@ class BaseURLTest extends MockedTest
|
|||
self::assertFalse($baseUrl->save('test', 10, 'nope'));
|
||||
|
||||
// nothing should have changed because we never successfully saved anything
|
||||
self::assertEquals($baseUrl->getHostname(), 'friendica.local');
|
||||
self::assertEquals($baseUrl->getUrlPath(), 'new/test');
|
||||
self::assertEquals($baseUrl->getSSLPolicy(), BaseURL::DEFAULT_SSL_SCHEME);
|
||||
self::assertEquals($baseUrl->get(), 'http://friendica.local/new/test');
|
||||
self::assertEquals('friendica.local', $baseUrl->getHostname());
|
||||
self::assertEquals('new/test', $baseUrl->getUrlPath());
|
||||
self::assertEquals(BaseURL::DEFAULT_SSL_SCHEME, $baseUrl->getSSLPolicy());
|
||||
self::assertEquals('http://friendica.local/new/test', $baseUrl->get());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,11 +55,12 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
|
||||
/**
|
||||
* Test the loadConfigFiles() method with a wrong local.config.php
|
||||
* @expectedException \Exception
|
||||
* @expectedExceptionMessageRegExp /Error loading config file \w+/
|
||||
*
|
||||
*/
|
||||
public function testLoadConfigWrong()
|
||||
{
|
||||
$this->expectExceptionMessageRegExp("/Error loading config file \w+/");
|
||||
$this->expectException(\Exception::class);
|
||||
$this->delConfigFile('local.config.php');
|
||||
|
||||
vfsStream::newFile('local.config.php')
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
*
|
||||
* This is in the same namespace as Crypto for mocking 'rand' and 'random_init'
|
||||
*/
|
||||
|
||||
/// @todo Use right namespace - needs alternative way of mocking random_int()
|
||||
namespace Friendica\Util;
|
||||
|
||||
use phpseclib\Crypt\RSA;
|
||||
|
@ -120,7 +122,6 @@ function random_int($min, $max)
|
|||
{
|
||||
global $phpMock;
|
||||
if (isset($phpMock['random_int'])) {
|
||||
$result = call_user_func_array($phpMock['random_int'], func_get_args());
|
||||
return $result;
|
||||
return call_user_func_array($phpMock['random_int'], func_get_args());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,9 +35,6 @@ class EMailerTest extends MockedTest
|
|||
/** @var BaseURL|MockInterface */
|
||||
private $baseUrl;
|
||||
|
||||
/** @var string */
|
||||
private $defaultHeaders;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
@ -54,8 +51,6 @@ class EMailerTest extends MockedTest
|
|||
$this->baseUrl = \Mockery::mock(BaseURL::class);
|
||||
$this->baseUrl->shouldReceive('getHostname')->andReturn('friendica.local');
|
||||
$this->baseUrl->shouldReceive('get')->andReturn('http://friendica.local');
|
||||
|
||||
$this->defaultHeaders = [];
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace Friendica\Test\src\Util\Emailer;
|
|||
use Friendica\App\BaseURL;
|
||||
use Friendica\Core\Config\IConfig;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Object\EMail\IEmail;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Test\Util\SampleMailBuilder;
|
||||
|
@ -50,7 +51,7 @@ class MailBuilderTest extends MockedTest
|
|||
/** @var string */
|
||||
private $defaultHeaders;
|
||||
|
||||
public function setUp()
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -95,7 +96,7 @@ class MailBuilderTest extends MockedTest
|
|||
*/
|
||||
public function testBuilderWithNonRawEmail()
|
||||
{
|
||||
$this->markTestIncomplete('Cannot easily mock Renderer and BBCode, so skipping tests wit them');
|
||||
static::markTestIncomplete('Cannot easily mock Renderer and BBCode, so skipping tests wit them');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,11 +129,12 @@ class MailBuilderTest extends MockedTest
|
|||
/**
|
||||
* Test if the builder throws an exception in case no recipient
|
||||
*
|
||||
* @expectedException \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @expectedExceptionMessage Recipient address is missing.
|
||||
*/
|
||||
public function testBuilderWithEmptyMail()
|
||||
{
|
||||
$this->expectException(InternalServerErrorException::class);
|
||||
$this->expectExceptionMessage("Recipient address is missing.");
|
||||
|
||||
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config, new NullLogger());
|
||||
|
||||
$builder->build(true);
|
||||
|
@ -140,12 +142,12 @@ class MailBuilderTest extends MockedTest
|
|||
|
||||
/**
|
||||
* Test if the builder throws an exception in case no sender
|
||||
*
|
||||
* @expectedException \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @expectedExceptionMessage Sender address or name is missing.
|
||||
*/
|
||||
public function testBuilderWithEmptySender()
|
||||
{
|
||||
$this->expectException(InternalServerErrorException::class);
|
||||
$this->expectExceptionMessage("Sender address or name is missing.");
|
||||
|
||||
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config, new NullLogger());
|
||||
|
||||
$builder
|
||||
|
|
|
@ -41,10 +41,7 @@ class SystemMailBuilderTest extends MockedTest
|
|||
/** @var BaseURL */
|
||||
private $baseUrl;
|
||||
|
||||
/** @var string[] */
|
||||
private $defaultHeaders;
|
||||
|
||||
public function setUp()
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -59,8 +56,6 @@ class SystemMailBuilderTest extends MockedTest
|
|||
$this->baseUrl = \Mockery::mock(BaseURL::class);
|
||||
$this->baseUrl->shouldReceive('getHostname')->andReturn('friendica.local');
|
||||
$this->baseUrl->shouldReceive('get')->andReturn('http://friendica.local');
|
||||
|
||||
$this->defaultHeaders = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,11 +32,6 @@ class StreamLoggerTest extends AbstractLoggerTest
|
|||
{
|
||||
use VFSTrait;
|
||||
|
||||
/**
|
||||
* @var StreamLogger
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* @var vfsStreamFile
|
||||
*/
|
||||
|
@ -53,7 +48,7 @@ class StreamLoggerTest extends AbstractLoggerTest
|
|||
|
||||
$this->setUpVfsDir();
|
||||
|
||||
$this->fileSystem = new Filesystem();
|
||||
$this->fileSystem = new FileSystem();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,9 +59,9 @@ class StreamLoggerTest extends AbstractLoggerTest
|
|||
$this->logfile = vfsStream::newFile('friendica.log')
|
||||
->at($this->root);
|
||||
|
||||
$this->logger = new StreamLogger('test', $this->logfile->url(), $this->introspection, $this->fileSystem, $level);
|
||||
$logger = new StreamLogger('test', $this->logfile->url(), $this->introspection, $this->fileSystem, $level);
|
||||
|
||||
return $this->logger;
|
||||
return $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,11 +111,12 @@ class StreamLoggerTest extends AbstractLoggerTest
|
|||
|
||||
/**
|
||||
* Test when a file isn't set
|
||||
* @expectedException \LogicException
|
||||
* @expectedExceptionMessage Missing stream URL.
|
||||
*/
|
||||
public function testNoUrl()
|
||||
{
|
||||
$this->expectException(\LogicException::class);
|
||||
$this->expectExceptionMessage("Missing stream URL.");
|
||||
|
||||
$logger = new StreamLogger('test', '', $this->introspection, $this->fileSystem);
|
||||
|
||||
$logger->emergency('not working');
|
||||
|
@ -128,11 +124,12 @@ class StreamLoggerTest extends AbstractLoggerTest
|
|||
|
||||
/**
|
||||
* Test when a file cannot be opened
|
||||
* @expectedException \UnexpectedValueException
|
||||
* @expectedExceptionMessageRegExp /The stream or file .* could not be opened: .* /
|
||||
*/
|
||||
public function testWrongUrl()
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp("/The stream or file .* could not be opened: .* /");
|
||||
|
||||
$logfile = vfsStream::newFile('friendica.log')
|
||||
->at($this->root)->chmod(0);
|
||||
|
||||
|
@ -143,12 +140,13 @@ class StreamLoggerTest extends AbstractLoggerTest
|
|||
|
||||
/**
|
||||
* Test when the directory cannot get created
|
||||
* @expectedException \UnexpectedValueException
|
||||
* @expectedExceptionMessageRegExp /Directory .* cannot get created: .* /
|
||||
*/
|
||||
public function testWrongDir()
|
||||
{
|
||||
$this->markTestIncomplete('We need a platform independent way to set directory to readonly');
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp("/Directory .* cannot get created: .* /");
|
||||
|
||||
static::markTestIncomplete('We need a platform independent way to set directory to readonly');
|
||||
|
||||
$logger = new StreamLogger('test', '/$%/wrong/directory/file.txt', $this->introspection, $this->fileSystem);
|
||||
|
||||
|
@ -157,21 +155,23 @@ class StreamLoggerTest extends AbstractLoggerTest
|
|||
|
||||
/**
|
||||
* Test when the minimum level is not valid
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessageRegExp /The level ".*" is not valid./
|
||||
*/
|
||||
public function testWrongMinimumLevel()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessageRegExp("/The level \".*\" is not valid./");
|
||||
|
||||
$logger = new StreamLogger('test', 'file.text', $this->introspection, $this->fileSystem, 'NOPE');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test when the minimum level is not valid
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessageRegExp /The level ".*" is not valid./
|
||||
*/
|
||||
public function testWrongLogLevel()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessageRegExp("/The level \".*\" is not valid./");
|
||||
|
||||
$logfile = vfsStream::newFile('friendica.log')
|
||||
->at($this->root);
|
||||
|
||||
|
@ -182,11 +182,12 @@ class StreamLoggerTest extends AbstractLoggerTest
|
|||
|
||||
/**
|
||||
* Test when the file is null
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage A stream must either be a resource or a string.
|
||||
*/
|
||||
public function testWrongFile()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage("A stream must either be a resource or a string.");
|
||||
|
||||
$logger = new StreamLogger('test', null, $this->introspection, $this->fileSystem);
|
||||
}
|
||||
|
||||
|
@ -195,7 +196,7 @@ class StreamLoggerTest extends AbstractLoggerTest
|
|||
*/
|
||||
public function testRealPath()
|
||||
{
|
||||
$this->markTestSkipped('vfsStream isn\'t compatible with chdir, so not testable.');
|
||||
static::markTestSkipped('vfsStream isn\'t compatible with chdir, so not testable.');
|
||||
|
||||
$logfile = vfsStream::newFile('friendica.log')
|
||||
->at($this->root);
|
||||
|
|
|
@ -59,21 +59,23 @@ class SyslogLoggerTest extends AbstractLoggerTest
|
|||
|
||||
/**
|
||||
* Test when the minimum level is not valid
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessageRegExp /The level ".*" is not valid./
|
||||
*/
|
||||
public function testWrongMinimumLevel()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessageRegExp("/The level \".*\" is not valid./");
|
||||
|
||||
$logger = new SyslogLoggerWrapper('test', $this->introspection, 'NOPE');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test when the minimum level is not valid
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessageRegExp /The level ".*" is not valid./
|
||||
*/
|
||||
public function testWrongLogLevel()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessageRegExp("/The level \".*\" is not valid./");
|
||||
|
||||
$logger = new SyslogLoggerWrapper('test', $this->introspection);
|
||||
|
||||
$logger->log('NOPE', 'a test');
|
||||
|
@ -81,11 +83,12 @@ class SyslogLoggerTest extends AbstractLoggerTest
|
|||
|
||||
/**
|
||||
* Test when the logfacility is wrong (string)
|
||||
* @expectedException \UnexpectedValueException
|
||||
* @expectedExceptionMessageRegExp /Can\'t open syslog for ident ".*" and facility ".*": .* /
|
||||
*/
|
||||
public function testServerException()
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp("/Can\'t open syslog for ident \".*\" and facility \".*\": .* /");
|
||||
|
||||
$logger = new SyslogLoggerWrapper('test', $this->introspection, LogLevel::DEBUG, null, 'a string');
|
||||
$logger->emergency('not working');
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ class SyslogLoggerWrapper extends SyslogLogger
|
|||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @noinspection PhpMissingParentCallCommonInspection
|
||||
*/
|
||||
protected function syslogWrapper($level, $entry)
|
||||
{
|
||||
|
|
|
@ -34,10 +34,12 @@ class WorkerLoggerTest extends MockedTest
|
|||
|
||||
/**
|
||||
* Test the a id with length zero
|
||||
* @expectedException \Error
|
||||
*
|
||||
*/
|
||||
public function testGetWorkerIdZero()
|
||||
{
|
||||
$this->expectException(\Error::class);
|
||||
|
||||
$logger = \Mockery::mock(LoggerInterface::class);
|
||||
new WorkerLogger($logger, 'test', 0);
|
||||
}
|
||||
|
|
|
@ -53,6 +53,8 @@ class ProfilerTest extends MockedTest
|
|||
->andReturn(true)
|
||||
->twice();
|
||||
$profiler = new Profiler($configCache);
|
||||
|
||||
self::assertInstanceOf(Profiler::class, $profiler);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,7 +143,7 @@ class ProfilerTest extends MockedTest
|
|||
* Test the Profiler reset
|
||||
* @dataProvider dataPerformance
|
||||
*/
|
||||
public function testReset($timestamp, $name, array $functions)
|
||||
public function testReset($timestamp, $name)
|
||||
{
|
||||
$configCache = \Mockery::mock(Cache::class);
|
||||
$configCache->shouldReceive('get')
|
||||
|
|
|
@ -130,7 +130,7 @@ class StringsTest extends TestCase
|
|||
*
|
||||
* @dataProvider dataIsHex
|
||||
*/
|
||||
public function testIsHex($input, $valid)
|
||||
public function testIsHex(string $input, bool $valid)
|
||||
{
|
||||
self::assertEquals($valid, Strings::isHex($input));
|
||||
}
|
||||
|
|
|
@ -34,9 +34,9 @@ class XmlTest extends TestCase
|
|||
*/
|
||||
public function testEscapeUnescape()
|
||||
{
|
||||
$text="<tag>I want to break\n this!11!<?hard?></tag>";
|
||||
$xml=XML::escape($text);
|
||||
$retext=XML::unescape($text);
|
||||
$text = "<tag>I want to break\n this!11!<?hard?></tag>";
|
||||
$xml = XML::escape($text);
|
||||
$retext = XML::unescape($text);
|
||||
self::assertEquals($text, $retext);
|
||||
}
|
||||
|
||||
|
@ -45,20 +45,20 @@ class XmlTest extends TestCase
|
|||
*/
|
||||
public function testEscapeDocument()
|
||||
{
|
||||
$tag="<tag>I want to break</tag>";
|
||||
$xml=XML::escape($tag);
|
||||
$text='<text>'.$xml.'</text>';
|
||||
$xml_parser=xml_parser_create();
|
||||
$tag = "<tag>I want to break</tag>";
|
||||
$xml = XML::escape($tag);
|
||||
$text = '<text>' . $xml . '</text>';
|
||||
$xml_parser = xml_parser_create();
|
||||
//should be possible to parse it
|
||||
$values=array();
|
||||
$index=array();
|
||||
$values = [];
|
||||
$index = [];
|
||||
self::assertEquals(1, xml_parse_into_struct($xml_parser, $text, $values, $index));
|
||||
self::assertEquals(
|
||||
array('TEXT'=>array(0)),
|
||||
['TEXT' => [0]],
|
||||
$index
|
||||
);
|
||||
self::assertEquals(
|
||||
array(array('tag'=>'TEXT', 'type'=>'complete', 'level'=>1, 'value'=>$tag)),
|
||||
[['tag' => 'TEXT', 'type' => 'complete', 'level' => 1, 'value' => $tag]],
|
||||
$values
|
||||
);
|
||||
xml_parser_free($xml_parser);
|
||||
|
|
Loading…
Reference in New Issue
Block a user