]> git.mxchange.org Git - friendica.git/commitdiff
Fix a lot of notices/warnings/deprecation notes in the test directory
authorPhilipp <admin@philipp.info>
Sun, 18 Oct 2020 18:31:57 +0000 (20:31 +0200)
committerPhilipp <admin@philipp.info>
Sun, 18 Oct 2020 18:52:27 +0000 (20:52 +0200)
77 files changed:
src/Database/Database.php
tests/Util/AppMockTrait.php
tests/Util/DBAMockTrait.php
tests/Util/DBStructureMockTrait.php
tests/Util/Database/ExtendedPDO.php
tests/Util/Database/StaticDatabase.php
tests/Util/DbaCacheMockTrait.php [deleted file]
tests/Util/DbaLockMockTrait.php [deleted file]
tests/Util/EmailerSpy.php
tests/Util/HookMockTrait.php
tests/Util/Intercept.php
tests/Util/RendererMockTrait.php
tests/Util/StaticCookie.php
tests/Util/VFSTrait.php
tests/functional/DependencyCheckTest.php
tests/src/App/ModeTest.php
tests/src/App/ModuleTest.php
tests/src/App/RouterTest.php
tests/src/Console/AutomaticInstallationConsoleTest.php
tests/src/Console/ConfigConsoleTest.php
tests/src/Console/ConsoleTest.php
tests/src/Console/LockConsoleTest.php
tests/src/Console/ServerBlockConsoleTest.php
tests/src/Content/ItemTest.php
tests/src/Content/PageInfoMock.php
tests/src/Content/SmiliesTest.php
tests/src/Content/Text/BBCodeTest.php
tests/src/Content/Text/HTMLTest.php
tests/src/Content/Text/MarkdownTest.php
tests/src/Core/Cache/APCuCacheTest.php
tests/src/Core/Cache/ArrayCacheTest.php
tests/src/Core/Cache/CacheTest.php
tests/src/Core/Cache/DatabaseCacheTest.php
tests/src/Core/Cache/MemcacheCacheTest.php
tests/src/Core/Cache/MemcachedCacheTest.php
tests/src/Core/Cache/MemoryCacheTest.php
tests/src/Core/Cache/RedisCacheTest.php
tests/src/Core/Config/CacheTest.php
tests/src/Core/Config/ConfigTest.php
tests/src/Core/Config/JitConfigTest.php
tests/src/Core/Config/PreloadConfigTest.php
tests/src/Core/InstallerTest.php
tests/src/Core/Lock/APCuCacheLockTest.php
tests/src/Core/Lock/DatabaseLockDriverTest.php
tests/src/Core/Lock/LockTest.php
tests/src/Core/Lock/MemcacheCacheLockTest.php
tests/src/Core/Lock/MemcachedCacheLockTest.php
tests/src/Core/Lock/RedisCacheLockTest.php
tests/src/Core/Lock/SemaphoreLockTest.php
tests/src/Core/PConfig/CacheTest.php
tests/src/Core/PConfig/JitPConfigTest.php
tests/src/Core/PConfig/PConfigTest.php
tests/src/Core/PConfig/PreloadPConfigTest.php
tests/src/Core/StorageManagerTest.php
tests/src/Core/SystemTest.php
tests/src/Database/DBATest.php
tests/src/Database/DBStructureTest.php
tests/src/Model/ProcessTest.php
tests/src/Model/Storage/FilesystemStorageTest.php
tests/src/Model/User/CookieTest.php
tests/src/Module/Api/Twitter/ContactEndpointMock.php
tests/src/Module/Api/Twitter/ContactEndpointTest.php
tests/src/Util/ACLFormaterTest.php
tests/src/Util/BasePathTest.php
tests/src/Util/BaseURLTest.php
tests/src/Util/Config/ConfigFileLoaderTest.php
tests/src/Util/CryptoTest.php
tests/src/Util/EMailerTest.php
tests/src/Util/Emailer/MailBuilderTest.php
tests/src/Util/Emailer/SystemMailBuilderTest.php
tests/src/Util/Logger/StreamLoggerTest.php
tests/src/Util/Logger/SyslogLoggerTest.php
tests/src/Util/Logger/SyslogLoggerWrapper.php
tests/src/Util/Logger/WorkerLoggerTest.php
tests/src/Util/ProfilerTest.php
tests/src/Util/StringsTest.php
tests/src/Util/XmlTest.php

index c2dd3c84c78cde7de0247508d383f3113f1bf6f5..e380878f88f0adcf748506689c907ef358e4a128 100644 (file)
@@ -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;
index 59e1b3f556fd55b534344050317b40a06e2a4f19..c6f07897c6054be4bb072017a7600fc70745b43a 100644 (file)
@@ -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)
        {
index 932cceea8826547f4e73807592216cbfa5171e79..f15157e81bea444617c016364da8b43e62777b0c 100644 (file)
@@ -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();
 
index 2d47cc85ef5619f89181bd73dd863529944e4768..c792643018214340478c1ee5b469f7a50c1ad8e1 100644 (file)
@@ -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);
index 857589d2c5b7a073d144c54de91abf9f57298814..abd53a4e6c5b057b83a1cdeaf629a1e655b2cb14 100644 (file)
@@ -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
index 73a142d9a9c32931648f009a571c3f3c15674ed5..c6488fc4839e88f44fb858b04f7c5b83dd853484 100644 (file)
@@ -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 (file)
index 77f1cd7..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-<?php
-/**
- * @copyright Copyright (C) 2020, Friendica
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- *
- */
-
-namespace Friendica\Test\Util;
-
-use Friendica\Core\Cache\Duration;
-
-trait DbaCacheMockTrait
-{
-       /**
-        * @var
-        */
-       protected $dba;
-
-       public function __construct()
-       {
-       }
-
-       protected function mockDelete($key, $return = true, $times = null)
-       {
-               $this->mockDBADelete('cache', ['k' => $key], $return, $times);
-       }
-
-       protected function mockGet($key, $return = null, $time = null, $times = null)
-       {
-               if ($time === null) {
-                       $time = time();
-               }
-
-               $value = @serialize($return);
-
-               $this->mockSelectFirst('cache', ['v'], ['`k` = ? AND (`expires` >= ? OR `expires` = -1)', $key, $time], ['v' => $value], $times);
-               $this->mockIsResult(['v' => $value], isset($return), $times);
-       }
-
-       protected function mockSet($key, $value, $ttl = Duration::FIVE_MINUTES, $time = null, $return = true, $times = null)
-       {
-               if ($time === null) {
-                       $time = time();
-               }
-
-               if ($ttl > 0) {
-                       $this->mockUtc('now + ' . $ttl . 'seconds', $time + $ttl, $times);
-                       $fields = [
-                               'v' => serialize($value),
-                               'expires' => $time + $ttl,
-                               'updated' => $time
-                       ];
-               } else {
-                       $fields = [
-                               'v' => serialize($value),
-                               'expires' => -1,
-                               'updated' => $time
-                       ];
-               }
-
-               $this->mockDBAUpdate('cache', $fields, ['k' => $key], true, $return, $times);
-       }
-
-       protected function mockClear($outdated = true, $return = true, $times = null)
-       {
-               if ($outdated) {
-                       $this->mockDBADelete('cache', ['`expires` < NOW()'], $return, $times);
-               } else {
-                       $this->mockDBADelete('cache', ['`k` IS NOT NULL '], $return, $times);
-               }
-       }
-
-       protected function mockGetAllKeys($prefix = null, $return = [], $time = null, $times = null)
-       {
-               if ($time === null) {
-                       $time = time();
-               }
-
-               if (empty($prefix)) {
-                       $where = ['`expires` >= ?', $time];
-               } else {
-                       $where = ['`expires` >= ? AND `k` LIKE CONCAT(?, \'%\')', $time, $prefix];
-               }
-
-               $this->mockSelect('cache', ['k'], $where, $return, $times);
-               $this->mockFetchLoop($return, $times);
-               $this->mockDbaClose(true, $times);
-       }
-}
diff --git a/tests/Util/DbaLockMockTrait.php b/tests/Util/DbaLockMockTrait.php
deleted file mode 100644 (file)
index e38770c..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-<?php
-/**
- * @copyright Copyright (C) 2020, Friendica
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- *
- */
-
-namespace Friendica\Test\Util;
-
-use Friendica\Core\Cache\Duration;
-use Friendica\Core\Lock\DatabaseLock;
-
-trait DbaLockMockTrait
-{
-       use DBAMockTrait;
-       use DateTimeFormatMockTrait;
-
-       /**
-        * Mocking acquireLock with DBA-backend
-        *
-        * @param mixed    $key       The key to lock
-        * @param int      $ttl       The TimeToLive
-        *
-        * @param bool     $locked    Was the lock already set?
-        * @param null     $pid       The PID which was set
-        * @param bool     $rowExists True, if a row already exists in the lock table
-        * @param null     $time      The current timestamp
-        * @param null|int $times     How often the method will get used
-        *
-        *@see DatabaseLock::acquire()
-        *
-        */
-       public function mockAcquireLock($key, $ttl = Duration::FIVE_MINUTES, $locked = false, $pid = null, $rowExists = true, $time = null, $times = null)
-       {
-               if ($time === null) {
-                       $time = time();
-               }
-
-               if ($pid === null) {
-                       $pid = getmypid();
-               }
-
-               $this->mockDbaLock('locks', true, $times);
-
-               $this->mockUtcNow($time, $times);
-               $result = ['locked' => $locked, 'pid' => $pid];
-               $this->mockSelectFirst('locks', ['locked', 'pid'], ['`name` = ? AND `expires` >= ?', $key, $time], $result, $times);
-               $this->mockIsResult($result, $rowExists, $times);
-
-               if ($rowExists) {
-                       if (!$locked ) {
-                               $this->mockUtc('now + ' . $ttl . 'seconds', $time, $times);
-                               $this->mockDBAUpdate('locks', ['locked' => true, 'pid' => $pid, 'expires' => $time], ['name' => $key], [], true, $times);
-                       }
-               } else {
-                       $this->mockUtc('now + ' . $ttl . 'seconds', $time, $times);
-                       $this->mockDBAInsert('locks', ['name' => $key, 'locked' => true, 'pid' => $pid, 'expires' => $time], false, true, $times);
-               }
-
-               $this->mockDbaUnlock($times);
-       }
-
-       /**
-        * Mocking isLocked with DBA-backend
-        *
-        * @param mixed     $key    The key of the lock
-        * @param null|bool $return True, if the key is already locked
-        * @param null      $time   The current timestamp
-        * @param null|int  $times  How often the method will get used
-        *
-        *@see DatabaseLock::isLocked()
-        *
-        */
-       public function mockIsLocked($key, $return = true, $time = null, $times = null)
-       {
-               if ($time === null) {
-                       $time = time();
-               }
-
-               $this->mockUtcNow($time, $times);
-               $return = ((isset($return)) ? ['locked' => $return] : null);
-               $this->mockSelectFirst('locks', ['locked'], ['`name` = ? AND `expires` >= ?', $key, $time], $return, $times);
-               $this->mockIsResult($return, (isset($return) && $return), $times);
-       }
-
-       /**
-        * Mocking releaseAll with DBA-backend
-        *
-        * @param null     $pid   The PID which was set
-        * @param null|int $times How often the method will get used
-        *
-        *@see DatabaseLock::releaseAll()
-        *
-        */
-       public function mockReleaseAll($pid = null, $times = null)
-       {
-               if ($pid === null) {
-                       $pid = getmypid();
-               }
-
-               $this->mockDBADelete('locks', ['pid' => $pid], true, $times);
-       }
-
-       /**
-        * Mocking ReleaseLock with DBA-backend
-        *
-        * @param mixed    $key    The key to release
-        * @param null|int $pid    The PID which was set
-        * @param null|int $times  How often the method will get used
-        *
-        *@see DatabaseLock::release()
-        *
-        */
-       public function mockReleaseLock($key, $pid = null, $times = null)
-       {
-               if ($pid === null) {
-                       $pid = getmypid();
-               }
-
-               $this->mockDBADelete('locks', ['name' => $key, 'pid' => $pid], true, $times);
-       }
-}
index effd2ed08010a6611688a7e8a97261d79b490aa5..161e0f0db5ca730c331792fed7cad54565b72421 100644 (file)
@@ -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 = [
index 68a17c5bdbf4066c405a454a646800dd8fb87de2..fbc95aa9af86527d8b5f9756752d6dce897ecf1a 100644 (file)
@@ -16,6 +16,8 @@ trait HookMockTrait
        /**
         * Mocking a method 'Hook::call()' call
         *
+        * @param string $name
+        * @param mixed  $capture
         */
        public function mockHookCallAll(string $name, &$capture)
        {
index f22e98798bd3d9f2eae3a6484283e1a998a14160..ba4748dc0fdb41d1bf7fe1e793917e59c1fa06c8 100644 (file)
@@ -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)) {
index 04a65e302294f022cde3f3649f7a4ff9b8643e7d..f3973ea9be5783468709dc17c004a5bfcae838af 100644 (file)
@@ -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);
index 9aeec0b3348f6ff4c1759b7494fa848fc90b23a4..6cfbdc3ab7df3d8757cbc9558b47072ffec19dd1 100644 (file)
@@ -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;
index 96f385b3bad3813bb2a5f29bc56483e50611b45b..7b99806ab20b0329500213c2e18535f5b134e075 100644 (file)
@@ -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);
index 32c0164486ba8f9c709eedddfc95a1975bf6fbfa..d1c85bdd0ec3073a944603fa39e2270564c88958 100644 (file)
@@ -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;
 
index 9179bfddce8343df072ebecdc53c118c55db83d7..0a374fd63e61b8be624acd874a7381128e80444c 100644 (file)
@@ -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);
 
index a24608eb02e18b47754d4aa43f354c998e50ef4c..5f3f14c521c2a0424fe0f6797400679093361136 100644 (file)
@@ -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();
index 6846f74ff716d64cbe4c709945282a6b317f85ac..5edf3e2574d77cdd4092f871ae69369ba15e7a27 100644 (file)
@@ -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);
        }
index b0481be98c84af17d55012cf693d712e82e33d25..751cc0b9888d223f707b1c8a3b409f07f1c97b98 100644 (file)
@@ -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');
index 837d234b831d5cb062e10caedaf5814ecd8975fe..51bf04d59a5cf8838f00a82e624b900ea151cd96 100644 (file)
@@ -25,6 +25,8 @@ use Friendica\App;
 use Friendica\App\Mode;
 use Friendica\Console\Config;
 use Friendica\Core\Config\IConfig;
+use Mockery;
+use Mockery\LegacyMockInterface;
 use Mockery\MockInterface;
 
 class ConfigConsoleTest extends ConsoleTest
@@ -33,27 +35,27 @@ class ConfigConsoleTest extends ConsoleTest
         * @var App\Mode|MockInterface $appMode
         */
        private $appMode;
-       /** @var IConfig|\Mockery\LegacyMockInterface|MockInterface */
+       /** @var IConfig|LegacyMockInterface|MockInterface */
        private $configMock;
 
        protected function setUp()
        {
                parent::setUp();
 
-               \Mockery::getConfiguration()->setConstantsMap([
+               Mockery::getConfiguration()->setConstantsMap([
                        Mode::class => [
-                               'DBCONFIGAVAILABLE' => 0
-                       ]
+                               'DBCONFIGAVAILABLE' => 0,
+                       ],
                ]);
 
-               $this->appMode = \Mockery::mock(App\Mode::class);
+               $this->appMode = Mockery::mock(App\Mode::class);
                $this->appMode->shouldReceive('has')
-                       ->andReturn(true);
+                                         ->andReturn(true);
 
-               $this->configMock = \Mockery::mock(IConfig::class);
+               $this->configMock = Mockery::mock(IConfig::class);
        }
 
-       function testSetGetKeyValue()
+       public function testSetGetKeyValue()
        {
                $this->configMock
                        ->shouldReceive('set')
@@ -98,7 +100,8 @@ class ConfigConsoleTest extends ConsoleTest
                self::assertEquals("config.test => \n", $txt);
        }
 
-       function testSetArrayValue() {
+       public function testSetArrayValue()
+       {
                $testArray = [1, 2, 3];
                $this->configMock
                        ->shouldReceive('get')
@@ -115,19 +118,21 @@ class ConfigConsoleTest extends ConsoleTest
                self::assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt);
        }
 
-       function testTooManyArguments() {
+       public function testTooManyArguments()
+       {
                $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
                $console->setArgument(0, 'config');
                $console->setArgument(1, 'test');
                $console->setArgument(2, 'it');
                $console->setArgument(3, 'now');
-               $txt = $this->dumpExecute($console);
+               $txt       = $this->dumpExecute($console);
                $assertion = '[Warning] Too many arguments';
                $firstline = substr($txt, 0, strlen($assertion));
                self::assertEquals($assertion, $firstline);
        }
 
-       function testVerbose() {
+       public function testVerbose()
+       {
                $this->configMock
                        ->shouldReceive('get')
                        ->with('test', 'it')
@@ -138,7 +143,7 @@ class ConfigConsoleTest extends ConsoleTest
                $console->setArgument(1, 'it');
                $console->setOption('v', 1);
                $executable = $this->consoleArgv[0];
-               $assertion = <<<CONF
+               $assertion  = <<<CONF
 Executable: {$executable}
 Class: Friendica\Console\Config
 Arguments: array (
@@ -151,11 +156,12 @@ Options: array (
 test.it => now
 
 CONF;
-               $txt = $this->dumpExecute($console);
+               $txt        = $this->dumpExecute($console);
                self::assertEquals($assertion, $txt);
        }
 
-       function testUnableToSet() {
+       public function testUnableToSet()
+       {
                $this->configMock
                        ->shouldReceive('set')
                        ->with('test', 'it', 'now')
@@ -164,7 +170,7 @@ CONF;
                $this->configMock
                        ->shouldReceive('get')
                        ->with('test', 'it')
-                       ->andReturn(NULL)
+                       ->andReturn(null)
                        ->once();
                $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
                $console->setArgument(0, 'test');
index 724163d6ff0552968b074fd313abcc000a7493a8..7f2f13c7395fbc7c83043c44985834faf5087c3d 100644 (file)
@@ -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();
index e06ee3a4ca55199e973bb3aeb70a90ca49226b5d..04ac54b3e33c8b3cf4fb7630aa1ff5a26ba75c14 100644 (file)
@@ -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()
index 8efa8a4a76d6b786b5454d25c318710b379e1acc..cb595f99125094e62bc805ec08aff890ff96c47f 100644 (file)
@@ -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);
        }
 
        /**
index 102e594270b0775908a8cc615df68497b342bfd1..7d8c229301a27744c47371aa33ee25b1327659bc 100644 (file)
@@ -27,6 +27,6 @@ class ItemTest extends MockedTest
 {
        public function testDetermineCategoriesTerms()
        {
-               $this->markTestIncomplete('Test data needed.');
+               static::markTestIncomplete('Test data needed.');
        }
 }
index d2a5fcff480fb250423798cf1a970c5d4aa42342..99e2da399b54ceaab061b1807d97f9f0c710e54d 100644 (file)
@@ -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)
        {
index 27bdead3c154654a39312096541edbf3e929d769..a3633cea53a0e812f779c4eb0093772fdf2b5ccb 100644 (file)
@@ -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);
index 17c2bca19bb68202128c699e51894f4e995c8d59..1a1e05f454cfabc0e1c895f0d896ae5c38a5baf8 100644 (file)
@@ -24,9 +24,11 @@ namespace Friendica\Test\src\Content\Text;
 use Friendica\App\BaseURL;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\L10n;
+use Friendica\Network\HTTPException\InternalServerErrorException;
 use Friendica\Test\MockedTest;
 use Friendica\Test\Util\AppMockTrait;
 use Friendica\Test\Util\VFSTrait;
+use Mockery;
 
 class BBCodeTest extends MockedTest
 {
@@ -62,13 +64,13 @@ class BBCodeTest extends MockedTest
                        ->with('system', 'big_emojis')
                        ->andReturn(false);
 
-               $l10nMock = \Mockery::mock(L10n::class);
+               $l10nMock = Mockery::mock(L10n::class);
                $l10nMock->shouldReceive('t')->withAnyArgs()->andReturnUsing(function ($args) { return $args; });
                $this->dice->shouldReceive('create')
                           ->with(L10n::class)
                           ->andReturn($l10nMock);
 
-               $baseUrlMock = \Mockery::mock(BaseURL::class);
+               $baseUrlMock = Mockery::mock(BaseURL::class);
                $baseUrlMock->shouldReceive('get')->withAnyArgs()->andReturn('friendica.local');
                $this->dice->shouldReceive('create')
                           ->with(BaseURL::class)
@@ -158,13 +160,15 @@ class BBCodeTest extends MockedTest
 
        /**
         * Test convert different links inside a text
+        *
         * @dataProvider dataLinks
         *
-        * @param string $data The data to text
-        * @param bool $assertHTML True, if the link is a HTML link (<a href...>...</a>)
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @param string $data       The data to text
+        * @param bool   $assertHTML True, if the link is a HTML link (<a href...>...</a>)
+        *
+        * @throws InternalServerErrorException
         */
-       public function testAutoLinking($data, $assertHTML)
+       public function testAutoLinking(string $data, bool $assertHTML)
        {
                $output = BBCode::convert($data);
                $assert = '<a href="' . $data . '" target="_blank" rel="noopener noreferrer">' . $data . '</a>';
@@ -258,9 +262,10 @@ class BBCodeTest extends MockedTest
         * @param bool   $try_oembed   Whether to convert multimedia BBCode tag
         * @param int    $simpleHtml   BBCode::convert method $simple_html parameter value, optional.
         * @param bool   $forPlaintext BBCode::convert method $for_plaintext parameter value, optional.
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        *
+        * @throws InternalServerErrorException
         */
-       public function testConvert($expectedHtml, $text, $try_oembed = false, $simpleHtml = 0, $forPlaintext = false)
+       public function testConvert(string $expectedHtml, string $text, $try_oembed = false, int $simpleHtml = 0, bool $forPlaintext = false)
        {
                $actual = BBCode::convert($text, $try_oembed, $simpleHtml, $forPlaintext);
 
@@ -290,12 +295,13 @@ class BBCodeTest extends MockedTest
         *
         * @dataProvider dataBBCodesToMarkdown
         *
-        * @param string $expected     Expected Markdown output
-        * @param string $text         BBCode text
+        * @param string $expected Expected Markdown output
+        * @param string $text     BBCode text
         * @param bool   $for_diaspora
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        *
+        * @throws InternalServerErrorException
         */
-       public function testToMarkdown($expected, $text, $for_diaspora = false)
+       public function testToMarkdown(string $expected, string $text, $for_diaspora = false)
        {
                $actual = BBCode::toMarkdown($text, $for_diaspora);
 
index ca313bec57c6dd5ef0291eca9fd2cc6003ac3156..86315ee092d1c8a73279ef567b8f0446a1c0f199 100644 (file)
@@ -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);
 
index 1f1146af9a01bd8d4f96070317340071127ff26d..fc0bfb9584a503def815b54c1cc3f9829ae0e2e4 100644 (file)
@@ -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);
 
index 695c725d3f344d5effdf29422bf7cdee3736e038..5e49f45f5676777d82ddb71973923dbde2dac330 100644 (file)
@@ -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();
index a0dd87b0322f91c7bba591b923ec7fa36221f5c6..0297a3b13c89a90310af73cef73c0dd0dfe43270 100644 (file)
@@ -31,7 +31,7 @@ class ArrayCacheTest extends MemoryCacheTest
                return $this->cache;
        }
 
-       public function tearDown()
+       protected function tearDown()
        {
                $this->cache->clear(false);
                parent::tearDown();
index 3daf1db6f446734c9d3140ef6d2f0d58c03675ea..731b86c9005044a8acc3e561c2840e2371d51d1c 100644 (file)
@@ -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');
index f8919a6cfbb75ce4b0439c5f32a9854a07ed897a..c1891b08c147705af55337aea92c9513eda16527 100644 (file)
@@ -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();
index 44600d5eed81ef1f527b3d2476678b66c0cd9879..5d85a065676ddb1b8493c7a3bc5bc0f31abedff2 100644 (file)
 
 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');
        }
 }
index c6ec48a4ba6269dbce66e1a4baf27fbf93e8e91a..b02311c0f71a48f2a9ba518f1334fbee8961a173 100644 (file)
 
 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');
        }
 }
index 003db6ad832af0f807eff1bb37e14d6c873f072c..9e096320a940d134a0461e23e2b7f504b0f96aec 100644 (file)
 
 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'));
 
index 543137ca09ad509b45e6d3ddf95ea92a37a454c2..9d8d02decd4ddf805247d815c096c40262cb6393 100644 (file)
 
 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();
index 383046b0425a7ecc31b8e4a7b45eeb183d1d35ce..0cc54360f1e0d5d54cea8adc0b615833a7b85744 100644 (file)
@@ -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' => '',
                        ]
                ]);
index 59ad3b9690a999955a7ee900c9e0f952327f7949..ca0d4b37b842b53abbeee00085d67395e2d6e1d4 100644 (file)
@@ -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());
index df0ea4f308a583b56134bda8339e554dea349266..204e87ec792e4a2423c16e82a8ec72ab16a635e4 100644 (file)
@@ -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) {
index 386f093023708d0604483170271297a7e0a5ae43..0dbf6787b18d6c449935d0750992d73d9043dd3d 100644 (file)
@@ -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) {
index 68af5ff37f9bf068c25eee08a28dfc248c7d5058..0933d9e1a52b608c876354f31abb68692d29fbd7 100644 (file)
@@ -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'])) {
index 84486595654801c7cb1b1782c03154bdce1fe36a..052636591c2ea08a5119b967dfda6e92c8c6b4fb 100644 (file)
@@ -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();
index 5f3ef13c128e7de90e9c021aed061dbc92fd235e..821b0874d7da86d292c5c0a5983c15074f0080a8 100644 (file)
@@ -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
index ea668d83bb04d4d33e360c5593ad5448ce62e535..2c0445c01607a8d5a759d36f9445bf66f90aae96 100644 (file)
@@ -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'));
index f4aab0602cd943cc6cd3c5c2be0cdf96277c083f..b5ee717d2c0c65a445428a60977ceea5f1b0d21e 100644 (file)
 
 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');
        }
 }
index f41bf992055417c3f474b505fbbcc0a122506a2c..55350302d47ae9249ae3a1de0c4c995d659bfb12 100644 (file)
 
 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');
        }
 }
index 62b15bc7c73eef0cf616fb61ddb4e785ece9ebed..b531a5dfe71db31c2faf6ecbd2569f1e13c26c20 100644 (file)
 
 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;
index fd60f32c71fccded6b63cc56fc584a0dc2b4ca88..ce11ca5314abafad9702bc1f77a9b7144b5240f9 100644 (file)
@@ -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()
index bc5aa6934f738cbc5c2cae652e0a272094934694..da76ab4d9de6a9098a807f7237676f3ccda5b191 100644 (file)
@@ -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();
 
index b8df4682989361b3798f72ae221e9e8c09364c3e..6dfe1403ae1c2255cda9ac86692a7e900fbb17bb 100644 (file)
@@ -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
 {
index 4bc5edb41844aed7b4de6153e778da4778d5146d..f84447fb2fd328ae20618d7d919745f095a0c3c7 100644 (file)
@@ -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());
index 413a6c99709d7116bcd8ec857b9404737d2bd926..400618e8e406d877a98e7eac1d0144a0c2374b29 100644 (file)
@@ -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
 {
index f061ea0fff8c7456e66d4f8650e0ebad6d45e2b9..e3fd747e4a4d9a6ec80bfd7a25d8c3231feb9c2f 100644 (file)
@@ -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);
index 2235b37574790c98f6de5ce5f4a033e179c3df34..1d90bc7576243f07f805f2c6f9e715df840fcd46 100644 (file)
@@ -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');
index 053acbe6492825ff40cd9fbe74ee401f229bc929..c013dcda836004ec1dcc2f23adfc5ebcf19b7784 100644 (file)
@@ -10,7 +10,7 @@ use Friendica\Test\Util\Database\StaticDatabase;
 
 class DBATest extends DatabaseTest
 {
-       public function setUp()
+       protected function setUp()
        {
                parent::setUp();
 
index ee1fb04f87e09e0b8270c3b2c35ccf8ab4331c99..1987f10c3146ec2964cba31ef553f826558d018d 100644 (file)
@@ -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';
 
index 490cd34c7a75e1af7610b9ec66a235ca997f4ea1..fb02f62ff165769681a416e113985d2b926ad010 100644 (file)
@@ -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()
index 232c0fc4bfad7a3cfc7d8918a2f2a44c8655c025..0224e9101fe3f95c140034a0c60154bf3cd20ab2 100644 (file)
@@ -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);
 
index e8dba95576ae4d369edee29a1018038413cf81f0..e6e29048d9ba6534d0834eaad056163f9518bd16 100644 (file)
@@ -48,6 +48,8 @@ class CookieTest extends MockedTest
        protected function tearDown()
        {
                StaticCookie::clearStatic();
+
+               parent::tearDown();
        }
 
        /**
index ff887171921ce9abb18bdd31724560e5d59dece9..84c6ce68c1716b6d55590fc8aa8d7d4e4dfa1ae9 100644 (file)
@@ -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)
        {
index 677790d63fef4ba3d573adfebd26fa0c41c7f767..d9506a60ec8863f1d6ef10ee0c380b45445fe27c 100644 (file)
@@ -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()
index d565d0ba95db0366d270f700da17e6fc9b72c14d..609bd5fa5abb58a45452008dc8e44da30fcbf47f 100644 (file)
@@ -21,7 +21,6 @@
 
 namespace Friendica\Test\src\Util;
 
-use Error;
 use Friendica\Model\Group;
 use Friendica\Util\ACLFormatter;
 use PHPUnit\Framework\TestCase;
index 61c740c79c34bbe3c256e3a2c2e582eb33205f4a..ffafa5b55a69bb37d6511c3cb815eb3cf2cc9a4e 100644 (file)
@@ -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();
        }
index 83410066b0cf14517723f7a4c6dea480328208ae..79f0637e3f179a11882a02ab8fa73592759581bd 100644 (file)
@@ -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());
        }
 }
index 96e54bea050cdf107cce9932534000f0b172d071..43ee8b84a971a0d4a4a74a8810be9ceef52c0efd 100644 (file)
@@ -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')
index 1a25e171953a052362e19c0f93ab3ca3ab7e7916..67c3b2ba2a80f15d87c72a0a357b6377c74375bb 100644 (file)
@@ -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());
        }
 }
index 7c3b4b026b1429cad40ce2c2131a7be7250b2e8d..523d3de1222a1304b528430ec7b6ff214d40a63e 100644 (file)
@@ -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()
index 8287e7609001d29b9aa354759756b13c2f6b0f81..72f2fcdf044eb4cbb440cd9f8df4ec79526772b5 100644 (file)
@@ -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
index 857369bdff45960d13cf552e955effac088e7423..bab5ab010d813f66f9820da358d8acbfdad1c011 100644 (file)
@@ -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 = [];
        }
 
        /**
index 2e2aac2f1b2a076329b2de25c1e32bb9e0536e88..e17a07ce29ef8eb459432567e181707d117f4b2a 100644 (file)
@@ -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);
index 5bedaf5dc3fde6a61b593aee5d553716e5b84e37..2191b7d20db3f2fa54c3b97347a913603588ddcc 100644 (file)
@@ -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');
        }
index 8cc6a77f5fb43ef706bb09538347e11956da9948..1cfeb09e77fbe14445052e5f05d96817e48416dd 100644 (file)
@@ -51,6 +51,7 @@ class SyslogLoggerWrapper extends SyslogLogger
 
        /**
         * {@inheritdoc}
+        * @noinspection PhpMissingParentCallCommonInspection
         */
        protected function syslogWrapper($level, $entry)
        {
index b110677de1cc0ea53a7a077ef5bc51181730b62c..4a5db2ea7a02d969f3248207500bbcf63054e5fa 100644 (file)
@@ -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);
        }
index 45b29943f507a893be49cf8513f03810dcb7a6ce..cc4f2c8760b75671841a37650ba3b1819a633cbb 100644 (file)
@@ -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')
index 86b55a2fe3328100358485683258fde7c22b8a2c..9b2215368687800520f685d4709df2a2e65c26c0 100644 (file)
@@ -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));
        }
index 99b58a0b8795e6bea313a0e463aeefc15cd87a07..ed8955a9f0473105ef47428b1d5094f41476147f 100644 (file)
@@ -29,36 +29,36 @@ use PHPUnit\Framework\TestCase;
  */
 class XmlTest extends TestCase
 {
-    /**
-       * escape and unescape
-       */
+       /**
+        * escape and unescape
+        */
        public function testEscapeUnescape()
        {
-               $text="<tag>I want to break\n this!11!<?hard?></tag>";
-               $xml=XML::escape($text);
-               $retext=XML::unescape($text);
+               $text   = "<tag>I want to break\n this!11!<?hard?></tag>";
+               $xml    = XML::escape($text);
+               $retext = XML::unescape($text);
                self::assertEquals($text, $retext);
-    }
-    
+       }
+
        /**
         * escape and put in a document
         */
        public function testEscapeDocument()
        {
-               $tag="<tag>I want to break</tag>";
-               $xml=XML::escape($tag);
-               $text='<text>'.$xml.'</text>';
-               $xml_parser=xml_parser_create();
+               $tag        = "<tag>I want to break</tag>";
+               $xml        = XML::escape($tag);
+               $text       = '<text>' . $xml . '</text>';
+               $xml_parser = xml_parser_create();
                //should be possible to parse it
-               $values=array();
-               $index=array();
+               $values = [];
+               $index  = [];
                self::assertEquals(1, xml_parse_into_struct($xml_parser, $text, $values, $index));
                self::assertEquals(
-                       array('TEXT'=>array(0)),
+                       ['TEXT' => [0]],
                        $index
                );
                self::assertEquals(
-                       array(array('tag'=>'TEXT', 'type'=>'complete', 'level'=>1, 'value'=>$tag)),
+                       [['tag' => 'TEXT', 'type' => 'complete', 'level' => 1, 'value' => $tag]],
                        $values
                );
                xml_parser_free($xml_parser);