]> git.mxchange.org Git - friendica.git/commitdiff
Adapt tests for PhpUnit 7.5
authorPhilipp <admin@philipp.info>
Thu, 1 Apr 2021 19:19:45 +0000 (21:19 +0200)
committerPhilipp <admin@philipp.info>
Sun, 4 Apr 2021 17:13:40 +0000 (19:13 +0200)
tests/legacy/ApiTest.php
tests/src/Core/Cache/ArrayCacheTest.php
tests/src/Core/InstallerTest.php
tests/src/Core/Lock/ArrayCacheLockTest.php
tests/src/Core/Lock/SemaphoreLockTest.php
tests/src/Security/TwoFactor/Factory/TrustedBrowserTest.php
tests/src/Security/TwoFactor/Model/TrustedBrowserTest.php
tests/src/Util/Logger/ProfilerLoggerTest.php
tests/src/Util/Logger/SyslogLoggerTest.php
tests/src/Util/Logger/VoidLoggerTest.php

index 265f502f0aae3c7283e868a16c89152ac1ed6a63..89bddf31d17aa4667dc6524ebd54e058612017b7 100644 (file)
@@ -22,6 +22,8 @@ require_once __DIR__ . '/../../include/api.php';
  *
  * Functions that use header() need to be tested in a separate process.
  * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
+ *
+ * @backupGlobals enabled
  */
 class ApiTest extends FixtureTest
 {
@@ -108,10 +110,6 @@ class ApiTest extends FixtureTest
                        'authenticated' => true,
                        'uid'           => $this->selfUser['id']
                ];
-
-               $_POST   = [];
-               $_GET    = [];
-               $_SERVER = [];
        }
 
        /**
@@ -140,7 +138,7 @@ class ApiTest extends FixtureTest
         *
         * @return void
         */
-       private function assertOtherUser(array $user)
+       private function assertOtherUser(array $user = [])
        {
                self::assertEquals($this->otherUser['id'], $user['id']);
                self::assertEquals($this->otherUser['id'], $user['id_str']);
@@ -157,10 +155,10 @@ class ApiTest extends FixtureTest
         *
         * @return void
         */
-       private function assertStatus(array $status)
+       private function assertStatus(array $status = [])
        {
-               self::assertInternalType('string', $status['text']);
-               self::assertInternalType('int', $status['id']);
+               self::assertInternalType('string', $status['text'] ?? '');
+               self::assertInternalType('int', $status['id'] ?? '');
                // We could probably do more checks here.
        }
 
@@ -171,7 +169,7 @@ class ApiTest extends FixtureTest
         *
         * @return void
         */
-       private function assertList(array $list)
+       private function assertList(array $list = [])
        {
                self::assertInternalType('string', $list['name']);
                self::assertInternalType('int', $list['id']);
@@ -188,7 +186,7 @@ class ApiTest extends FixtureTest
         *
         * @return void
         */
-       private function assertXml($result, $root_element)
+       private function assertXml($result = '', $root_element = '')
        {
                self::assertStringStartsWith('<?xml version="1.0"?>', $result);
                self::assertContains('<' . $root_element, $result);
@@ -304,6 +302,7 @@ class ApiTest extends FixtureTest
         *
         * @return void
         * @runInSeparateProcess
+        * @preserveGlobalState disabled
         * @expectedException Friendica\Network\HTTPException\UnauthorizedException
         */
        public function testApiLoginWithoutLogin()
@@ -316,6 +315,7 @@ class ApiTest extends FixtureTest
         *
         * @return void
         * @runInSeparateProcess
+        * @preserveGlobalState disabled
         * @expectedException Friendica\Network\HTTPException\UnauthorizedException
         */
        public function testApiLoginWithBadLogin()
@@ -349,6 +349,7 @@ class ApiTest extends FixtureTest
         *
         * @return void
         * @runInSeparateProcess
+        * @doesNotPerformAssertions
         */
        public function testApiLoginWithCorrectLogin()
        {
@@ -1312,8 +1313,8 @@ class ApiTest extends FixtureTest
 
        /**
         * Test the api_media_upload() function.
-        *
-        * @return void
+        * @runInSeparateProcess
+        * @preserveGlobalState disabled
         * @expectedException Friendica\Network\HTTPException\BadRequestException
         */
        public function testApiMediaUpload()
@@ -1504,7 +1505,7 @@ class ApiTest extends FixtureTest
                $result             = api_search('json');
                foreach ($result['status'] as $status) {
                        self::assertStatus($status);
-                       self::assertContains('reply', $status['text'], null, true);
+                       self::assertContains('reply', $status['text'], '', true);
                }
        }
 
@@ -1520,7 +1521,7 @@ class ApiTest extends FixtureTest
                $result            = api_search('json');
                foreach ($result['status'] as $status) {
                        self::assertStatus($status);
-                       self::assertContains('reply', $status['text'], null, true);
+                       self::assertContains('reply', $status['text'], '', true);
                }
        }
 
@@ -1536,14 +1537,13 @@ class ApiTest extends FixtureTest
                $result          = api_search('json');
                foreach ($result['status'] as $status) {
                        self::assertStatus($status);
-                       self::assertContains('reply', $status['text'], null, true);
+                       self::assertContains('reply', $status['text'], '', true);
                }
        }
 
        /**
         * Test the api_search() function with an q parameter contains hashtag.
-        *
-        * @return void
+        * @doesNotPerformAssertions
         */
        public function testApiSearchWithHashtag()
        {
@@ -1551,14 +1551,13 @@ class ApiTest extends FixtureTest
                $result        = api_search('json');
                foreach ($result['status'] as $status) {
                        self::assertStatus($status);
-                       self::assertContains('#friendica', $status['text'], null, true);
+                       self::assertContains('#friendica', $status['text'], '', true);
                }
        }
 
        /**
         * Test the api_search() function with an exclude_replies parameter.
-        *
-        * @return void
+        * @doesNotPerformAssertions
         */
        public function testApiSearchWithExcludeReplies()
        {
@@ -2474,8 +2473,7 @@ class ApiTest extends FixtureTest
 
        /**
         * Test the api_format_items() function.
-        *
-        * @return void
+        * @doesNotPerformAssertions
         */
        public function testApiFormatItems()
        {
@@ -2500,8 +2498,7 @@ class ApiTest extends FixtureTest
 
        /**
         * Test the api_format_items() function with an XML result.
-        *
-        * @return void
+        * @doesNotPerformAssertions
         */
        public function testApiFormatItemsWithXml()
        {
@@ -2617,8 +2614,7 @@ class ApiTest extends FixtureTest
 
        /**
         * Test the api_lists_statuses() function with a list ID.
-        *
-        * @return void
+        * @doesNotPerformAssertions
         */
        public function testApiListsStatusesWithListId()
        {
@@ -3271,8 +3267,6 @@ class ApiTest extends FixtureTest
 
        /**
         * Test the api_fr_photo_create_update() function.
-        *
-        * @return void
         * @expectedException Friendica\Network\HTTPException\BadRequestException
         */
        public function testApiFrPhotoCreateUpdate()
index 6ce6d4c1faeb535c0e85db260ed3f8e310a1e468..2d8d0ff837c1efd53e969dc51033f01290d64a45 100644 (file)
@@ -40,6 +40,7 @@ class ArrayCacheTest extends MemoryCacheTest
        public function testTTL()
        {
                // Array Cache doesn't support TTL
+               self::markTestSkipped("Array Cache doesn't support TTL");
                return true;
        }
 }
index 365502e4673fef06961cb4986f09352b516d9149..b3f91e7d33609a0bb217aa13f695077f41b85e25 100644 (file)
@@ -463,10 +463,11 @@ class InstallerTest extends MockedTest
 
        /**
         * Test the setup of the config cache for installation
+        * @doesNotPerformAssertions
         */
        public function testSetUpCache()
        {
-               $this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
+               $this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; })->times(5);
 
                $install = new Installer();
                $configCache = Mockery::mock(Cache::class);
index 727b9724a1e52e558c774e6eebb6a5830afd8c35..6ddedfa438b3bfeb6d1d9aa283aeab1461ae3605 100644 (file)
@@ -33,7 +33,6 @@ class ArrayCacheLockTest extends LockTest
 
        public function testLockTTL()
        {
-               // ArrayCache doesn't support TTL
-               return true;
+               self::markTestSkipped("ArrayCache doesn't support TTL");
        }
 }
index dc7b9ee41994c29f6dc7ec8f0ba1cd688b503220..71273fdc2c0289749778a5038c741b88370291fd 100644 (file)
@@ -61,8 +61,7 @@ class SemaphoreLockTest extends LockTest
 
        public function testLockTTL()
        {
-               // Semaphore doesn't work with TTL
-               return true;
+               self::markTestSkipped("Semaphore doesn't work with TTL");
        }
 
        /**
index 5b2b6111c9422656f842655a455a03c23d150d02..0a093db5a1d92a6843c407868a2f00fd5fad4fa6 100644 (file)
@@ -3,11 +3,12 @@
 namespace Friendica\Test\src\Security\TwoFactor\Factory;
 
 use Friendica\Security\TwoFactor\Factory\TrustedBrowser;
+use Friendica\Test\MockedTest;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Logger\VoidLogger;
 use Friendica\Util\Strings;
 
-class TrustedBrowserTest extends \PHPUnit_Framework_TestCase
+class TrustedBrowserTest extends MockedTest
 {
        public function testCreateFromTableRowSuccess()
        {
index d89527374444488f792ea6e7e3ac19e779d08ad3..eae7f580f38736aaab1182b2aa72f8b4bd3bfc56 100644 (file)
@@ -3,10 +3,11 @@
 namespace Friendica\Test\src\Security\TwoFactor\Model;
 
 use Friendica\Security\TwoFactor\Model\TrustedBrowser;
+use Friendica\Test\MockedTest;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
 
-class TrustedBrowserTest extends \PHPUnit_Framework_TestCase
+class TrustedBrowserTest extends MockedTest
 {
        public function test__construct()
        {
index 81a94a46622183473b84784d71211fa87156fb7a..9dd82b4276575237887484cf1d4b3d8a4528237b 100644 (file)
@@ -52,6 +52,7 @@ class ProfilerLoggerTest extends MockedTest
        /**
         * Test if the profiler is profiling data
         * @dataProvider dataTests
+        * @doesNotPerformAssertions
         */
        public function testProfiling($function, $message, array $context)
        {
@@ -64,6 +65,7 @@ class ProfilerLoggerTest extends MockedTest
 
        /**
         * Test the log() function
+        * @doesNotPerformAssertions
         */
        public function testProfilingLog()
        {
index 67c726e2516951d82b6a0879ed52f908d453bafa..61c0d874a8ea992a712c49fca9b685a4d20e4ad5 100644 (file)
@@ -95,6 +95,7 @@ class SyslogLoggerTest extends AbstractLoggerTest
 
        /**
         * Test the close() method
+        * @doesNotPerformAssertions
         */
        public function testClose()
        {
index bea2bc404e7b7d55ee37aa8cc3ea171f61e3ded7..75b2d1a8b8f166230f31f5bc17772906040ee408 100644 (file)
@@ -32,6 +32,7 @@ class VoidLoggerTest extends MockedTest
        /**
         * Test if the profiler is profiling data
         * @dataProvider dataTests
+        * @doesNotPerformAssertions
         */
        public function testNormal($function, $message, array $context)
        {
@@ -41,6 +42,7 @@ class VoidLoggerTest extends MockedTest
 
        /**
         * Test the log() function
+        * @doesNotPerformAssertions
         */
        public function testProfilingLog()
        {