]> git.mxchange.org Git - friendica.git/commitdiff
Replace string namespaces with ::class
authorPhilipp Holzer <admin@philipp.info>
Sun, 24 Feb 2019 12:40:54 +0000 (13:40 +0100)
committerPhilipp Holzer <admin@philipp.info>
Sun, 24 Feb 2019 12:40:54 +0000 (13:40 +0100)
src/Factory/LoggerFactory.php
src/Factory/ProfilerFactory.php
tests/Util/DBAMockTrait.php
tests/Util/DBStructureMockTrait.php
tests/Util/DateTimeFormatMockTrait.php
tests/Util/L10nMockTrait.php
tests/Util/RendererMockTrait.php
tests/src/Core/Console/ConfigConsoleTest.php
tests/src/Core/InstallerTest.php
tests/src/Util/Logger/WorkerLoggerTest.php
tests/src/Util/ProfilerTest.php

index 97b513bd34289d133062c74bbc984bb0f906a0ab..8eb5506093da9145cda2231508381afb553883aa 100644 (file)
@@ -20,6 +20,16 @@ use Psr\Log\LogLevel;
  */
 class LoggerFactory
 {
+       /**
+        * A list of classes, which shouldn't get logged
+        * @var array
+        */
+       private static $ignoreClassList = [
+               Logger::class,
+               Profiler::class,
+               WorkerLogger::class
+       ];
+
        /**
         * Creates a new PSR-3 compliant logger instances
         *
@@ -34,7 +44,7 @@ class LoggerFactory
                $logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor());
                $logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor());
                $logger->pushProcessor(new Monolog\Processor\UidProcessor());
-               $logger->pushProcessor(new FriendicaIntrospectionProcessor(LogLevel::DEBUG, [Logger::class, Profiler::class, WorkerLogger::class]));
+               $logger->pushProcessor(new FriendicaIntrospectionProcessor(LogLevel::DEBUG, self::$ignoreClassList));
 
                $debugging = $config->get('system', 'debugging');
                $stream    = $config->get('system', 'logfile');
@@ -79,7 +89,7 @@ class LoggerFactory
                $logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor());
                $logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor());
                $logger->pushProcessor(new Monolog\Processor\UidProcessor());
-               $logger->pushProcessor(new FriendicaIntrospectionProcessor(LogLevel::DEBUG, ['Friendica\\Core\\Logger']));
+               $logger->pushProcessor(new FriendicaIntrospectionProcessor(LogLevel::DEBUG, self::$ignoreClassList));
 
                $logger->pushHandler(new FriendicaDevelopHandler($developerIp));
 
@@ -146,6 +156,13 @@ class LoggerFactory
                        if (!is_int($loglevel)) {
                                $loglevel = LogLevel::NOTICE;
                        }
+
+                       // if the stream is a file and it isn't writeable, add a null handler and return
+                       if (is_file($stream) && !is_writable($stream)) {
+                               $logger->pushHandler(new Monolog\Handler\NullHandler());
+                               return;
+                       }
+
                        $fileHandler = new Monolog\Handler\StreamHandler($stream, $loglevel);
 
                        $formatter = new Monolog\Formatter\LineFormatter("%datetime% %channel% [%level_name%]: %message% %context% %extra%\n");
index 26a156639e6bb05d79d8976f0862418cef2183be..19c96e8ca216eab37c4b30f567e56c46705fc370 100644 (file)
@@ -17,9 +17,9 @@ class ProfilerFactory
        public static function create(IConfigCache $configCache)
        {
                $enabled = $configCache->get('system', 'profiler');
-               $enabled = isset($enabled) && $enabled !== '!<unset>!';
+               $enabled = isset($enabled) && $enabled !== '0';
                $renderTime = $configCache->get('rendertime', 'callstack');
-               $renderTime = isset($renderTime) && $renderTime !== '!<unset>!';
+               $renderTime = isset($renderTime) && $renderTime !== '0';
 
                return new Profiler($enabled, $renderTime);
        }
index 296e3539496f225f1397686ed91212ced47ec449..ab5bc6059edec3765c9fa132610ec7f692f6c0fc 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Friendica\Test\Util;
 
+use Friendica\Database\DBA;
 use Mockery\MockInterface;
 
 class DBAStub
@@ -22,7 +23,7 @@ trait DBAMockTrait
        private function checkMock()
        {
                if (!isset($this->dbaMock)) {
-                       $this->dbaMock = \Mockery::namedMock('Friendica\Database\DBA', 'Friendica\Test\Util\DBAStub');
+                       $this->dbaMock = \Mockery::namedMock(DBA::class, DBAStub::class);
                }
        }
 
index 92ec412cb7ed4bec698c49c768248b2efe9d67a1..224e5d07af27482eedb0915c891dfbb72cfababc 100644 (file)
@@ -26,7 +26,7 @@ trait DBStructureMockTrait
        public function mockUpdate($args = [], $return = true, $times = null)
        {
                if (!isset($this->dbStructure)) {
-                       $this->dbStructure = \Mockery::mock('alias:Friendica\Database\DBStructure');
+                       $this->dbStructure = \Mockery::mock('alias:' . DBStructure::class);
                }
 
                $this->dbStructure
@@ -46,7 +46,7 @@ trait DBStructureMockTrait
        public function mockExistsTable($tableName, $return = true, $times = null)
        {
                if (!isset($this->dbStructure)) {
-                       $this->dbStructure = \Mockery::mock('alias:Friendica\Database\DBStructure');
+                       $this->dbStructure = \Mockery::mock('alias:' . DBStructure::class);
                }
 
                $this->dbStructure
index 1f1ad0199a52caf6b2271133448644697f6dc37c..0230e16a432019613996eb4962083bc3e5d0f12a 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Friendica\Test\Util;
 
+use Friendica\Util\DateTimeFormat;
 use Mockery\MockInterface;
 
 trait DateTimeFormatMockTrait
@@ -14,7 +15,7 @@ trait DateTimeFormatMockTrait
        public function mockUtcNow($time, $times = null)
        {
                if (!isset($this->dtfMock)) {
-                       $this->dtfMock = \Mockery::mock('alias:Friendica\Util\DateTimeFormat');
+                       $this->dtfMock = \Mockery::mock('alias:'. DateTimeFormat::class);
                }
 
                $this->dtfMock
@@ -26,7 +27,7 @@ trait DateTimeFormatMockTrait
        public function mockUtc($input, $time, $times = null)
        {
                if (!isset($this->dtfMock)) {
-                       $this->dtfMock = \Mockery::mock('alias:Friendica\Util\DateTimeFormat');
+                       $this->dtfMock = \Mockery::mock('alias:' . DateTimeFormat::class);
                }
 
                $this->dtfMock
index f1c771c6b3f6d36b8256a32f0009a8998bcde10c..e47a35edccd62ea89286384128373c59832bccae 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Friendica\Test\Util;
 
+use Friendica\Core\L10n;
 use Mockery\MockInterface;
 
 trait L10nMockTrait
@@ -21,7 +22,7 @@ trait L10nMockTrait
        public function mockL10nT($input = null, $times = null, $return = null)
        {
                if (!isset($this->l10nMock)) {
-                       $this->l10nMock = \Mockery::mock('alias:Friendica\Core\L10n');
+                       $this->l10nMock = \Mockery::mock('alias:' . L10n::class);
                }
 
                $with = isset($input) ? $input : \Mockery::any();
index bea0fe16fc24db01e00e969b2455982fe3b03003..f4e05f39b8a1e7597f510aad06fbaf57cd0745a3 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Friendica\Test\Util;
 
+use Friendica\Core\Renderer;
 use Mockery\MockInterface;
 
 trait RendererMockTrait
@@ -21,7 +22,7 @@ trait RendererMockTrait
        public function mockGetMarkupTemplate($templateName, $return = '', $times = null)
        {
                if (!isset($this->rendererMock)) {
-                       $this->rendererMock = \Mockery::mock('alias:Friendica\Core\Renderer');
+                       $this->rendererMock = \Mockery::mock('alias:' . Renderer::class);
                }
 
                $this->rendererMock
@@ -42,7 +43,7 @@ trait RendererMockTrait
        public function mockReplaceMacros($template, $args = [], $return = '', $times = null)
        {
                if (!isset($this->rendererMock)) {
-                       $this->rendererMock = \Mockery::mock('alias:Friendica\Core\Renderer');
+                       $this->rendererMock = \Mockery::mock('alias:' . Renderer::class);
                }
 
                $this->rendererMock
index 579b28e026b4a94ff1623c5e4710a65472d27c00..ef50c19b7271a895acf592486522fb990810facf 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Friendica\Test\src\Core\Console;
 
+use Friendica\App\Mode;
 use Friendica\Core\Console\Config;
 
 /**
@@ -16,12 +17,12 @@ class ConfigConsoleTest extends ConsoleTest
                parent::setUp();
 
                \Mockery::getConfiguration()->setConstantsMap([
-                       'Friendica\App\Mode' => [
+                       Mode::class => [
                                'DBCONFIGAVAILABLE' => 0
                        ]
                ]);
 
-               $mode = \Mockery::mock('Friendica\App\Mode');
+               $mode = \Mockery::mock(Mode::class);
                $mode
                        ->shouldReceive('has')
                        ->andReturn(true);
index c1a003bade6d0ba374ca5b61056112afbf404b3e..e56596c6c090b67fc0574d9c0041d74723173da9 100644 (file)
@@ -3,9 +3,12 @@
 // this is in the same namespace as Install for mocking 'function_exists'
 namespace Friendica\Core;
 
+use Friendica\Network\CurlResult;
+use Friendica\Object\Image;
 use Friendica\Test\MockedTest;
 use Friendica\Test\Util\L10nMockTrait;
 use Friendica\Test\Util\VFSTrait;
+use Friendica\Util\Network;
 
 /**
  * @runTestsInSeparateProcesses
@@ -248,7 +251,7 @@ class InstallerTest extends MockedTest
                $this->mockL10nT();
 
                // Mocking the CURL Response
-               $curlResult = \Mockery::mock('Friendica\Network\CurlResult');
+               $curlResult = \Mockery::mock(CurlResult::class);
                $curlResult
                        ->shouldReceive('getReturnCode')
                        ->andReturn('404');
@@ -260,7 +263,7 @@ class InstallerTest extends MockedTest
                        ->andReturn('test Error');
 
                // Mocking the CURL Request
-               $networkMock = \Mockery::mock('alias:Friendica\Util\Network');
+               $networkMock = \Mockery::mock('alias:' . Network::class);
                $networkMock
                        ->shouldReceive('fetchUrlFull')
                        ->with('https://test/install/testrewrite')
@@ -287,19 +290,19 @@ class InstallerTest extends MockedTest
                $this->mockL10nT();
 
                // Mocking the failed CURL Response
-               $curlResultF = \Mockery::mock('Friendica\Network\CurlResult');
+               $curlResultF = \Mockery::mock(CurlResult::class);
                $curlResultF
                        ->shouldReceive('getReturnCode')
                        ->andReturn('404');
 
                // Mocking the working CURL Response
-               $curlResultW = \Mockery::mock('Friendica\Network\CurlResult');
+               $curlResultW = \Mockery::mock(CurlResult::class);
                $curlResultW
                        ->shouldReceive('getReturnCode')
                        ->andReturn('204');
 
                // Mocking the CURL Request
-               $networkMock = \Mockery::mock('alias:Friendica\Util\Network');
+               $networkMock = \Mockery::mock('alias:' . Network::class);
                $networkMock
                        ->shouldReceive('fetchUrlFull')
                        ->with('https://test/install/testrewrite')
@@ -327,7 +330,7 @@ class InstallerTest extends MockedTest
        {
                $this->mockL10nT();
 
-               $imageMock = \Mockery::mock('alias:Friendica\Object\Image');
+               $imageMock = \Mockery::mock('alias:'. Image::class);
                $imageMock
                        ->shouldReceive('supportedTypes')
                        ->andReturn(['image/gif' => 'gif']);
@@ -354,7 +357,7 @@ class InstallerTest extends MockedTest
        {
                $this->mockL10nT();
 
-               $imageMock = \Mockery::mock('alias:Friendica\Object\Image');
+               $imageMock = \Mockery::mock('alias:' . Image::class);
                $imageMock
                        ->shouldReceive('supportedTypes')
                        ->andReturn([]);
index 4a84c40bb5a9bfb36103d402197417fd7b4a6b4d..8ee3c82d8efe3fd5ebabcbdca3e3439af190e5a8 100644 (file)
@@ -4,6 +4,7 @@ namespace src\Util\Logger;
 
 use Friendica\Test\MockedTest;
 use Friendica\Util\Logger\WorkerLogger;
+use Psr\Log\LoggerInterface;
 
 class WorkerLoggerTest extends MockedTest
 {
@@ -18,7 +19,7 @@ class WorkerLoggerTest extends MockedTest
         */
        public function testGetWorkerIdZero()
        {
-               $logger = \Mockery::mock('Psr\Log\LoggerInterface');
+               $logger = \Mockery::mock(LoggerInterface::class);
                $logger
                        ->shouldReceive('alert')
                        ->with('id length must be greater than 0.')
@@ -31,7 +32,7 @@ class WorkerLoggerTest extends MockedTest
         */
        public function testGetWorkerId()
        {
-               $logger = \Mockery::mock('Psr\Log\LoggerInterface');
+               $logger = \Mockery::mock(LoggerInterface::class);
                for ($i = 1; $i < 14; $i++) {
                        $workLogger = new WorkerLogger($logger, 'test', $i);
                        $uid = $workLogger->getWorkerId();
@@ -86,7 +87,7 @@ class WorkerLoggerTest extends MockedTest
         */
        public function testEmergency($func, $msg, $context = [])
        {
-               $logger = \Mockery::mock('Psr\Log\LoggerInterface');
+               $logger = \Mockery::mock(LoggerInterface::class);
                $workLogger = new WorkerLogger($logger, 'test');
                $testContext = $context;
                $testContext['worker_id'] = $workLogger->getWorkerId();
@@ -104,7 +105,7 @@ class WorkerLoggerTest extends MockedTest
         */
        public function testLog()
        {
-               $logger = \Mockery::mock('Psr\Log\LoggerInterface');
+               $logger = \Mockery::mock(LoggerInterface::class);
                $workLogger = new WorkerLogger($logger, 'test');
                $context = $testContext = ['test' => 'it'];
                $testContext['worker_id'] = $workLogger->getWorkerId();
index 449ec5e5ff1a18d75508ee508dd23f6c2fc8d0b4..af2e985092be462358e443a3947942f4c48db388 100644 (file)
@@ -18,7 +18,7 @@ class ProfilerTest extends MockedTest
        {
                parent::setUp();
 
-               $this->logger = \Mockery::mock('Psr\Log\LoggerInterface');
+               $this->logger = \Mockery::mock(LoggerInterface::class);
        }
 
        /**