Replace string namespaces with ::class

This commit is contained in:
Philipp Holzer 2019-02-24 13:40:54 +01:00
parent 9f11476ca0
commit 5fc42a744e
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
11 changed files with 52 additions and 26 deletions

View file

@ -20,6 +20,16 @@ use Psr\Log\LogLevel;
*/ */
class LoggerFactory 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 * 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\PsrLogMessageProcessor());
$logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor()); $logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor());
$logger->pushProcessor(new Monolog\Processor\UidProcessor()); $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'); $debugging = $config->get('system', 'debugging');
$stream = $config->get('system', 'logfile'); $stream = $config->get('system', 'logfile');
@ -79,7 +89,7 @@ class LoggerFactory
$logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor()); $logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor());
$logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor()); $logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor());
$logger->pushProcessor(new Monolog\Processor\UidProcessor()); $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)); $logger->pushHandler(new FriendicaDevelopHandler($developerIp));
@ -146,6 +156,13 @@ class LoggerFactory
if (!is_int($loglevel)) { if (!is_int($loglevel)) {
$loglevel = LogLevel::NOTICE; $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); $fileHandler = new Monolog\Handler\StreamHandler($stream, $loglevel);
$formatter = new Monolog\Formatter\LineFormatter("%datetime% %channel% [%level_name%]: %message% %context% %extra%\n"); $formatter = new Monolog\Formatter\LineFormatter("%datetime% %channel% [%level_name%]: %message% %context% %extra%\n");

View file

@ -17,9 +17,9 @@ class ProfilerFactory
public static function create(IConfigCache $configCache) public static function create(IConfigCache $configCache)
{ {
$enabled = $configCache->get('system', 'profiler'); $enabled = $configCache->get('system', 'profiler');
$enabled = isset($enabled) && $enabled !== '!<unset>!'; $enabled = isset($enabled) && $enabled !== '0';
$renderTime = $configCache->get('rendertime', 'callstack'); $renderTime = $configCache->get('rendertime', 'callstack');
$renderTime = isset($renderTime) && $renderTime !== '!<unset>!'; $renderTime = isset($renderTime) && $renderTime !== '0';
return new Profiler($enabled, $renderTime); return new Profiler($enabled, $renderTime);
} }

View file

@ -2,6 +2,7 @@
namespace Friendica\Test\Util; namespace Friendica\Test\Util;
use Friendica\Database\DBA;
use Mockery\MockInterface; use Mockery\MockInterface;
class DBAStub class DBAStub
@ -22,7 +23,7 @@ trait DBAMockTrait
private function checkMock() private function checkMock()
{ {
if (!isset($this->dbaMock)) { if (!isset($this->dbaMock)) {
$this->dbaMock = \Mockery::namedMock('Friendica\Database\DBA', 'Friendica\Test\Util\DBAStub'); $this->dbaMock = \Mockery::namedMock(DBA::class, DBAStub::class);
} }
} }

View file

@ -26,7 +26,7 @@ trait DBStructureMockTrait
public function mockUpdate($args = [], $return = true, $times = null) public function mockUpdate($args = [], $return = true, $times = null)
{ {
if (!isset($this->dbStructure)) { if (!isset($this->dbStructure)) {
$this->dbStructure = \Mockery::mock('alias:Friendica\Database\DBStructure'); $this->dbStructure = \Mockery::mock('alias:' . DBStructure::class);
} }
$this->dbStructure $this->dbStructure
@ -46,7 +46,7 @@ trait DBStructureMockTrait
public function mockExistsTable($tableName, $return = true, $times = null) public function mockExistsTable($tableName, $return = true, $times = null)
{ {
if (!isset($this->dbStructure)) { if (!isset($this->dbStructure)) {
$this->dbStructure = \Mockery::mock('alias:Friendica\Database\DBStructure'); $this->dbStructure = \Mockery::mock('alias:' . DBStructure::class);
} }
$this->dbStructure $this->dbStructure

View file

@ -2,6 +2,7 @@
namespace Friendica\Test\Util; namespace Friendica\Test\Util;
use Friendica\Util\DateTimeFormat;
use Mockery\MockInterface; use Mockery\MockInterface;
trait DateTimeFormatMockTrait trait DateTimeFormatMockTrait
@ -14,7 +15,7 @@ trait DateTimeFormatMockTrait
public function mockUtcNow($time, $times = null) public function mockUtcNow($time, $times = null)
{ {
if (!isset($this->dtfMock)) { if (!isset($this->dtfMock)) {
$this->dtfMock = \Mockery::mock('alias:Friendica\Util\DateTimeFormat'); $this->dtfMock = \Mockery::mock('alias:'. DateTimeFormat::class);
} }
$this->dtfMock $this->dtfMock
@ -26,7 +27,7 @@ trait DateTimeFormatMockTrait
public function mockUtc($input, $time, $times = null) public function mockUtc($input, $time, $times = null)
{ {
if (!isset($this->dtfMock)) { if (!isset($this->dtfMock)) {
$this->dtfMock = \Mockery::mock('alias:Friendica\Util\DateTimeFormat'); $this->dtfMock = \Mockery::mock('alias:' . DateTimeFormat::class);
} }
$this->dtfMock $this->dtfMock

View file

@ -2,6 +2,7 @@
namespace Friendica\Test\Util; namespace Friendica\Test\Util;
use Friendica\Core\L10n;
use Mockery\MockInterface; use Mockery\MockInterface;
trait L10nMockTrait trait L10nMockTrait
@ -21,7 +22,7 @@ trait L10nMockTrait
public function mockL10nT($input = null, $times = null, $return = null) public function mockL10nT($input = null, $times = null, $return = null)
{ {
if (!isset($this->l10nMock)) { 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(); $with = isset($input) ? $input : \Mockery::any();

View file

@ -2,6 +2,7 @@
namespace Friendica\Test\Util; namespace Friendica\Test\Util;
use Friendica\Core\Renderer;
use Mockery\MockInterface; use Mockery\MockInterface;
trait RendererMockTrait trait RendererMockTrait
@ -21,7 +22,7 @@ trait RendererMockTrait
public function mockGetMarkupTemplate($templateName, $return = '', $times = null) public function mockGetMarkupTemplate($templateName, $return = '', $times = null)
{ {
if (!isset($this->rendererMock)) { if (!isset($this->rendererMock)) {
$this->rendererMock = \Mockery::mock('alias:Friendica\Core\Renderer'); $this->rendererMock = \Mockery::mock('alias:' . Renderer::class);
} }
$this->rendererMock $this->rendererMock
@ -42,7 +43,7 @@ trait RendererMockTrait
public function mockReplaceMacros($template, $args = [], $return = '', $times = null) public function mockReplaceMacros($template, $args = [], $return = '', $times = null)
{ {
if (!isset($this->rendererMock)) { if (!isset($this->rendererMock)) {
$this->rendererMock = \Mockery::mock('alias:Friendica\Core\Renderer'); $this->rendererMock = \Mockery::mock('alias:' . Renderer::class);
} }
$this->rendererMock $this->rendererMock

View file

@ -2,6 +2,7 @@
namespace Friendica\Test\src\Core\Console; namespace Friendica\Test\src\Core\Console;
use Friendica\App\Mode;
use Friendica\Core\Console\Config; use Friendica\Core\Console\Config;
/** /**
@ -16,12 +17,12 @@ class ConfigConsoleTest extends ConsoleTest
parent::setUp(); parent::setUp();
\Mockery::getConfiguration()->setConstantsMap([ \Mockery::getConfiguration()->setConstantsMap([
'Friendica\App\Mode' => [ Mode::class => [
'DBCONFIGAVAILABLE' => 0 'DBCONFIGAVAILABLE' => 0
] ]
]); ]);
$mode = \Mockery::mock('Friendica\App\Mode'); $mode = \Mockery::mock(Mode::class);
$mode $mode
->shouldReceive('has') ->shouldReceive('has')
->andReturn(true); ->andReturn(true);

View file

@ -3,9 +3,12 @@
// this is in the same namespace as Install for mocking 'function_exists' // this is in the same namespace as Install for mocking 'function_exists'
namespace Friendica\Core; namespace Friendica\Core;
use Friendica\Network\CurlResult;
use Friendica\Object\Image;
use Friendica\Test\MockedTest; use Friendica\Test\MockedTest;
use Friendica\Test\Util\L10nMockTrait; use Friendica\Test\Util\L10nMockTrait;
use Friendica\Test\Util\VFSTrait; use Friendica\Test\Util\VFSTrait;
use Friendica\Util\Network;
/** /**
* @runTestsInSeparateProcesses * @runTestsInSeparateProcesses
@ -248,7 +251,7 @@ class InstallerTest extends MockedTest
$this->mockL10nT(); $this->mockL10nT();
// Mocking the CURL Response // Mocking the CURL Response
$curlResult = \Mockery::mock('Friendica\Network\CurlResult'); $curlResult = \Mockery::mock(CurlResult::class);
$curlResult $curlResult
->shouldReceive('getReturnCode') ->shouldReceive('getReturnCode')
->andReturn('404'); ->andReturn('404');
@ -260,7 +263,7 @@ class InstallerTest extends MockedTest
->andReturn('test Error'); ->andReturn('test Error');
// Mocking the CURL Request // Mocking the CURL Request
$networkMock = \Mockery::mock('alias:Friendica\Util\Network'); $networkMock = \Mockery::mock('alias:' . Network::class);
$networkMock $networkMock
->shouldReceive('fetchUrlFull') ->shouldReceive('fetchUrlFull')
->with('https://test/install/testrewrite') ->with('https://test/install/testrewrite')
@ -287,19 +290,19 @@ class InstallerTest extends MockedTest
$this->mockL10nT(); $this->mockL10nT();
// Mocking the failed CURL Response // Mocking the failed CURL Response
$curlResultF = \Mockery::mock('Friendica\Network\CurlResult'); $curlResultF = \Mockery::mock(CurlResult::class);
$curlResultF $curlResultF
->shouldReceive('getReturnCode') ->shouldReceive('getReturnCode')
->andReturn('404'); ->andReturn('404');
// Mocking the working CURL Response // Mocking the working CURL Response
$curlResultW = \Mockery::mock('Friendica\Network\CurlResult'); $curlResultW = \Mockery::mock(CurlResult::class);
$curlResultW $curlResultW
->shouldReceive('getReturnCode') ->shouldReceive('getReturnCode')
->andReturn('204'); ->andReturn('204');
// Mocking the CURL Request // Mocking the CURL Request
$networkMock = \Mockery::mock('alias:Friendica\Util\Network'); $networkMock = \Mockery::mock('alias:' . Network::class);
$networkMock $networkMock
->shouldReceive('fetchUrlFull') ->shouldReceive('fetchUrlFull')
->with('https://test/install/testrewrite') ->with('https://test/install/testrewrite')
@ -327,7 +330,7 @@ class InstallerTest extends MockedTest
{ {
$this->mockL10nT(); $this->mockL10nT();
$imageMock = \Mockery::mock('alias:Friendica\Object\Image'); $imageMock = \Mockery::mock('alias:'. Image::class);
$imageMock $imageMock
->shouldReceive('supportedTypes') ->shouldReceive('supportedTypes')
->andReturn(['image/gif' => 'gif']); ->andReturn(['image/gif' => 'gif']);
@ -354,7 +357,7 @@ class InstallerTest extends MockedTest
{ {
$this->mockL10nT(); $this->mockL10nT();
$imageMock = \Mockery::mock('alias:Friendica\Object\Image'); $imageMock = \Mockery::mock('alias:' . Image::class);
$imageMock $imageMock
->shouldReceive('supportedTypes') ->shouldReceive('supportedTypes')
->andReturn([]); ->andReturn([]);

View file

@ -4,6 +4,7 @@ namespace src\Util\Logger;
use Friendica\Test\MockedTest; use Friendica\Test\MockedTest;
use Friendica\Util\Logger\WorkerLogger; use Friendica\Util\Logger\WorkerLogger;
use Psr\Log\LoggerInterface;
class WorkerLoggerTest extends MockedTest class WorkerLoggerTest extends MockedTest
{ {
@ -18,7 +19,7 @@ class WorkerLoggerTest extends MockedTest
*/ */
public function testGetWorkerIdZero() public function testGetWorkerIdZero()
{ {
$logger = \Mockery::mock('Psr\Log\LoggerInterface'); $logger = \Mockery::mock(LoggerInterface::class);
$logger $logger
->shouldReceive('alert') ->shouldReceive('alert')
->with('id length must be greater than 0.') ->with('id length must be greater than 0.')
@ -31,7 +32,7 @@ class WorkerLoggerTest extends MockedTest
*/ */
public function testGetWorkerId() public function testGetWorkerId()
{ {
$logger = \Mockery::mock('Psr\Log\LoggerInterface'); $logger = \Mockery::mock(LoggerInterface::class);
for ($i = 1; $i < 14; $i++) { for ($i = 1; $i < 14; $i++) {
$workLogger = new WorkerLogger($logger, 'test', $i); $workLogger = new WorkerLogger($logger, 'test', $i);
$uid = $workLogger->getWorkerId(); $uid = $workLogger->getWorkerId();
@ -86,7 +87,7 @@ class WorkerLoggerTest extends MockedTest
*/ */
public function testEmergency($func, $msg, $context = []) public function testEmergency($func, $msg, $context = [])
{ {
$logger = \Mockery::mock('Psr\Log\LoggerInterface'); $logger = \Mockery::mock(LoggerInterface::class);
$workLogger = new WorkerLogger($logger, 'test'); $workLogger = new WorkerLogger($logger, 'test');
$testContext = $context; $testContext = $context;
$testContext['worker_id'] = $workLogger->getWorkerId(); $testContext['worker_id'] = $workLogger->getWorkerId();
@ -104,7 +105,7 @@ class WorkerLoggerTest extends MockedTest
*/ */
public function testLog() public function testLog()
{ {
$logger = \Mockery::mock('Psr\Log\LoggerInterface'); $logger = \Mockery::mock(LoggerInterface::class);
$workLogger = new WorkerLogger($logger, 'test'); $workLogger = new WorkerLogger($logger, 'test');
$context = $testContext = ['test' => 'it']; $context = $testContext = ['test' => 'it'];
$testContext['worker_id'] = $workLogger->getWorkerId(); $testContext['worker_id'] = $workLogger->getWorkerId();

View file

@ -18,7 +18,7 @@ class ProfilerTest extends MockedTest
{ {
parent::setUp(); parent::setUp();
$this->logger = \Mockery::mock('Psr\Log\LoggerInterface'); $this->logger = \Mockery::mock(LoggerInterface::class);
} }
/** /**