diff --git a/src/Database/Database.php b/src/Database/Database.php index c2dd3c84c7..e380878f88 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -58,6 +58,7 @@ class Database protected $connection; protected $driver; protected $emulate_prepares = false; + protected $pdo_emulate_prepares = false; private $error = false; private $errorno = 0; private $affected_rows = 0; diff --git a/tests/Util/AppMockTrait.php b/tests/Util/AppMockTrait.php index 59e1b3f556..c6f07897c6 100644 --- a/tests/Util/AppMockTrait.php +++ b/tests/Util/AppMockTrait.php @@ -25,6 +25,7 @@ use Dice\Dice; use Friendica\App; use Friendica\Core\Config; use Friendica\DI; +use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Render\FriendicaSmartyEngine; use Friendica\Util\Profiler; use Mockery\MockInterface; @@ -64,7 +65,9 @@ trait AppMockTrait * Mock the App * * @param vfsStreamDirectory $root The root directory - * @param bool $raw If true, no config mocking will be done + * @param bool $raw If true, no config mocking will be done + * + * @throws InternalServerErrorException */ public function mockApp(vfsStreamDirectory $root, $raw = false) { diff --git a/tests/Util/DBAMockTrait.php b/tests/Util/DBAMockTrait.php index 932cceea88..f15157e81b 100644 --- a/tests/Util/DBAMockTrait.php +++ b/tests/Util/DBAMockTrait.php @@ -81,11 +81,11 @@ trait DBAMockTrait /** * Mocking DBA::fetchFirst() * - * @param string $arg The argument of fetchFirst - * @param bool $return True, if the DB is connected, otherwise false - * @param null|int $times How often the method will get used + * @param string $arg The argument of fetchFirst + * @param bool $return True, if the DB is connected, otherwise false + * @param null|int $times How often the method will get used */ - public function mockFetchFirst($arg, $return = true, $times = null) + public function mockFetchFirst(string $arg, bool $return = true, int $times = null) { $this->checkMock(); @@ -139,13 +139,13 @@ trait DBAMockTrait /** * Mocking DBA::select() * - * @param string $tableName The name of the table - * @param array $select The Select Array (Default is []) - * @param array $where The Where Array (Default is []) - * @param object $return The array to return (Default is []) - * @param null|int $times How often the method will get used + * @param string $tableName The name of the table + * @param array $select The Select Array (Default is []) + * @param array $where The Where Array (Default is []) + * @param object $return The array to return (Default is []) + * @param null|int $times How often the method will get used */ - public function mockSelect($tableName, $select = [], $where = [], $return = null, $times = null) + public function mockSelect(string $tableName, array $select = [], array $where = [], $return = null, int $times = null) { $this->checkMock(); @@ -159,12 +159,12 @@ trait DBAMockTrait /** * Mocking DBA::delete() * - * @param string $tableName The name of the table - * @param array $where The Where Array (Default is []) - * @param bool $return The array to return (Default is true) - * @param null|int $times How often the method will get used + * @param string $tableName The name of the table + * @param array $where The Where Array (Default is []) + * @param bool $return The array to return (Default is true) + * @param null|int $times How often the method will get used */ - public function mockDBADelete($tableName, $where = [], $return = true, $times = null) + public function mockDBADelete(string $tableName, array $where = [], bool $return = true, int $times = null) { $this->checkMock(); @@ -178,14 +178,14 @@ trait DBAMockTrait /** * Mocking DBA::update() * - * @param string $expTableName The name of the table - * @param array $expFields The Fields Array - * @param array $expCondition The Condition Array - * @param array $expOld_fields The Old Fieldnames (Default is []) - * @param bool $return true if the update was successful - * @param null|int $times How often the method will get used + * @param string $expTableName The name of the table + * @param array $expFields The Fields Array + * @param array $expCondition The Condition Array + * @param array $expOld_fields The Old Fieldnames (Default is []) + * @param bool $return true if the update was successful + * @param null|int $times How often the method will get used */ - public function mockDBAUpdate($expTableName, $expFields, $expCondition, $expOld_fields = [], $return = true, $times = null) + public function mockDBAUpdate(string $expTableName, array $expFields, array $expCondition, array $expOld_fields = [], bool $return = true, int $times = null) { $this->checkMock(); @@ -207,13 +207,13 @@ trait DBAMockTrait /** * Mocking DBA::insert() * - * @param string $expTableName The name of the table - * @param array $expParam The Parameters Array - * @param bool $expOnDuplUpdate Update on a duplicated entry - * @param bool $return True if the insert was successful - * @param null|int $times How often the method will get used + * @param string $expTableName The name of the table + * @param array $expParam The Parameters Array + * @param bool $expOnDuplUpdate Update on a duplicated entry + * @param bool $return True if the insert was successful + * @param null|int $times How often the method will get used */ - public function mockDBAInsert($expTableName, $expParam, $expOnDuplUpdate = false, $return = true, $times = null) + public function mockDBAInsert(string $expTableName, array $expParam, bool $expOnDuplUpdate = false, bool $return = true, int $times = null) { $this->checkMock(); @@ -234,13 +234,13 @@ trait DBAMockTrait /** * Mocking DBA::selectFirst() * - * @param string $expTableName The name of the table - * @param array $expSelect The Select Array (Default is []) - * @param array $expWhere The Where Array (Default is []) - * @param array $return The array to return (Default is []) - * @param null|int $times How often the method will get used + * @param string $expTableName The name of the table + * @param array $expSelect The Select Array (Default is []) + * @param array $expWhere The Where Array (Default is []) + * @param array $return The array to return (Default is []) + * @param null|int $times How often the method will get used */ - public function mockSelectFirst($expTableName, $expSelect = [], $expWhere = [], $return = [], $times = null) + public function mockSelectFirst(string $expTableName, array $expSelect = [], array $expWhere = [], array $return = [], int $times = null) { $this->checkMock(); @@ -321,11 +321,11 @@ trait DBAMockTrait /** * Mocking DBA::lock() * - * @param string $table The table to lock - * @param bool $return True, if the lock is set successful - * @param null|int $times How often the method will get used + * @param string $table The table to lock + * @param bool $return True, if the lock is set successful + * @param null|int $times How often the method will get used */ - public function mockDbaLock($table, $return = true, $times = null) + public function mockDbaLock(string $table, bool $return = true, int $times = null) { $this->checkMock(); diff --git a/tests/Util/DBStructureMockTrait.php b/tests/Util/DBStructureMockTrait.php index 2d47cc85ef..c792643018 100644 --- a/tests/Util/DBStructureMockTrait.php +++ b/tests/Util/DBStructureMockTrait.php @@ -42,7 +42,7 @@ trait DBStructureMockTrait * @param bool $return True, if the connect was successful, otherwise false * @param null|int $times How often the method will get used */ - public function mockUpdate($args = [], $return = true, $times = null) + public function mockUpdate(array $args = [], bool $return = true, int $times = null) { if (!isset($this->dbStructure)) { $this->dbStructure = \Mockery::mock('alias:' . DBStructure::class); @@ -58,11 +58,11 @@ trait DBStructureMockTrait /** * Mocking DBStructure::existsTable() * - * @param string $tableName The name of the table to check - * @param bool $return True, if the connect was successful, otherwise false - * @param null|int $times How often the method will get used + * @param string $tableName The name of the table to check + * @param bool $return True, if the connect was successful, otherwise false + * @param null|int $times How often the method will get used */ - public function mockExistsTable($tableName, $return = true, $times = null) + public function mockExistsTable(string $tableName, bool $return = true, int $times = null) { if (!isset($this->dbStructure)) { $this->dbStructure = \Mockery::mock('alias:' . DBStructure::class); diff --git a/tests/Util/Database/ExtendedPDO.php b/tests/Util/Database/ExtendedPDO.php index 857589d2c5..abd53a4e6c 100644 --- a/tests/Util/Database/ExtendedPDO.php +++ b/tests/Util/Database/ExtendedPDO.php @@ -33,7 +33,7 @@ class ExtendedPDO extends PDO /** * @var array Database drivers that support SAVEPOINT * statements. */ - protected static $_supportedDrivers = array("pgsql", "mysql"); + protected static $_supportedDrivers = ["pgsql", "mysql"]; /** * @var int the current transaction depth diff --git a/tests/Util/Database/StaticDatabase.php b/tests/Util/Database/StaticDatabase.php index 73a142d9a9..c6488fc483 100644 --- a/tests/Util/Database/StaticDatabase.php +++ b/tests/Util/Database/StaticDatabase.php @@ -22,6 +22,7 @@ namespace Friendica\Test\Util\Database; use Friendica\Database\Database; +use Friendica\Database\DatabaseException; use PDO; use PDOException; @@ -80,7 +81,7 @@ class StaticDatabase extends Database /** * Does a commit * - * @return boolean Was the command executed successfully? + * @return bool Was the command executed successfully? */ public function commit() { @@ -96,6 +97,8 @@ class StaticDatabase extends Database * Either through explicit calling or through implicit using the Database * * @param array $server $_SERVER variables + * + * @throws \Exception */ public static function statConnect(array $server) { @@ -119,6 +122,10 @@ class StaticDatabase extends Database $db_data = $server['MYSQL_DATABASE']; } + if (empty($db_host) || empty($db_user) || empty($db_data)) { + throw new DatabaseException('Either one of the following settings are missing: Host, User or Database', 999, 'CONNECT'); + } + $port = 0; $serveraddr = trim($db_host); $serverdata = explode(':', $serveraddr); @@ -128,7 +135,7 @@ class StaticDatabase extends Database } $server = trim($server); $user = trim($db_user); - $pass = trim($db_pw); + $pass = trim($db_pw ?? ''); $db = trim($db_data); if (!(strlen($server) && strlen($user))) { diff --git a/tests/Util/DbaCacheMockTrait.php b/tests/Util/DbaCacheMockTrait.php deleted file mode 100644 index 77f1cd73c6..0000000000 --- a/tests/Util/DbaCacheMockTrait.php +++ /dev/null @@ -1,103 +0,0 @@ -. - * - */ - -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); - } -} diff --git a/tests/Util/DbaLockMockTrait.php b/tests/Util/DbaLockMockTrait.php deleted file mode 100644 index e38770cb2e..0000000000 --- a/tests/Util/DbaLockMockTrait.php +++ /dev/null @@ -1,136 +0,0 @@ -. - * - */ - -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); - } -} diff --git a/tests/Util/EmailerSpy.php b/tests/Util/EmailerSpy.php index effd2ed080..161e0f0db5 100644 --- a/tests/Util/EmailerSpy.php +++ b/tests/Util/EmailerSpy.php @@ -8,6 +8,18 @@ class EmailerSpy extends Emailer { public static $MAIL_DATA; + /** + * Wrapper around the mail() method (mainly used to overwrite for tests) + * @see mail() + * + * @param string $to Recipient of this mail + * @param string $subject Subject of this mail + * @param string $body Message body of this mail + * @param string $headers Headers of this mail + * @param string $parameters Additional (sendmail) parameters of this mail + * + * @return bool true if the mail was successfully accepted for delivery, false otherwise. + */ protected function mail(string $to, string $subject, string $body, string $headers, string $parameters) { self::$MAIL_DATA = [ diff --git a/tests/Util/HookMockTrait.php b/tests/Util/HookMockTrait.php index 68a17c5bdb..fbc95aa9af 100644 --- a/tests/Util/HookMockTrait.php +++ b/tests/Util/HookMockTrait.php @@ -16,6 +16,8 @@ trait HookMockTrait /** * Mocking a method 'Hook::call()' call * + * @param string $name + * @param mixed $capture */ public function mockHookCallAll(string $name, &$capture) { diff --git a/tests/Util/Intercept.php b/tests/Util/Intercept.php index f22e98798b..ba4748dc0f 100644 --- a/tests/Util/Intercept.php +++ b/tests/Util/Intercept.php @@ -36,6 +36,7 @@ class Intercept extends php_user_filter */ public static $cache = ''; + /** @noinspection PhpMissingParentCallCommonInspection */ public function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { diff --git a/tests/Util/RendererMockTrait.php b/tests/Util/RendererMockTrait.php index 04a65e3022..f3973ea9be 100644 --- a/tests/Util/RendererMockTrait.php +++ b/tests/Util/RendererMockTrait.php @@ -38,7 +38,7 @@ trait RendererMockTrait * @param string $return the return value of the mock (should be defined to have it later for followUp use) * @param null|int $times How often the method will get used */ - public function mockGetMarkupTemplate($templateName, $return = '', $times = null) + public function mockGetMarkupTemplate(string $templateName, string $return = '', int $times = null) { if (!isset($this->rendererMock)) { $this->rendererMock = \Mockery::mock('alias:' . Renderer::class); @@ -54,12 +54,12 @@ trait RendererMockTrait /** * Mocking the method 'Renderer::replaceMacros()' * - * @param string $template The template to use (normally, it is the mock result of 'mockGetMarkupTemplate()' - * @param array|\Closure|null $args The arguments to pass to the macro - * @param string $return the return value of the mock - * @param null|int $times How often the method will get used + * @param string $template The template to use (normally, it is the mock result of 'mockGetMarkupTemplate()' + * @param array|\Closure|null $args The arguments to pass to the macro + * @param string $return the return value of the mock + * @param null|int $times How often the method will get used */ - public function mockReplaceMacros($template, $args = null, $return = '', $times = null) + public function mockReplaceMacros(string $template, $args = null, string $return = '', int $times = null) { if (!isset($this->rendererMock)) { $this->rendererMock = \Mockery::mock('alias:' . Renderer::class); diff --git a/tests/Util/StaticCookie.php b/tests/Util/StaticCookie.php index 9aeec0b334..6cfbdc3ab7 100644 --- a/tests/Util/StaticCookie.php +++ b/tests/Util/StaticCookie.php @@ -33,6 +33,20 @@ class StaticCookie extends Cookie /** @var int The last expire time set */ public static $_EXPIRE; + /** + * Send a cookie - protected, internal function for test-mocking possibility + * @see Cookie::setCookie() + * + * @link https://php.net/manual/en/function.setcookie.php + * + * @param string $name + * @param string $value [optional] + * @param int $expire [optional] + * @param bool $secure [optional] + * + * @noinspection PhpMissingParentCallCommonInspection + * + */ protected function setCookie(string $name, string $value = null, int $expire = null, bool $secure = null) { self::$_COOKIE[$name] = $value; diff --git a/tests/Util/VFSTrait.php b/tests/Util/VFSTrait.php index 96f385b3ba..7b99806ab2 100644 --- a/tests/Util/VFSTrait.php +++ b/tests/Util/VFSTrait.php @@ -58,9 +58,9 @@ trait VFSTrait * Copying a config file from the file system to the Virtual File System * * @param string $filename The filename of the config file - * @param bool $static True, if the folder `static` instead of `config` should be used + * @param bool $static True, if the folder `static` instead of `config` should be used */ - protected function setConfigFile($filename, bool $static = false) + protected function setConfigFile(string $filename, bool $static = false) { $file = dirname(__DIR__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . @@ -78,9 +78,9 @@ trait VFSTrait * Delets a config file from the Virtual File System * * @param string $filename The filename of the config file - * @param bool $static True, if the folder `static` instead of `config` should be used + * @param bool $static True, if the folder `static` instead of `config` should be used */ - protected function delConfigFile($filename, bool $static = false) + protected function delConfigFile(string $filename, bool $static = false) { if ($this->root->hasChild(($static ? 'static' : 'config') . '/' . $filename)) { $this->root->getChild(($static ? 'static' : 'config'))->removeChild($filename); diff --git a/tests/functional/DependencyCheckTest.php b/tests/functional/DependencyCheckTest.php index 32c0164486..d1c85bdd0e 100644 --- a/tests/functional/DependencyCheckTest.php +++ b/tests/functional/DependencyCheckTest.php @@ -36,7 +36,7 @@ use Friendica\Util\Profiler; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; -class dependencyCheck extends TestCase +class DependencyCheckTest extends TestCase { use VFSTrait; diff --git a/tests/src/App/ModeTest.php b/tests/src/App/ModeTest.php index 9179bfddce..0a374fd63e 100644 --- a/tests/src/App/ModeTest.php +++ b/tests/src/App/ModeTest.php @@ -24,12 +24,13 @@ namespace Friendica\Test\src\App; use Detection\MobileDetect; use Friendica\App\Mode; use Friendica\App\Module; -use Friendica\Core\Config; +use Friendica\Core\Config\Cache; use Friendica\Database\Database; use Friendica\Test\MockedTest; use Friendica\Test\Util\DBAMockTrait; use Friendica\Test\Util\VFSTrait; use Friendica\Util\BasePath; +use Mockery; use Mockery\MockInterface; class ModeTest extends MockedTest @@ -48,19 +49,19 @@ class ModeTest extends MockedTest private $databaseMock; /** - * @var \Friendica\Core\Config\Cache|MockInterface + * @var Cache|MockInterface */ private $configCacheMock; - public function setUp() + protected function setUp() { parent::setUp(); $this->setUpVfsDir(); - $this->basePathMock = \Mockery::mock(BasePath::class); - $this->databaseMock = \Mockery::mock(Database::class); - $this->configCacheMock = \Mockery::mock(Config\Cache::class); + $this->basePathMock = Mockery::mock(BasePath::class); + $this->databaseMock = Mockery::mock(Database::class); + $this->configCacheMock = Mockery::mock(Cache::class); } public function testItEmpty() @@ -280,7 +281,7 @@ class ModeTest extends MockedTest { $server = []; $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, [], false); - $mobileDetect = \Mockery::mock(MobileDetect::class); + $mobileDetect = Mockery::mock(MobileDetect::class); $mobileDetect->shouldReceive('isMobile')->andReturn(true); $mobileDetect->shouldReceive('isTablet')->andReturn(true); @@ -298,7 +299,7 @@ class ModeTest extends MockedTest { $server = []; $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, [], false); - $mobileDetect = \Mockery::mock(MobileDetect::class); + $mobileDetect = Mockery::mock(MobileDetect::class); $mobileDetect->shouldReceive('isMobile')->andReturn(false); $mobileDetect->shouldReceive('isTablet')->andReturn(false); diff --git a/tests/src/App/ModuleTest.php b/tests/src/App/ModuleTest.php index a24608eb02..5f3f14c521 100644 --- a/tests/src/App/ModuleTest.php +++ b/tests/src/App/ModuleTest.php @@ -29,6 +29,7 @@ use Friendica\LegacyModule; use Friendica\Module\HTTPException\PageNotFound; use Friendica\Module\WellKnown\HostMeta; use Friendica\Test\DatabaseTest; +use Mockery; class ModuleTest extends DatabaseTest { @@ -170,13 +171,13 @@ class ModuleTest extends DatabaseTest */ public function testModuleClass($assert, string $name, string $command, bool $privAdd) { - $config = \Mockery::mock(IConfig::class); + $config = Mockery::mock(IConfig::class); $config->shouldReceive('get')->with('config', 'private_addons', false)->andReturn($privAdd)->atMost()->once(); - $l10n = \Mockery::mock(L10n::class); + $l10n = Mockery::mock(L10n::class); $l10n->shouldReceive('t')->andReturnUsing(function ($args) { return $args; }); - $cache = \Mockery::mock(ICache::class); + $cache = Mockery::mock(ICache::class); $cache->shouldReceive('get')->with('routerDispatchData')->andReturn('')->atMost()->once(); $cache->shouldReceive('get')->with('lastRoutesFileModifiedTime')->andReturn('')->atMost()->once(); $cache->shouldReceive('set')->withAnyArgs()->andReturn(false)->atMost()->twice(); diff --git a/tests/src/App/RouterTest.php b/tests/src/App/RouterTest.php index 6846f74ff7..5edf3e2574 100644 --- a/tests/src/App/RouterTest.php +++ b/tests/src/App/RouterTest.php @@ -27,6 +27,7 @@ use Friendica\Core\L10n; use Friendica\Module; use Friendica\Network\HTTPException\MethodNotAllowedException; use Friendica\Network\HTTPException\NotFoundException; +use Mockery; use Mockery\MockInterface; use PHPUnit\Framework\TestCase; @@ -43,10 +44,10 @@ class RouterTest extends TestCase { parent::setUp(); - $this->l10n = \Mockery::mock(L10n::class); + $this->l10n = Mockery::mock(L10n::class); $this->l10n->shouldReceive('t')->andReturnUsing(function ($args) { return $args; }); - $this->cache = \Mockery::mock(ICache::class); + $this->cache = Mockery::mock(ICache::class); $this->cache->shouldReceive('get')->andReturn(null); $this->cache->shouldReceive('set')->andReturn(false); } diff --git a/tests/src/Console/AutomaticInstallationConsoleTest.php b/tests/src/Console/AutomaticInstallationConsoleTest.php index b0481be98c..751cc0b988 100644 --- a/tests/src/Console/AutomaticInstallationConsoleTest.php +++ b/tests/src/Console/AutomaticInstallationConsoleTest.php @@ -35,6 +35,7 @@ use Friendica\Test\Util\DBStructureMockTrait; use Friendica\Test\Util\RendererMockTrait; use Friendica\Test\Util\VFSTrait; use Friendica\Util\Logger\VoidLogger; +use Mockery; use Mockery\MockInterface; use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStreamFile; @@ -77,7 +78,7 @@ class AutomaticInstallationConsoleTest extends ConsoleTest public function setUp() { - $this->markTestSkipped('Needs class \'Installer\' as constructing argument for console tests'); + static::markTestSkipped('Needs class \'Installer\' as constructing argument for console tests'); parent::setUp(); @@ -87,9 +88,9 @@ class AutomaticInstallationConsoleTest extends ConsoleTest $this->root->getChild('config') ->removeChild('local.config.php'); } - $this->dice = \Mockery::mock(Dice::class)->makePartial(); + $this->dice = Mockery::mock(Dice::class)->makePartial(); - $l10nMock = \Mockery::mock(L10n::class); + $l10nMock = Mockery::mock(L10n::class); $l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; }); $this->dice->shouldReceive('create') @@ -400,7 +401,7 @@ FIN; $this->mockUpdate([$this->root->url(), false, true, true], null, 1); $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); - $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1); + $this->mockReplaceMacros('testTemplate', Mockery::any(), '', 1); $console = new AutomaticInstallation($this->consoleArgv); $console->setOption('url', 'http://friendica.local'); @@ -502,7 +503,7 @@ CONF; $this->mockUpdate([$this->root->url(), false, true, true], null, 1); $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); - $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1); + $this->mockReplaceMacros('testTemplate', Mockery::any(), '', 1); self::assertTrue(putenv('MYSQL_HOST=' . $data['database']['hostname'])); self::assertTrue(putenv('MYSQL_PORT=' . $data['database']['port'])); @@ -540,7 +541,7 @@ CONF; $this->mockUpdate([$this->root->url(), false, true, true], null, 1); $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); - $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1); + $this->mockReplaceMacros('testTemplate', Mockery::any(), '', 1); self::assertTrue(putenv('MYSQL_HOST=' . $data['database']['hostname'])); self::assertTrue(putenv('MYSQL_PORT=' . $data['database']['port'])); @@ -576,7 +577,7 @@ CONF; $this->mockUpdate([$this->root->url(), false, true, true], null, 1); $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); - $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1); + $this->mockReplaceMacros('testTemplate', Mockery::any(), '', 1); $console = new AutomaticInstallation($this->consoleArgv); @@ -611,7 +612,7 @@ CONF; $this->mockConnect(false, 1); $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); - $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1); + $this->mockReplaceMacros('testTemplate', Mockery::any(), '', 1); $console = new AutomaticInstallation($this->consoleArgv); $console->setOption('url', 'http://friendica.local'); diff --git a/tests/src/Console/ConfigConsoleTest.php b/tests/src/Console/ConfigConsoleTest.php index 837d234b83..51bf04d59a 100644 --- a/tests/src/Console/ConfigConsoleTest.php +++ b/tests/src/Console/ConfigConsoleTest.php @@ -25,6 +25,8 @@ use Friendica\App; use Friendica\App\Mode; use Friendica\Console\Config; use Friendica\Core\Config\IConfig; +use Mockery; +use Mockery\LegacyMockInterface; use Mockery\MockInterface; class ConfigConsoleTest extends ConsoleTest @@ -33,27 +35,27 @@ class ConfigConsoleTest extends ConsoleTest * @var App\Mode|MockInterface $appMode */ private $appMode; - /** @var IConfig|\Mockery\LegacyMockInterface|MockInterface */ + /** @var IConfig|LegacyMockInterface|MockInterface */ private $configMock; protected function setUp() { parent::setUp(); - \Mockery::getConfiguration()->setConstantsMap([ + Mockery::getConfiguration()->setConstantsMap([ Mode::class => [ - 'DBCONFIGAVAILABLE' => 0 - ] + 'DBCONFIGAVAILABLE' => 0, + ], ]); - $this->appMode = \Mockery::mock(App\Mode::class); + $this->appMode = Mockery::mock(App\Mode::class); $this->appMode->shouldReceive('has') - ->andReturn(true); + ->andReturn(true); - $this->configMock = \Mockery::mock(IConfig::class); + $this->configMock = Mockery::mock(IConfig::class); } - function testSetGetKeyValue() + public function testSetGetKeyValue() { $this->configMock ->shouldReceive('set') @@ -98,7 +100,8 @@ class ConfigConsoleTest extends ConsoleTest self::assertEquals("config.test => \n", $txt); } - function testSetArrayValue() { + public function testSetArrayValue() + { $testArray = [1, 2, 3]; $this->configMock ->shouldReceive('get') @@ -115,19 +118,21 @@ class ConfigConsoleTest extends ConsoleTest self::assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt); } - function testTooManyArguments() { + public function testTooManyArguments() + { $console = new Config($this->appMode, $this->configMock, $this->consoleArgv); $console->setArgument(0, 'config'); $console->setArgument(1, 'test'); $console->setArgument(2, 'it'); $console->setArgument(3, 'now'); - $txt = $this->dumpExecute($console); + $txt = $this->dumpExecute($console); $assertion = '[Warning] Too many arguments'; $firstline = substr($txt, 0, strlen($assertion)); self::assertEquals($assertion, $firstline); } - function testVerbose() { + public function testVerbose() + { $this->configMock ->shouldReceive('get') ->with('test', 'it') @@ -138,7 +143,7 @@ class ConfigConsoleTest extends ConsoleTest $console->setArgument(1, 'it'); $console->setOption('v', 1); $executable = $this->consoleArgv[0]; - $assertion = << now CONF; - $txt = $this->dumpExecute($console); + $txt = $this->dumpExecute($console); self::assertEquals($assertion, $txt); } - function testUnableToSet() { + public function testUnableToSet() + { $this->configMock ->shouldReceive('set') ->with('test', 'it', 'now') @@ -164,7 +170,7 @@ CONF; $this->configMock ->shouldReceive('get') ->with('test', 'it') - ->andReturn(NULL) + ->andReturn(null) ->once(); $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]); $console->setArgument(0, 'test'); diff --git a/tests/src/Console/ConsoleTest.php b/tests/src/Console/ConsoleTest.php index 724163d6ff..7f2f13c739 100644 --- a/tests/src/Console/ConsoleTest.php +++ b/tests/src/Console/ConsoleTest.php @@ -46,7 +46,7 @@ abstract class ConsoleTest extends MockedTest * * @return string the output of the execution */ - protected function dumpExecute($console) + protected function dumpExecute(Console $console) { Intercept::reset(); $console->execute(); diff --git a/tests/src/Console/LockConsoleTest.php b/tests/src/Console/LockConsoleTest.php index e06ee3a4ca..04ac54b3e3 100644 --- a/tests/src/Console/LockConsoleTest.php +++ b/tests/src/Console/LockConsoleTest.php @@ -25,6 +25,7 @@ use Friendica\App; use Friendica\App\Mode; use Friendica\Console\Lock; use Friendica\Core\Lock\ILock; +use Mockery; use Mockery\MockInterface; class LockConsoleTest extends ConsoleTest @@ -43,17 +44,17 @@ class LockConsoleTest extends ConsoleTest { parent::setUp(); - \Mockery::getConfiguration()->setConstantsMap([ + Mockery::getConfiguration()->setConstantsMap([ Mode::class => [ 'DBCONFIGAVAILABLE' => 0 ] ]); - $this->appMode = \Mockery::mock(App\Mode::class); + $this->appMode = Mockery::mock(App\Mode::class); $this->appMode->shouldReceive('has') ->andReturn(true); - $this->lockMock = \Mockery::mock(ILock::class); + $this->lockMock = Mockery::mock(ILock::class); } public function testList() diff --git a/tests/src/Console/ServerBlockConsoleTest.php b/tests/src/Console/ServerBlockConsoleTest.php index 8efa8a4a76..cb595f9912 100644 --- a/tests/src/Console/ServerBlockConsoleTest.php +++ b/tests/src/Console/ServerBlockConsoleTest.php @@ -23,6 +23,7 @@ namespace Friendica\Test\src\Console; use Friendica\Console\ServerBlock; use Friendica\Core\Config\IConfig; +use Mockery; class ServerBlockConsoleTest extends ConsoleTest { @@ -36,12 +37,16 @@ class ServerBlockConsoleTest extends ConsoleTest 'reason' => 'Illegal content', ] ]; + /** + * @var IConfig|Mockery\LegacyMockInterface|Mockery\MockInterface + */ + private $configMock; protected function setUp() { parent::setUp(); - $this->configMock = \Mockery::mock(IConfig::class); + $this->configMock = Mockery::mock(IConfig::class); } /** diff --git a/tests/src/Content/ItemTest.php b/tests/src/Content/ItemTest.php index 102e594270..7d8c229301 100644 --- a/tests/src/Content/ItemTest.php +++ b/tests/src/Content/ItemTest.php @@ -27,6 +27,6 @@ class ItemTest extends MockedTest { public function testDetermineCategoriesTerms() { - $this->markTestIncomplete('Test data needed.'); + static::markTestIncomplete('Test data needed.'); } } diff --git a/tests/src/Content/PageInfoMock.php b/tests/src/Content/PageInfoMock.php index d2a5fcff48..99e2da399b 100644 --- a/tests/src/Content/PageInfoMock.php +++ b/tests/src/Content/PageInfoMock.php @@ -21,6 +21,8 @@ namespace Friendica\Test\src\Content; +use Friendica\Content\PageInfo; + /** * Class PageInfoMock * @@ -29,7 +31,7 @@ namespace Friendica\Test\src\Content; * @method static string|null getRelevantUrlFromBody(string $body, $searchNakedUrls = false) * @method static string stripTrailingUrlFromBody(string $body, string $url) */ -class PageInfoMock extends \Friendica\Content\PageInfo +class PageInfoMock extends PageInfo { public static function __callStatic($name, $arguments) { diff --git a/tests/src/Content/SmiliesTest.php b/tests/src/Content/SmiliesTest.php index 27bdead3c1..a3633cea53 100644 --- a/tests/src/Content/SmiliesTest.php +++ b/tests/src/Content/SmiliesTest.php @@ -9,6 +9,7 @@ namespace Friendica\Test\src\Content; use Friendica\Content\Smilies; +use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Test\MockedTest; use Friendica\Test\Util\AppMockTrait; use Friendica\Test\Util\VFSTrait; @@ -52,14 +53,16 @@ class SmiliesTest extends MockedTest /** * Test replace smilies in different texts + * * @dataProvider dataLinks * * @param string $text Test string * @param array $smilies List of smilies to replace * @param string $expected Expected result - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * + * @throws InternalServerErrorException */ - public function testReplaceFromArray($text, $smilies, $expected) + public function testReplaceFromArray(string $text, array $smilies, string $expected) { $output = Smilies::replaceFromArray($text, $smilies); self::assertEquals($expected, $output); diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 17c2bca19b..1a1e05f454 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -24,9 +24,11 @@ namespace Friendica\Test\src\Content\Text; use Friendica\App\BaseURL; use Friendica\Content\Text\BBCode; use Friendica\Core\L10n; +use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Test\MockedTest; use Friendica\Test\Util\AppMockTrait; use Friendica\Test\Util\VFSTrait; +use Mockery; class BBCodeTest extends MockedTest { @@ -62,13 +64,13 @@ class BBCodeTest extends MockedTest ->with('system', 'big_emojis') ->andReturn(false); - $l10nMock = \Mockery::mock(L10n::class); + $l10nMock = Mockery::mock(L10n::class); $l10nMock->shouldReceive('t')->withAnyArgs()->andReturnUsing(function ($args) { return $args; }); $this->dice->shouldReceive('create') ->with(L10n::class) ->andReturn($l10nMock); - $baseUrlMock = \Mockery::mock(BaseURL::class); + $baseUrlMock = Mockery::mock(BaseURL::class); $baseUrlMock->shouldReceive('get')->withAnyArgs()->andReturn('friendica.local'); $this->dice->shouldReceive('create') ->with(BaseURL::class) @@ -158,13 +160,15 @@ class BBCodeTest extends MockedTest /** * Test convert different links inside a text + * * @dataProvider dataLinks * - * @param string $data The data to text - * @param bool $assertHTML True, if the link is a HTML link (...) - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @param string $data The data to text + * @param bool $assertHTML True, if the link is a HTML link (...) + * + * @throws InternalServerErrorException */ - public function testAutoLinking($data, $assertHTML) + public function testAutoLinking(string $data, bool $assertHTML) { $output = BBCode::convert($data); $assert = '' . $data . ''; @@ -258,9 +262,10 @@ class BBCodeTest extends MockedTest * @param bool $try_oembed Whether to convert multimedia BBCode tag * @param int $simpleHtml BBCode::convert method $simple_html parameter value, optional. * @param bool $forPlaintext BBCode::convert method $for_plaintext parameter value, optional. - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * + * @throws InternalServerErrorException */ - public function testConvert($expectedHtml, $text, $try_oembed = false, $simpleHtml = 0, $forPlaintext = false) + public function testConvert(string $expectedHtml, string $text, $try_oembed = false, int $simpleHtml = 0, bool $forPlaintext = false) { $actual = BBCode::convert($text, $try_oembed, $simpleHtml, $forPlaintext); @@ -290,12 +295,13 @@ class BBCodeTest extends MockedTest * * @dataProvider dataBBCodesToMarkdown * - * @param string $expected Expected Markdown output - * @param string $text BBCode text + * @param string $expected Expected Markdown output + * @param string $text BBCode text * @param bool $for_diaspora - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * + * @throws InternalServerErrorException */ - public function testToMarkdown($expected, $text, $for_diaspora = false) + public function testToMarkdown(string $expected, string $text, $for_diaspora = false) { $actual = BBCode::toMarkdown($text, $for_diaspora); diff --git a/tests/src/Content/Text/HTMLTest.php b/tests/src/Content/Text/HTMLTest.php index ca313bec57..86315ee092 100644 --- a/tests/src/Content/Text/HTMLTest.php +++ b/tests/src/Content/Text/HTMLTest.php @@ -21,7 +21,9 @@ namespace Friendica\Test\src\Content\Text; +use Exception; use Friendica\Content\Text\HTML; +use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Test\MockedTest; use Friendica\Test\Util\AppMockTrait; use Friendica\Test\Util\VFSTrait; @@ -61,9 +63,10 @@ class HTMLTest extends MockedTest * * @param string $input The Markdown text to test * @param string $expected The expected HTML output - * @throws \Exception + * + * @throws Exception */ - public function testToPlaintext($input, $expected) + public function testToPlaintext(string $input, string $expected) { $output = HTML::toPlaintext($input, 0); @@ -91,9 +94,10 @@ class HTMLTest extends MockedTest * * @param string $expectedBBCode Expected BBCode output * @param string $html HTML text - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * + * @throws InternalServerErrorException */ - public function testToBBCode($expectedBBCode, $html) + public function testToBBCode(string $expectedBBCode, string $html) { $actual = HTML::toBBCode($html); diff --git a/tests/src/Content/Text/MarkdownTest.php b/tests/src/Content/Text/MarkdownTest.php index 1f1146af9a..fc0bfb9584 100644 --- a/tests/src/Content/Text/MarkdownTest.php +++ b/tests/src/Content/Text/MarkdownTest.php @@ -21,7 +21,7 @@ namespace Friendica\Test\src\Content\Text; -use Friendica\Content\Text\HTML; +use Exception; use Friendica\Content\Text\Markdown; use Friendica\Test\MockedTest; use Friendica\Test\Util\AppMockTrait; @@ -57,13 +57,15 @@ class MarkdownTest extends MockedTest /** * Test convert different input Markdown text into HTML + * * @dataProvider dataMarkdown * * @param string $input The Markdown text to test * @param string $expected The expected HTML output - * @throws \Exception + * + * @throws Exception */ - public function testConvert($input, $expected) + public function testConvert(string $input, string $expected) { $output = Markdown::convert($input); @@ -87,9 +89,8 @@ class MarkdownTest extends MockedTest * * @param string $expectedBBCode Expected BBCode output * @param string $html Markdown text - * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function testToBBCode($expectedBBCode, $html) + public function testToBBCode(string $expectedBBCode, string $html) { $actual = Markdown::toBBCode($html); diff --git a/tests/src/Core/Cache/APCuCacheTest.php b/tests/src/Core/Cache/APCuCacheTest.php index 695c725d3f..5e49f45f56 100644 --- a/tests/src/Core/Cache/APCuCacheTest.php +++ b/tests/src/Core/Cache/APCuCacheTest.php @@ -31,7 +31,7 @@ class APCuCacheTest extends MemoryCacheTest protected function setUp() { if (!APCuCache::isAvailable()) { - $this->markTestSkipped('APCu is not available'); + static::markTestSkipped('APCu is not available'); } parent::setUp(); @@ -43,7 +43,7 @@ class APCuCacheTest extends MemoryCacheTest return $this->cache; } - public function tearDown() + protected function tearDown() { $this->cache->clear(false); parent::tearDown(); diff --git a/tests/src/Core/Cache/ArrayCacheTest.php b/tests/src/Core/Cache/ArrayCacheTest.php index a0dd87b032..0297a3b13c 100644 --- a/tests/src/Core/Cache/ArrayCacheTest.php +++ b/tests/src/Core/Cache/ArrayCacheTest.php @@ -31,7 +31,7 @@ class ArrayCacheTest extends MemoryCacheTest return $this->cache; } - public function tearDown() + protected function tearDown() { $this->cache->clear(false); parent::tearDown(); diff --git a/tests/src/Core/Cache/CacheTest.php b/tests/src/Core/Cache/CacheTest.php index 3daf1db6f4..731b86c900 100644 --- a/tests/src/Core/Cache/CacheTest.php +++ b/tests/src/Core/Cache/CacheTest.php @@ -21,6 +21,8 @@ namespace Friendica\Test\src\Core\Cache; +use Friendica\Core\Cache\ICache; +use Friendica\Core\Cache\IMemoryCache; use Friendica\Test\MockedTest; use Friendica\Util\PidFile; @@ -32,12 +34,12 @@ abstract class CacheTest extends MockedTest protected $startTime = 1417011228; /** - * @var \Friendica\Core\Cache\ICache + * @var ICache */ protected $instance; /** - * @var \Friendica\Core\Cache\IMemoryCache + * @var IMemoryCache */ protected $cache; @@ -95,7 +97,7 @@ abstract class CacheTest extends MockedTest * @param mixed $value1 a first * @param mixed $value2 a second */ - function testSimple($value1, $value2) + public function testSimple($value1, $value2) { self::assertNull($this->instance->get('value1')); @@ -127,9 +129,8 @@ abstract class CacheTest extends MockedTest * @param mixed $value3 a third * @param mixed $value4 a fourth */ - function testClear($value1, $value2, $value3, $value4) + public function testClear($value1, $value2, $value3, $value4) { - $value = 'ipsum lorum'; $this->instance->set('1_value1', $value1); $this->instance->set('1_value2', $value2); $this->instance->set('2_value1', $value3); @@ -179,9 +180,9 @@ abstract class CacheTest extends MockedTest /** * @medium */ - function testTTL() + public function testTTL() { - $this->markTestSkipped('taking too much time without mocking'); + static::markTestSkipped('taking too much time without mocking'); self::assertNull($this->instance->get('value1')); @@ -198,11 +199,11 @@ abstract class CacheTest extends MockedTest /** * @small * - * @param $data mixed the data to store in the cache + * @param mixed $data the data to store in the cache * * @dataProvider dataTypesInCache */ - function testDifferentTypesInCache($data) + public function testDifferentTypesInCache($data) { $this->instance->set('val', $data); $received = $this->instance->get('val'); diff --git a/tests/src/Core/Cache/DatabaseCacheTest.php b/tests/src/Core/Cache/DatabaseCacheTest.php index f8919a6cfb..c1891b08c1 100644 --- a/tests/src/Core/Cache/DatabaseCacheTest.php +++ b/tests/src/Core/Cache/DatabaseCacheTest.php @@ -28,6 +28,7 @@ use Friendica\Test\Util\Database\StaticDatabase; use Friendica\Test\Util\VFSTrait; use Friendica\Util\ConfigFileLoader; use Friendica\Util\Profiler; +use Mockery; use Psr\Log\NullLogger; class DatabaseCacheTest extends CacheTest @@ -45,7 +46,7 @@ class DatabaseCacheTest extends CacheTest protected function getInstance() { $logger = new NullLogger(); - $profiler = \Mockery::mock(Profiler::class); + $profiler = Mockery::mock(Profiler::class); $profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true); // load real config to avoid mocking every config-entry which is related to the Database class @@ -59,7 +60,7 @@ class DatabaseCacheTest extends CacheTest return $this->cache; } - public function tearDown() + protected function tearDown() { $this->cache->clear(false); parent::tearDown(); diff --git a/tests/src/Core/Cache/MemcacheCacheTest.php b/tests/src/Core/Cache/MemcacheCacheTest.php index 44600d5eed..5d85a06567 100644 --- a/tests/src/Core/Cache/MemcacheCacheTest.php +++ b/tests/src/Core/Cache/MemcacheCacheTest.php @@ -21,8 +21,10 @@ namespace Friendica\Test\src\Core\Cache; +use Exception; use Friendica\Core\Cache\MemcacheCache; use Friendica\Core\Config\IConfig; +use Mockery; /** * @requires extension memcache @@ -32,7 +34,7 @@ class MemcacheCacheTest extends MemoryCacheTest { protected function getInstance() { - $configMock = \Mockery::mock(IConfig::class); + $configMock = Mockery::mock(IConfig::class); $host = $_SERVER['MEMCACHE_HOST'] ?? 'localhost'; $port = $_SERVER['MEMCACHE_PORT'] ?? '11211'; @@ -48,13 +50,13 @@ class MemcacheCacheTest extends MemoryCacheTest try { $this->cache = new MemcacheCache($host, $configMock); - } catch (\Exception $e) { - $this->markTestSkipped('Memcache is not available'); + } catch (Exception $e) { + static::markTestSkipped('Memcache is not available'); } return $this->cache; } - public function tearDown() + protected function tearDown() { $this->cache->clear(false); parent::tearDown(); @@ -67,6 +69,6 @@ class MemcacheCacheTest extends MemoryCacheTest */ public function testGetAllKeys($value1, $value2, $value3) { - $this->markTestIncomplete('Race condition because of too fast getAllKeys() which uses a workaround'); + static::markTestIncomplete('Race condition because of too fast getAllKeys() which uses a workaround'); } } diff --git a/tests/src/Core/Cache/MemcachedCacheTest.php b/tests/src/Core/Cache/MemcachedCacheTest.php index c6ec48a4ba..b02311c0f7 100644 --- a/tests/src/Core/Cache/MemcachedCacheTest.php +++ b/tests/src/Core/Cache/MemcachedCacheTest.php @@ -21,8 +21,10 @@ namespace Friendica\Test\src\Core\Cache; +use Exception; use Friendica\Core\Cache\MemcachedCache; use Friendica\Core\Config\IConfig; +use Mockery; use Psr\Log\NullLogger; /** @@ -33,7 +35,7 @@ class MemcachedCacheTest extends MemoryCacheTest { protected function getInstance() { - $configMock = \Mockery::mock(IConfig::class); + $configMock = Mockery::mock(IConfig::class); $host = $_SERVER['MEMCACHED_HOST'] ?? 'localhost'; $port = $_SERVER['MEMCACHED_PORT'] ?? '11211'; @@ -47,13 +49,13 @@ class MemcachedCacheTest extends MemoryCacheTest try { $this->cache = new MemcachedCache($host, $configMock, $logger); - } catch (\Exception $exception) { - $this->markTestSkipped('Memcached is not available'); + } catch (Exception $exception) { + static::markTestSkipped('Memcached is not available'); } return $this->cache; } - public function tearDown() + protected function tearDown() { $this->cache->clear(false); parent::tearDown(); @@ -66,6 +68,6 @@ class MemcachedCacheTest extends MemoryCacheTest */ public function testGetAllKeys($value1, $value2, $value3) { - $this->markTestIncomplete('Race condition because of too fast getAllKeys() which uses a workaround'); + static::markTestIncomplete('Race condition because of too fast getAllKeys() which uses a workaround'); } } diff --git a/tests/src/Core/Cache/MemoryCacheTest.php b/tests/src/Core/Cache/MemoryCacheTest.php index 003db6ad83..9e096320a9 100644 --- a/tests/src/Core/Cache/MemoryCacheTest.php +++ b/tests/src/Core/Cache/MemoryCacheTest.php @@ -21,12 +21,13 @@ namespace Friendica\Test\src\Core\Cache; +use Exception; use Friendica\Core\Cache\IMemoryCache; abstract class MemoryCacheTest extends CacheTest { /** - * @var \Friendica\Core\Cache\IMemoryCache + * @var IMemoryCache */ protected $instance; @@ -35,7 +36,7 @@ abstract class MemoryCacheTest extends CacheTest parent::setUp(); if (!($this->instance instanceof IMemoryCache)) { - throw new \Exception('MemoryCacheTest unsupported'); + throw new Exception('MemoryCacheTest unsupported'); } } @@ -43,7 +44,7 @@ abstract class MemoryCacheTest extends CacheTest * @small * @dataProvider dataSimple */ - function testCompareSet($value1, $value2) + public function testCompareSet($value1, $value2) { self::assertNull($this->instance->get('value1')); @@ -60,7 +61,7 @@ abstract class MemoryCacheTest extends CacheTest * @small * @dataProvider dataSimple */ - function testNegativeCompareSet($value1, $value2) + public function testNegativeCompareSet($value1, $value2) { self::assertNull($this->instance->get('value1')); @@ -78,7 +79,7 @@ abstract class MemoryCacheTest extends CacheTest * @small * @dataProvider dataSimple */ - function testCompareDelete($data) + public function testCompareDelete($data) { self::assertNull($this->instance->get('value1')); @@ -93,7 +94,7 @@ abstract class MemoryCacheTest extends CacheTest * @small * @dataProvider dataSimple */ - function testNegativeCompareDelete($data) + public function testNegativeCompareDelete($data) { self::assertNull($this->instance->get('value1')); @@ -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')); diff --git a/tests/src/Core/Cache/RedisCacheTest.php b/tests/src/Core/Cache/RedisCacheTest.php index 543137ca09..9d8d02decd 100644 --- a/tests/src/Core/Cache/RedisCacheTest.php +++ b/tests/src/Core/Cache/RedisCacheTest.php @@ -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(); diff --git a/tests/src/Core/Config/CacheTest.php b/tests/src/Core/Config/CacheTest.php index 383046b042..0cc54360f1 100644 --- a/tests/src/Core/Config/CacheTest.php +++ b/tests/src/Core/Config/CacheTest.php @@ -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' => '', ] ]); diff --git a/tests/src/Core/Config/ConfigTest.php b/tests/src/Core/Config/ConfigTest.php index 59ad3b9690..ca0d4b37b8 100644 --- a/tests/src/Core/Config/ConfigTest.php +++ b/tests/src/Core/Config/ConfigTest.php @@ -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()); diff --git a/tests/src/Core/Config/JitConfigTest.php b/tests/src/Core/Config/JitConfigTest.php index df0ea4f308..204e87ec79 100644 --- a/tests/src/Core/Config/JitConfigTest.php +++ b/tests/src/Core/Config/JitConfigTest.php @@ -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) { diff --git a/tests/src/Core/Config/PreloadConfigTest.php b/tests/src/Core/Config/PreloadConfigTest.php index 386f093023..0dbf6787b1 100644 --- a/tests/src/Core/Config/PreloadConfigTest.php +++ b/tests/src/Core/Config/PreloadConfigTest.php @@ -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) { diff --git a/tests/src/Core/InstallerTest.php b/tests/src/Core/InstallerTest.php index 68af5ff37f..0933d9e1a5 100644 --- a/tests/src/Core/InstallerTest.php +++ b/tests/src/Core/InstallerTest.php @@ -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'])) { diff --git a/tests/src/Core/Lock/APCuCacheLockTest.php b/tests/src/Core/Lock/APCuCacheLockTest.php index 8448659565..052636591c 100644 --- a/tests/src/Core/Lock/APCuCacheLockTest.php +++ b/tests/src/Core/Lock/APCuCacheLockTest.php @@ -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(); diff --git a/tests/src/Core/Lock/DatabaseLockDriverTest.php b/tests/src/Core/Lock/DatabaseLockDriverTest.php index 5f3ef13c12..821b0874d7 100644 --- a/tests/src/Core/Lock/DatabaseLockDriverTest.php +++ b/tests/src/Core/Lock/DatabaseLockDriverTest.php @@ -28,6 +28,7 @@ use Friendica\Test\Util\Database\StaticDatabase; use Friendica\Test\Util\VFSTrait; use Friendica\Util\ConfigFileLoader; use Friendica\Util\Profiler; +use Mockery; use Psr\Log\NullLogger; class 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 diff --git a/tests/src/Core/Lock/LockTest.php b/tests/src/Core/Lock/LockTest.php index ea668d83bb..2c0445c016 100644 --- a/tests/src/Core/Lock/LockTest.php +++ b/tests/src/Core/Lock/LockTest.php @@ -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')); diff --git a/tests/src/Core/Lock/MemcacheCacheLockTest.php b/tests/src/Core/Lock/MemcacheCacheLockTest.php index f4aab0602c..b5ee717d2c 100644 --- a/tests/src/Core/Lock/MemcacheCacheLockTest.php +++ b/tests/src/Core/Lock/MemcacheCacheLockTest.php @@ -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'); } } diff --git a/tests/src/Core/Lock/MemcachedCacheLockTest.php b/tests/src/Core/Lock/MemcachedCacheLockTest.php index f41bf99205..55350302d4 100644 --- a/tests/src/Core/Lock/MemcachedCacheLockTest.php +++ b/tests/src/Core/Lock/MemcachedCacheLockTest.php @@ -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'); } } diff --git a/tests/src/Core/Lock/RedisCacheLockTest.php b/tests/src/Core/Lock/RedisCacheLockTest.php index 62b15bc7c7..b531a5dfe7 100644 --- a/tests/src/Core/Lock/RedisCacheLockTest.php +++ b/tests/src/Core/Lock/RedisCacheLockTest.php @@ -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; diff --git a/tests/src/Core/Lock/SemaphoreLockTest.php b/tests/src/Core/Lock/SemaphoreLockTest.php index fd60f32c71..ce11ca5314 100644 --- a/tests/src/Core/Lock/SemaphoreLockTest.php +++ b/tests/src/Core/Lock/SemaphoreLockTest.php @@ -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() diff --git a/tests/src/Core/PConfig/CacheTest.php b/tests/src/Core/PConfig/CacheTest.php index bc5aa6934f..da76ab4d9d 100644 --- a/tests/src/Core/PConfig/CacheTest.php +++ b/tests/src/Core/PConfig/CacheTest.php @@ -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(); diff --git a/tests/src/Core/PConfig/JitPConfigTest.php b/tests/src/Core/PConfig/JitPConfigTest.php index b8df468298..6dfe1403ae 100644 --- a/tests/src/Core/PConfig/JitPConfigTest.php +++ b/tests/src/Core/PConfig/JitPConfigTest.php @@ -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 { diff --git a/tests/src/Core/PConfig/PConfigTest.php b/tests/src/Core/PConfig/PConfigTest.php index 4bc5edb418..f84447fb2f 100644 --- a/tests/src/Core/PConfig/PConfigTest.php +++ b/tests/src/Core/PConfig/PConfigTest.php @@ -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()); diff --git a/tests/src/Core/PConfig/PreloadPConfigTest.php b/tests/src/Core/PConfig/PreloadPConfigTest.php index 413a6c9970..400618e8e4 100644 --- a/tests/src/Core/PConfig/PreloadPConfigTest.php +++ b/tests/src/Core/PConfig/PreloadPConfigTest.php @@ -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 { diff --git a/tests/src/Core/StorageManagerTest.php b/tests/src/Core/StorageManagerTest.php index f061ea0fff..e3fd747e4a 100644 --- a/tests/src/Core/StorageManagerTest.php +++ b/tests/src/Core/StorageManagerTest.php @@ -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); diff --git a/tests/src/Core/SystemTest.php b/tests/src/Core/SystemTest.php index 2235b37574..1d90bc7576 100644 --- a/tests/src/Core/SystemTest.php +++ b/tests/src/Core/SystemTest.php @@ -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'); diff --git a/tests/src/Database/DBATest.php b/tests/src/Database/DBATest.php index 053acbe649..c013dcda83 100644 --- a/tests/src/Database/DBATest.php +++ b/tests/src/Database/DBATest.php @@ -10,7 +10,7 @@ use Friendica\Test\Util\Database\StaticDatabase; class DBATest extends DatabaseTest { - public function setUp() + protected function setUp() { parent::setUp(); diff --git a/tests/src/Database/DBStructureTest.php b/tests/src/Database/DBStructureTest.php index ee1fb04f87..1987f10c31 100644 --- a/tests/src/Database/DBStructureTest.php +++ b/tests/src/Database/DBStructureTest.php @@ -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'; diff --git a/tests/src/Model/ProcessTest.php b/tests/src/Model/ProcessTest.php index 490cd34c7a..fb02f62ff1 100644 --- a/tests/src/Model/ProcessTest.php +++ b/tests/src/Model/ProcessTest.php @@ -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() diff --git a/tests/src/Model/Storage/FilesystemStorageTest.php b/tests/src/Model/Storage/FilesystemStorageTest.php index 232c0fc4bf..0224e9101f 100644 --- a/tests/src/Model/Storage/FilesystemStorageTest.php +++ b/tests/src/Model/Storage/FilesystemStorageTest.php @@ -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); diff --git a/tests/src/Model/User/CookieTest.php b/tests/src/Model/User/CookieTest.php index e8dba95576..e6e29048d9 100644 --- a/tests/src/Model/User/CookieTest.php +++ b/tests/src/Model/User/CookieTest.php @@ -48,6 +48,8 @@ class CookieTest extends MockedTest protected function tearDown() { StaticCookie::clearStatic(); + + parent::tearDown(); } /** diff --git a/tests/src/Module/Api/Twitter/ContactEndpointMock.php b/tests/src/Module/Api/Twitter/ContactEndpointMock.php index ff88717192..84c6ce68c1 100644 --- a/tests/src/Module/Api/Twitter/ContactEndpointMock.php +++ b/tests/src/Module/Api/Twitter/ContactEndpointMock.php @@ -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) { diff --git a/tests/src/Module/Api/Twitter/ContactEndpointTest.php b/tests/src/Module/Api/Twitter/ContactEndpointTest.php index 677790d63f..d9506a60ec 100644 --- a/tests/src/Module/Api/Twitter/ContactEndpointTest.php +++ b/tests/src/Module/Api/Twitter/ContactEndpointTest.php @@ -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() diff --git a/tests/src/Util/ACLFormaterTest.php b/tests/src/Util/ACLFormaterTest.php index d565d0ba95..609bd5fa5a 100644 --- a/tests/src/Util/ACLFormaterTest.php +++ b/tests/src/Util/ACLFormaterTest.php @@ -21,7 +21,6 @@ namespace Friendica\Test\src\Util; -use Error; use Friendica\Model\Group; use Friendica\Util\ACLFormatter; use PHPUnit\Framework\TestCase; diff --git a/tests/src/Util/BasePathTest.php b/tests/src/Util/BasePathTest.php index 61c740c79c..ffafa5b55a 100644 --- a/tests/src/Util/BasePathTest.php +++ b/tests/src/Util/BasePathTest.php @@ -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(); } diff --git a/tests/src/Util/BaseURLTest.php b/tests/src/Util/BaseURLTest.php index 83410066b0..79f0637e3f 100644 --- a/tests/src/Util/BaseURLTest.php +++ b/tests/src/Util/BaseURLTest.php @@ -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()); } } diff --git a/tests/src/Util/Config/ConfigFileLoaderTest.php b/tests/src/Util/Config/ConfigFileLoaderTest.php index 96e54bea05..43ee8b84a9 100644 --- a/tests/src/Util/Config/ConfigFileLoaderTest.php +++ b/tests/src/Util/Config/ConfigFileLoaderTest.php @@ -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') diff --git a/tests/src/Util/CryptoTest.php b/tests/src/Util/CryptoTest.php index 1a25e17195..67c3b2ba2a 100644 --- a/tests/src/Util/CryptoTest.php +++ b/tests/src/Util/CryptoTest.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()); } } diff --git a/tests/src/Util/EMailerTest.php b/tests/src/Util/EMailerTest.php index 7c3b4b026b..523d3de122 100644 --- a/tests/src/Util/EMailerTest.php +++ b/tests/src/Util/EMailerTest.php @@ -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() diff --git a/tests/src/Util/Emailer/MailBuilderTest.php b/tests/src/Util/Emailer/MailBuilderTest.php index 8287e76090..72f2fcdf04 100644 --- a/tests/src/Util/Emailer/MailBuilderTest.php +++ b/tests/src/Util/Emailer/MailBuilderTest.php @@ -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 diff --git a/tests/src/Util/Emailer/SystemMailBuilderTest.php b/tests/src/Util/Emailer/SystemMailBuilderTest.php index 857369bdff..bab5ab010d 100644 --- a/tests/src/Util/Emailer/SystemMailBuilderTest.php +++ b/tests/src/Util/Emailer/SystemMailBuilderTest.php @@ -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 = []; } /** diff --git a/tests/src/Util/Logger/StreamLoggerTest.php b/tests/src/Util/Logger/StreamLoggerTest.php index 2e2aac2f1b..e17a07ce29 100644 --- a/tests/src/Util/Logger/StreamLoggerTest.php +++ b/tests/src/Util/Logger/StreamLoggerTest.php @@ -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); diff --git a/tests/src/Util/Logger/SyslogLoggerTest.php b/tests/src/Util/Logger/SyslogLoggerTest.php index 5bedaf5dc3..2191b7d20d 100644 --- a/tests/src/Util/Logger/SyslogLoggerTest.php +++ b/tests/src/Util/Logger/SyslogLoggerTest.php @@ -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'); } diff --git a/tests/src/Util/Logger/SyslogLoggerWrapper.php b/tests/src/Util/Logger/SyslogLoggerWrapper.php index 8cc6a77f5f..1cfeb09e77 100644 --- a/tests/src/Util/Logger/SyslogLoggerWrapper.php +++ b/tests/src/Util/Logger/SyslogLoggerWrapper.php @@ -51,6 +51,7 @@ class SyslogLoggerWrapper extends SyslogLogger /** * {@inheritdoc} + * @noinspection PhpMissingParentCallCommonInspection */ protected function syslogWrapper($level, $entry) { diff --git a/tests/src/Util/Logger/WorkerLoggerTest.php b/tests/src/Util/Logger/WorkerLoggerTest.php index b110677de1..4a5db2ea7a 100644 --- a/tests/src/Util/Logger/WorkerLoggerTest.php +++ b/tests/src/Util/Logger/WorkerLoggerTest.php @@ -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); } diff --git a/tests/src/Util/ProfilerTest.php b/tests/src/Util/ProfilerTest.php index 45b29943f5..cc4f2c8760 100644 --- a/tests/src/Util/ProfilerTest.php +++ b/tests/src/Util/ProfilerTest.php @@ -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') diff --git a/tests/src/Util/StringsTest.php b/tests/src/Util/StringsTest.php index 86b55a2fe3..9b22153686 100644 --- a/tests/src/Util/StringsTest.php +++ b/tests/src/Util/StringsTest.php @@ -126,11 +126,11 @@ class StringsTest extends TestCase * Tests if the string is a valid hexadecimal value * * @param string $input - * @param bool $valid + * @param bool $valid * * @dataProvider dataIsHex */ - public function testIsHex($input, $valid) + public function testIsHex(string $input, bool $valid) { self::assertEquals($valid, Strings::isHex($input)); } diff --git a/tests/src/Util/XmlTest.php b/tests/src/Util/XmlTest.php index 99b58a0b87..ed8955a9f0 100644 --- a/tests/src/Util/XmlTest.php +++ b/tests/src/Util/XmlTest.php @@ -29,36 +29,36 @@ use PHPUnit\Framework\TestCase; */ class XmlTest extends TestCase { - /** - * escape and unescape - */ + /** + * escape and unescape + */ public function testEscapeUnescape() { - $text="I want to break\n this!11!"; - $xml=XML::escape($text); - $retext=XML::unescape($text); + $text = "I want to break\n this!11!"; + $xml = XML::escape($text); + $retext = XML::unescape($text); self::assertEquals($text, $retext); - } - + } + /** * escape and put in a document */ public function testEscapeDocument() { - $tag="I want to break"; - $xml=XML::escape($tag); - $text=''.$xml.''; - $xml_parser=xml_parser_create(); + $tag = "I want to break"; + $xml = XML::escape($tag); + $text = '' . $xml . ''; + $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);