From 56ae87c281d2f54b23f98acf0e138d8e72196a06 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Apr 2021 14:26:43 +0200 Subject: Less ILogger Signed-off-by: Joas Schilling --- lib/private/App/AppManager.php | 18 +++------ lib/private/App/AppStore/Fetcher/AppFetcher.php | 17 +++----- .../App/AppStore/Fetcher/CategoryFetcher.php | 11 +----- lib/private/App/AppStore/Fetcher/Fetcher.php | 18 ++++----- lib/private/AppFramework/Bootstrap/Coordinator.php | 11 +++--- .../AppFramework/Bootstrap/RegistrationContext.php | 46 +++++++++------------- .../Middleware/Security/SecurityMiddleware.php | 11 +++--- lib/private/Avatar/Avatar.php | 11 ++---- lib/private/Avatar/AvatarManager.php | 16 ++------ lib/private/Avatar/GuestAvatar.php | 6 +-- lib/private/Avatar/PlaceholderAvatar.php | 6 +-- lib/private/Avatar/UserAvatar.php | 6 +-- lib/private/CapabilitiesManager.php | 12 +++--- .../Collaboration/Collaborators/LookupPlugin.php | 11 +++--- lib/private/Collaboration/Resources/Manager.php | 6 +-- .../Collaboration/Resources/ProviderManager.php | 10 ++--- lib/private/Console/Application.php | 17 +++----- lib/private/InitialStateService.php | 11 +++--- lib/private/Installer.php | 17 +++----- lib/private/Setup.php | 17 ++------ lib/private/Setup/AbstractDatabase.php | 6 +-- lib/private/Setup/MySQL.php | 15 +++---- lib/private/Updater.php | 27 +++++++------ 23 files changed, 127 insertions(+), 199 deletions(-) (limited to 'lib/private') diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 7063878429a..a00a93aa847 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -46,9 +46,9 @@ use OCP\ICacheFactory; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; -use OCP\ILogger; use OCP\IUser; use OCP\IUserSession; +use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; class AppManager implements IAppManager { @@ -83,7 +83,7 @@ class AppManager implements IAppManager { /** @var EventDispatcherInterface */ private $dispatcher; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var string[] $appId => $enabled */ @@ -104,21 +104,13 @@ class AppManager implements IAppManager { /** @var array */ private $autoDisabledApps = []; - /** - * @param IUserSession $userSession - * @param IConfig $config - * @param AppConfig $appConfig - * @param IGroupManager $groupManager - * @param ICacheFactory $memCacheFactory - * @param EventDispatcherInterface $dispatcher - */ public function __construct(IUserSession $userSession, IConfig $config, AppConfig $appConfig, IGroupManager $groupManager, ICacheFactory $memCacheFactory, EventDispatcherInterface $dispatcher, - ILogger $logger) { + LoggerInterface $logger) { $this->userSession = $userSession; $this->config = $config; $this->appConfig = $appConfig; @@ -249,7 +241,7 @@ class AppManager implements IAppManager { if (!is_array($groupIds)) { $jsonError = json_last_error(); - $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); + $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError); return false; } @@ -282,7 +274,7 @@ class AppManager implements IAppManager { if (!is_array($groupIds)) { $jsonError = json_last_error(); - $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); + $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError); return false; } diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index 416e55463cf..cd6b005c0d1 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -37,6 +37,7 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\Http\Client\IClientService; use OCP\IConfig; use OCP\ILogger; +use Psr\Log\LoggerInterface; class AppFetcher extends Fetcher { @@ -46,20 +47,12 @@ class AppFetcher extends Fetcher { /** @var bool */ private $ignoreMaxVersion; - /** - * @param Factory $appDataFactory - * @param IClientService $clientService - * @param ITimeFactory $timeFactory - * @param IConfig $config - * @param CompareVersion $compareVersion - * @param ILogger $logger - */ public function __construct(Factory $appDataFactory, IClientService $clientService, ITimeFactory $timeFactory, IConfig $config, CompareVersion $compareVersion, - ILogger $logger) { + LoggerInterface $logger) { parent::__construct( $appDataFactory, $clientService, @@ -86,7 +79,7 @@ class AppFetcher extends Fetcher { protected function fetch($ETag, $content, $allowUnstable = false) { /** @var mixed[] $response */ $response = parent::fetch($ETag, $content); - + if (empty($response)) { return []; } @@ -134,7 +127,9 @@ class AppFetcher extends Fetcher { $releases[] = $release; } } catch (\InvalidArgumentException $e) { - $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::WARN]); + $this->logger->warning($e->getMessage(), [ + 'exception' => $e, + ]); } } } diff --git a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php index e34fbee8c58..896444a6640 100644 --- a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php +++ b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php @@ -31,21 +31,14 @@ use OC\Files\AppData\Factory; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Http\Client\IClientService; use OCP\IConfig; -use OCP\ILogger; +use Psr\Log\LoggerInterface; class CategoryFetcher extends Fetcher { - /** - * @param Factory $appDataFactory - * @param IClientService $clientService - * @param ITimeFactory $timeFactory - * @param IConfig $config - * @param ILogger $logger - */ public function __construct(Factory $appDataFactory, IClientService $clientService, ITimeFactory $timeFactory, IConfig $config, - ILogger $logger) { + LoggerInterface $logger) { parent::__construct( $appDataFactory, $clientService, diff --git a/lib/private/App/AppStore/Fetcher/Fetcher.php b/lib/private/App/AppStore/Fetcher/Fetcher.php index c5d83fcb1df..24c2fce00f5 100644 --- a/lib/private/App/AppStore/Fetcher/Fetcher.php +++ b/lib/private/App/AppStore/Fetcher/Fetcher.php @@ -39,7 +39,7 @@ use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\Http\Client\IClientService; use OCP\IConfig; -use OCP\ILogger; +use Psr\Log\LoggerInterface; abstract class Fetcher { public const INVALIDATE_AFTER_SECONDS = 3600; @@ -53,7 +53,7 @@ abstract class Fetcher { protected $timeFactory; /** @var IConfig */ protected $config; - /** @var Ilogger */ + /** @var LoggerInterface */ protected $logger; /** @var string */ protected $fileName; @@ -64,18 +64,11 @@ abstract class Fetcher { /** @var string */ protected $channel; - /** - * @param Factory $appDataFactory - * @param IClientService $clientService - * @param ITimeFactory $timeFactory - * @param IConfig $config - * @param ILogger $logger - */ public function __construct(Factory $appDataFactory, IClientService $clientService, ITimeFactory $timeFactory, IConfig $config, - ILogger $logger) { + LoggerInterface $logger) { $this->appData = $appDataFactory->get('appstore'); $this->clientService = $clientService; $this->timeFactory = $timeFactory; @@ -202,7 +195,10 @@ abstract class Fetcher { $this->logger->warning('Could not connect to appstore: ' . $e->getMessage(), ['app' => 'appstoreFetcher']); return []; } catch (\Exception $e) { - $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::WARN]); + $this->logger->warning($e->getMessage(), [ + 'exception' => $e, + 'app' => 'appstoreFetcher', + ]); return []; } } diff --git a/lib/private/AppFramework/Bootstrap/Coordinator.php b/lib/private/AppFramework/Bootstrap/Coordinator.php index 06a17e5242b..627618f04fa 100644 --- a/lib/private/AppFramework/Bootstrap/Coordinator.php +++ b/lib/private/AppFramework/Bootstrap/Coordinator.php @@ -36,8 +36,8 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\QueryException; use OCP\Dashboard\IManager; use OCP\EventDispatcher\IEventDispatcher; -use OCP\ILogger; use OCP\IServerContainer; +use Psr\Log\LoggerInterface; use Throwable; use function class_exists; use function class_implements; @@ -57,7 +57,7 @@ class Coordinator { /** @var IEventDispatcher */ private $eventDispatcher; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var RegistrationContext|null */ @@ -70,7 +70,7 @@ class Coordinator { Registry $registry, IManager $dashboardManager, IEventDispatcher $eventListener, - ILogger $logger) { + LoggerInterface $logger) { $this->serverContainer = $container; $this->registry = $registry; $this->dashboardManager = $dashboardManager; @@ -124,9 +124,8 @@ class Coordinator { try { $application->register($this->registrationContext->for($appId)); } catch (Throwable $e) { - $this->logger->logException($e, [ - 'message' => 'Error during app service registration: ' . $e->getMessage(), - 'level' => ILogger::FATAL, + $this->logger->emergency('Error during app service registration: ' . $e->getMessage(), [ + 'exception' => $e, ]); } } diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php index d056c088a9f..0859e606b7e 100644 --- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php +++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php @@ -43,10 +43,10 @@ use OCP\Dashboard\IWidget; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Template\ICustomTemplateProvider; use OCP\Http\WellKnown\IHandler; -use OCP\ILogger; use OCP\Notification\INotifier; use OCP\Search\IProvider; use OCP\Support\CrashReport\IReporter; +use Psr\Log\LoggerInterface; use Throwable; use function array_shift; @@ -97,10 +97,10 @@ class RegistrationContext { /** @var ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] */ private $twoFactorProviders = []; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; - public function __construct(ILogger $logger) { + public function __construct(LoggerInterface $logger) { $this->logger = $logger; } @@ -313,9 +313,8 @@ class RegistrationContext { ->registerCapability($registration->getService()); } catch (Throwable $e) { $appId = $registration->getAppId(); - $this->logger->logException($e, [ - 'message' => "Error during capability registration of $appId: " . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error("Error during capability registration of $appId: " . $e->getMessage(), [ + 'exception' => $e, ]); } } @@ -330,9 +329,8 @@ class RegistrationContext { $registry->registerLazy($registration->getService()); } catch (Throwable $e) { $appId = $registration->getAppId(); - $this->logger->logException($e, [ - 'message' => "Error during crash reporter registration of $appId: " . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error("Error during crash reporter registration of $appId: " . $e->getMessage(), [ + 'exception' => $e, ]); } } @@ -347,9 +345,8 @@ class RegistrationContext { $dashboardManager->lazyRegisterWidget($panel->getService()); } catch (Throwable $e) { $appId = $panel->getAppId(); - $this->logger->logException($e, [ - 'message' => "Error during dashboard registration of $appId: " . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error("Error during dashboard registration of $appId: " . $e->getMessage(), [ + 'exception' => $e, ]); } } @@ -365,9 +362,8 @@ class RegistrationContext { ); } catch (Throwable $e) { $appId = $registration->getAppId(); - $this->logger->logException($e, [ - 'message' => "Error during event listener registration of $appId: " . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error("Error during event listener registration of $appId: " . $e->getMessage(), [ + 'exception' => $e, ]); } } @@ -391,9 +387,8 @@ class RegistrationContext { ); } catch (Throwable $e) { $appId = $registration->getAppId(); - $this->logger->logException($e, [ - 'message' => "Error during service registration of $appId: " . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error("Error during service registration of $appId: " . $e->getMessage(), [ + 'exception' => $e, ]); } } @@ -408,9 +403,8 @@ class RegistrationContext { ); } catch (Throwable $e) { $appId = $registration->getAppId(); - $this->logger->logException($e, [ - 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error("Error during service alias registration of $appId: " . $e->getMessage(), [ + 'exception' => $e, ]); } } @@ -425,9 +419,8 @@ class RegistrationContext { ); } catch (Throwable $e) { $appId = $registration->getAppId(); - $this->logger->logException($e, [ - 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error("Error during service alias registration of $appId: " . $e->getMessage(), [ + 'exception' => $e, ]); } } @@ -444,9 +437,8 @@ class RegistrationContext { ->registerMiddleWare($middleware->getService()); } catch (Throwable $e) { $appId = $middleware->getAppId(); - $this->logger->logException($e, [ - 'message' => "Error during capability registration of $appId: " . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error("Error during capability registration of $appId: " . $e->getMessage(), [ + 'exception' => $e, ]); } } diff --git a/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php b/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php index 76665f8998f..9fa696154ff 100644 --- a/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php @@ -55,11 +55,11 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Middleware; use OCP\AppFramework\OCSController; use OCP\IL10N; -use OCP\ILogger; use OCP\INavigationManager; use OCP\IRequest; use OCP\IURLGenerator; use OCP\Util; +use Psr\Log\LoggerInterface; /** * Used to do all the authentication and checking stuff for a controller method @@ -78,7 +78,7 @@ class SecurityMiddleware extends Middleware { private $appName; /** @var IURLGenerator */ private $urlGenerator; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var bool */ private $isLoggedIn; @@ -95,7 +95,7 @@ class SecurityMiddleware extends Middleware { ControllerMethodReflector $reflector, INavigationManager $navigationManager, IURLGenerator $urlGenerator, - ILogger $logger, + LoggerInterface $logger, string $appName, bool $isLoggedIn, bool $isAdminUser, @@ -233,9 +233,8 @@ class SecurityMiddleware extends Middleware { } } - $this->logger->logException($exception, [ - 'level' => ILogger::DEBUG, - 'app' => 'core', + $this->logger->debug($exception->getMessage(), [ + 'exception' => $exception, ]); return $response; } diff --git a/lib/private/Avatar/Avatar.php b/lib/private/Avatar/Avatar.php index f716c567c79..bd40766afcb 100644 --- a/lib/private/Avatar/Avatar.php +++ b/lib/private/Avatar/Avatar.php @@ -43,14 +43,14 @@ use OC\Color; use OC_Image; use OCP\Files\NotFoundException; use OCP\IAvatar; -use OCP\ILogger; +use Psr\Log\LoggerInterface; /** * This class gets and sets users avatars. */ abstract class Avatar implements IAvatar { - /** @var ILogger */ + /** @var LoggerInterface */ protected $logger; /** @@ -69,12 +69,7 @@ abstract class Avatar implements IAvatar { {letter} '; - /** - * The base avatar constructor. - * - * @param ILogger $logger The logger - */ - public function __construct(ILogger $logger) { + public function __construct(LoggerInterface $logger) { $this->logger = $logger; } diff --git a/lib/private/Avatar/AvatarManager.php b/lib/private/Avatar/AvatarManager.php index 04d3a721022..c54539b2cde 100644 --- a/lib/private/Avatar/AvatarManager.php +++ b/lib/private/Avatar/AvatarManager.php @@ -45,8 +45,8 @@ use OCP\IAvatar; use OCP\IAvatarManager; use OCP\IConfig; use OCP\IL10N; -use OCP\ILogger; use OCP\IUserSession; +use Psr\Log\LoggerInterface; /** * This class implements methods to access Avatar functionality @@ -65,7 +65,7 @@ class AvatarManager implements IAvatarManager { /** @var IL10N */ private $l; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var IConfig */ @@ -77,22 +77,12 @@ class AvatarManager implements IAvatarManager { /** @var KnownUserService */ private $knownUserService; - /** - * AvatarManager constructor. - * - * @param Manager $userManager - * @param IAppData $appData - * @param IL10N $l - * @param ILogger $logger - * @param IConfig $config - * @param IUserSession $userSession - */ public function __construct( IUserSession $userSession, Manager $userManager, IAppData $appData, IL10N $l, - ILogger $logger, + LoggerInterface $logger, IConfig $config, IAccountManager $accountManager, KnownUserService $knownUserService diff --git a/lib/private/Avatar/GuestAvatar.php b/lib/private/Avatar/GuestAvatar.php index cc7e21b9fe6..c208353d726 100644 --- a/lib/private/Avatar/GuestAvatar.php +++ b/lib/private/Avatar/GuestAvatar.php @@ -27,7 +27,7 @@ declare(strict_types=1); namespace OC\Avatar; use OCP\Files\SimpleFS\InMemoryFile; -use OCP\ILogger; +use Psr\Log\LoggerInterface; /** * This class represents a guest user's avatar. @@ -44,9 +44,9 @@ class GuestAvatar extends Avatar { * GuestAvatar constructor. * * @param string $userDisplayName The guest user display name - * @param ILogger $logger The logger + * @param LoggerInterface $logger The logger */ - public function __construct(string $userDisplayName, ILogger $logger) { + public function __construct(string $userDisplayName, LoggerInterface $logger) { parent::__construct($logger); $this->userDisplayName = $userDisplayName; } diff --git a/lib/private/Avatar/PlaceholderAvatar.php b/lib/private/Avatar/PlaceholderAvatar.php index 5883fe531a3..377b5e03654 100644 --- a/lib/private/Avatar/PlaceholderAvatar.php +++ b/lib/private/Avatar/PlaceholderAvatar.php @@ -38,7 +38,7 @@ use OCP\Files\SimpleFS\ISimpleFolder; use OCP\IConfig; use OCP\IImage; use OCP\IL10N; -use OCP\ILogger; +use Psr\Log\LoggerInterface; /** * This class represents a registered user's placeholder avatar. @@ -60,12 +60,12 @@ class PlaceholderAvatar extends Avatar { * @param ISimpleFolder $folder The avatar files folder * @param IL10N $l The localization helper * @param User $user The user this class manages the avatar for - * @param ILogger $logger The logger + * @param LoggerInterface $logger The logger */ public function __construct( ISimpleFolder $folder, $user, - ILogger $logger) { + LoggerInterface $logger) { parent::__construct($logger); $this->folder = $folder; diff --git a/lib/private/Avatar/UserAvatar.php b/lib/private/Avatar/UserAvatar.php index f47809425ed..970548f8c8e 100644 --- a/lib/private/Avatar/UserAvatar.php +++ b/lib/private/Avatar/UserAvatar.php @@ -39,7 +39,7 @@ use OCP\Files\SimpleFS\ISimpleFolder; use OCP\IConfig; use OCP\IImage; use OCP\IL10N; -use OCP\ILogger; +use Psr\Log\LoggerInterface; /** * This class represents a registered user's avatar. @@ -64,13 +64,13 @@ class UserAvatar extends Avatar { * @param ISimpleFolder $folder The avatar files folder * @param IL10N $l The localization helper * @param User $user The user this class manages the avatar for - * @param ILogger $logger The logger + * @param LoggerInterface $logger The logger */ public function __construct( ISimpleFolder $folder, IL10N $l, $user, - ILogger $logger, + LoggerInterface $logger, IConfig $config) { parent::__construct($logger); $this->folder = $folder; diff --git a/lib/private/CapabilitiesManager.php b/lib/private/CapabilitiesManager.php index 6a4d97ad159..efa1cff5146 100644 --- a/lib/private/CapabilitiesManager.php +++ b/lib/private/CapabilitiesManager.php @@ -32,17 +32,17 @@ namespace OC; use OCP\AppFramework\QueryException; use OCP\Capabilities\ICapability; use OCP\Capabilities\IPublicCapability; -use OCP\ILogger; +use Psr\Log\LoggerInterface; class CapabilitiesManager { /** @var \Closure[] */ private $capabilities = []; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; - public function __construct(ILogger $logger) { + public function __construct(LoggerInterface $logger) { $this->logger = $logger; } @@ -59,10 +59,8 @@ class CapabilitiesManager { try { $c = $capability(); } catch (QueryException $e) { - $this->logger->logException($e, [ - 'message' => 'CapabilitiesManager', - 'level' => ILogger::ERROR, - 'app' => 'core', + $this->logger->error('CapabilitiesManager', [ + 'exception' => $e, ]); continue; } diff --git a/lib/private/Collaboration/Collaborators/LookupPlugin.php b/lib/private/Collaboration/Collaborators/LookupPlugin.php index f675cece99e..3d118989cc6 100644 --- a/lib/private/Collaboration/Collaborators/LookupPlugin.php +++ b/lib/private/Collaboration/Collaborators/LookupPlugin.php @@ -33,9 +33,9 @@ use OCP\Collaboration\Collaborators\SearchResultType; use OCP\Federation\ICloudIdManager; use OCP\Http\Client\IClientService; use OCP\IConfig; -use OCP\ILogger; use OCP\IUserSession; use OCP\Share\IShare; +use Psr\Log\LoggerInterface; class LookupPlugin implements ISearchPlugin { @@ -47,14 +47,14 @@ class LookupPlugin implements ISearchPlugin { private $currentUserRemote; /** @var ICloudIdManager */ private $cloudIdManager; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; public function __construct(IConfig $config, IClientService $clientService, IUserSession $userSession, ICloudIdManager $cloudIdManager, - ILogger $logger) { + LoggerInterface $logger) { $this->config = $config; $this->clientService = $clientService; $this->cloudIdManager = $cloudIdManager; @@ -96,8 +96,9 @@ class LookupPlugin implements ISearchPlugin { try { $remote = $this->cloudIdManager->resolveCloudId($lookup['federationId'])->getRemote(); } catch (\Exception $e) { - $this->logger->error('Can not parse federated cloud ID "' . $lookup['federationId'] . '"'); - $this->logger->error($e->getMessage()); + $this->logger->error('Can not parse federated cloud ID "' . $lookup['federationId'] . '"', [ + 'exception' => $e, + ]); continue; } if ($this->currentUserRemote === $remote) { diff --git a/lib/private/Collaboration/Resources/Manager.php b/lib/private/Collaboration/Resources/Manager.php index 97213c45669..a84ca4da241 100644 --- a/lib/private/Collaboration/Resources/Manager.php +++ b/lib/private/Collaboration/Resources/Manager.php @@ -38,8 +38,8 @@ use OCP\Collaboration\Resources\IResource; use OCP\Collaboration\Resources\ResourceException; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; -use OCP\ILogger; use OCP\IUser; +use Psr\Log\LoggerInterface; class Manager implements IManager { public const TABLE_COLLECTIONS = 'collres_collections'; @@ -50,14 +50,14 @@ class Manager implements IManager { protected $connection; /** @var IProviderManager */ protected $providerManager; - /** @var ILogger */ + /** @var LoggerInterface */ protected $logger; /** @var string[] */ protected $providers = []; - public function __construct(IDBConnection $connection, IProviderManager $providerManager, ILogger $logger) { + public function __construct(IDBConnection $connection, IProviderManager $providerManager, LoggerInterface $logger) { $this->connection = $connection; $this->providerManager = $providerManager; $this->logger = $logger; diff --git a/lib/private/Collaboration/Resources/ProviderManager.php b/lib/private/Collaboration/Resources/ProviderManager.php index 095ffdcd8ee..71e7d8b7e2e 100644 --- a/lib/private/Collaboration/Resources/ProviderManager.php +++ b/lib/private/Collaboration/Resources/ProviderManager.php @@ -29,8 +29,8 @@ namespace OC\Collaboration\Resources; use OCP\AppFramework\QueryException; use OCP\Collaboration\Resources\IProvider; use OCP\Collaboration\Resources\IProviderManager; -use OCP\ILogger; use OCP\IServerContainer; +use Psr\Log\LoggerInterface; class ProviderManager implements IProviderManager { @@ -43,10 +43,10 @@ class ProviderManager implements IProviderManager { /** @var IServerContainer */ protected $serverContainer; - /** @var ILogger */ + /** @var LoggerInterface */ protected $logger; - public function __construct(IServerContainer $serverContainer, ILogger $logger) { + public function __construct(IServerContainer $serverContainer, LoggerInterface $logger) { $this->serverContainer = $serverContainer; $this->logger = $logger; } @@ -57,8 +57,8 @@ class ProviderManager implements IProviderManager { try { $this->providerInstances[] = $this->serverContainer->query($provider); } catch (QueryException $e) { - $this->logger->logException($e, [ - 'message' => "Could not query resource provider $provider: " . $e->getMessage() + $this->logger->error("Could not query resource provider $provider: " . $e->getMessage(), [ + 'exception' => $e, ]); } } diff --git a/lib/private/Console/Application.php b/lib/private/Console/Application.php index 9b1cc57aed3..06edf62147e 100644 --- a/lib/private/Console/Application.php +++ b/lib/private/Console/Application.php @@ -37,8 +37,8 @@ use OC_App; use OCP\AppFramework\QueryException; use OCP\Console\ConsoleEvent; use OCP\IConfig; -use OCP\ILogger; use OCP\IRequest; +use Psr\Log\LoggerInterface; use Symfony\Component\Console\Application as SymfonyApplication; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -53,22 +53,15 @@ class Application { private $dispatcher; /** @var IRequest */ private $request; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var MemoryInfo */ private $memoryInfo; - /** - * @param IConfig $config - * @param EventDispatcherInterface $dispatcher - * @param IRequest $request - * @param ILogger $logger - * @param MemoryInfo $memoryInfo - */ public function __construct(IConfig $config, EventDispatcherInterface $dispatcher, IRequest $request, - ILogger $logger, + LoggerInterface $logger, MemoryInfo $memoryInfo) { $defaults = \OC::$server->getThemingDefaults(); $this->config = $config; @@ -142,7 +135,9 @@ class Application { try { require $file; } catch (\Exception $e) { - $this->logger->logException($e); + $this->logger->error($e->getMessage(), [ + 'exception' => $e, + ]); } } } diff --git a/lib/private/InitialStateService.php b/lib/private/InitialStateService.php index bbc893269f7..38de49b4780 100644 --- a/lib/private/InitialStateService.php +++ b/lib/private/InitialStateService.php @@ -33,12 +33,12 @@ use OC\AppFramework\Bootstrap\Coordinator; use OCP\AppFramework\QueryException; use OCP\AppFramework\Services\InitialStateProvider; use OCP\IInitialStateService; -use OCP\ILogger; use OCP\IServerContainer; +use Psr\Log\LoggerInterface; class InitialStateService implements IInitialStateService { - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var string[][] */ @@ -53,7 +53,7 @@ class InitialStateService implements IInitialStateService { /** @var IServerContainer */ private $container; - public function __construct(ILogger $logger, Coordinator $bootstrapCoordinator, IServerContainer $container) { + public function __construct(LoggerInterface $logger, Coordinator $bootstrapCoordinator, IServerContainer $container) { $this->logger = $logger; $this->bootstrapCoordinator = $bootstrapCoordinator; $this->container = $container; @@ -118,9 +118,8 @@ class InitialStateService implements IInitialStateService { $provider = $this->container->query($initialState->getService()); } catch (QueryException $e) { // Log an continue. We can be fault tolerant here. - $this->logger->logException($e, [ - 'message' => 'Could not load initial state provider dynamically: ' . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error('Could not load initial state provider dynamically: ' . $e->getMessage(), [ + 'exception' => $e, 'app' => $initialState->getAppId(), ]); continue; diff --git a/lib/private/Installer.php b/lib/private/Installer.php index da3cef7d1e7..432f5c526ad 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -54,6 +54,7 @@ use OCP\IConfig; use OCP\ILogger; use OCP\ITempManager; use phpseclib\File\X509; +use Psr\Log\LoggerInterface; /** * This class provides the functionality needed to install, update and remove apps @@ -65,7 +66,7 @@ class Installer { private $clientService; /** @var ITempManager */ private $tempManager; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var IConfig */ private $config; @@ -76,18 +77,11 @@ class Installer { /** @var bool */ private $isCLI; - /** - * @param AppFetcher $appFetcher - * @param IClientService $clientService - * @param ITempManager $tempManager - * @param ILogger $logger - * @param IConfig $config - */ public function __construct( AppFetcher $appFetcher, IClientService $clientService, ITempManager $tempManager, - ILogger $logger, + LoggerInterface $logger, IConfig $config, bool $isCLI ) { @@ -201,9 +195,8 @@ class Installer { try { $this->downloadApp($appId, $allowUnstable); } catch (\Exception $e) { - $this->logger->logException($e, [ - 'level' => ILogger::ERROR, - 'app' => 'core', + $this->logger->error($e->getMessage(), [ + 'exception' => $e, ]); return false; } diff --git a/lib/private/Setup.php b/lib/private/Setup.php index 98cf11e3a87..fe658b2eedd 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -60,8 +60,8 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\Defaults; use OCP\IGroup; use OCP\IL10N; -use OCP\ILogger; use OCP\Security\ISecureRandom; +use Psr\Log\LoggerInterface; class Setup { /** @var SystemConfig */ @@ -72,28 +72,19 @@ class Setup { protected $l10n; /** @var Defaults */ protected $defaults; - /** @var ILogger */ + /** @var LoggerInterface */ protected $logger; /** @var ISecureRandom */ protected $random; /** @var Installer */ protected $installer; - /** - * @param SystemConfig $config - * @param IniGetWrapper $iniWrapper - * @param IL10N $l10n - * @param Defaults $defaults - * @param ILogger $logger - * @param ISecureRandom $random - * @param Installer $installer - */ public function __construct( SystemConfig $config, IniGetWrapper $iniWrapper, IL10N $l10n, Defaults $defaults, - ILogger $logger, + LoggerInterface $logger, ISecureRandom $random, Installer $installer ) { @@ -511,7 +502,7 @@ class Setup { \OC::$server->get(IniGetWrapper::class), \OC::$server->getL10N('lib'), \OC::$server->query(Defaults::class), - \OC::$server->getLogger(), + \OC::$server->get(LoggerInterface::class), \OC::$server->getSecureRandom(), \OC::$server->query(Installer::class) ); diff --git a/lib/private/Setup/AbstractDatabase.php b/lib/private/Setup/AbstractDatabase.php index 77f3c02f9f6..5b975bcfcca 100644 --- a/lib/private/Setup/AbstractDatabase.php +++ b/lib/private/Setup/AbstractDatabase.php @@ -34,8 +34,8 @@ use OC\DB\ConnectionFactory; use OC\DB\MigrationService; use OC\SystemConfig; use OCP\IL10N; -use OCP\ILogger; use OCP\Security\ISecureRandom; +use Psr\Log\LoggerInterface; abstract class AbstractDatabase { @@ -55,12 +55,12 @@ abstract class AbstractDatabase { protected $tablePrefix; /** @var SystemConfig */ protected $config; - /** @var ILogger */ + /** @var LoggerInterface */ protected $logger; /** @var ISecureRandom */ protected $random; - public function __construct(IL10N $trans, SystemConfig $config, ILogger $logger, ISecureRandom $random) { + public function __construct(IL10N $trans, SystemConfig $config, LoggerInterface $logger, ISecureRandom $random) { $this->trans = $trans; $this->config = $config; $this->logger = $logger; diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php index 229d47160f5..c2b0cd8aaac 100644 --- a/lib/private/Setup/MySQL.php +++ b/lib/private/Setup/MySQL.php @@ -84,9 +84,8 @@ class MySQL extends AbstractDatabase { $query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE ${characterSet}_bin;"; $connection->executeUpdate($query); } catch (\Exception $ex) { - $this->logger->logException($ex, [ - 'message' => 'Database creation failed.', - 'level' => ILogger::ERROR, + $this->logger->error('Database creation failed.', [ + 'exception' => $ex, 'app' => 'mysql.setup', ]); return; @@ -97,9 +96,8 @@ class MySQL extends AbstractDatabase { $query = "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `$name` . * TO '$user'"; $connection->executeUpdate($query); } catch (\Exception $ex) { - $this->logger->logException($ex, [ - 'message' => 'Could not automatically grant privileges, this can be ignored if database user already had privileges.', - 'level' => ILogger::DEBUG, + $this->logger->debug('Could not automatically grant privileges, this can be ignored if database user already had privileges.', [ + 'exception' => $ex, 'app' => 'mysql.setup', ]); } @@ -128,9 +126,8 @@ class MySQL extends AbstractDatabase { $connection->executeUpdate($query); } } catch (\Exception $ex) { - $this->logger->logException($ex, [ - 'message' => 'Database user creation failed.', - 'level' => ILogger::ERROR, + $this->logger->error('Database user creation failed.',[ + 'exception' => $ex, 'app' => 'mysql.setup', ]); } diff --git a/lib/private/Updater.php b/lib/private/Updater.php index 78c652b6ee4..964fd2ad102 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -59,7 +59,7 @@ use Symfony\Component\EventDispatcher\GenericEvent; */ class Updater extends BasicEmitter { - /** @var ILogger $log */ + /** @var LoggerInterface */ private $log; /** @var IConfig */ @@ -79,15 +79,9 @@ class Updater extends BasicEmitter { 4 => 'Fatal', ]; - /** - * @param IConfig $config - * @param Checker $checker - * @param ILogger $log - * @param Installer $installer - */ public function __construct(IConfig $config, Checker $checker, - ILogger $log = null, + ?LoggerInterface $log, Installer $installer) { $this->log = $log; $this->config = $config; @@ -132,11 +126,15 @@ class Updater extends BasicEmitter { try { $this->doUpgrade($currentVersion, $installedVersion); } catch (HintException $exception) { - $this->log->logException($exception, ['app' => 'core']); + $this->log->error($exception->getMessage(), [ + 'exception' => $exception, + ]); $this->emit('\OC\Updater', 'failure', [$exception->getMessage() . ': ' .$exception->getHint()]); $success = false; } catch (\Exception $exception) { - $this->log->logException($exception, ['app' => 'core']); + $this->log->error($exception->getMessage(), [ + 'exception' => $exception, + ]); $this->emit('\OC\Updater', 'failure', [get_class($exception) . ': ' .$exception->getMessage()]); $success = false; } @@ -272,7 +270,10 @@ class Updater extends BasicEmitter { $errors = Installer::installShippedApps(true); foreach ($errors as $appId => $exception) { /** @var \Exception $exception */ - $this->log->logException($exception, ['app' => $appId]); + $this->log->error($exception->getMessage(), [ + 'exception' => $exception, + 'app' => $appId, + ]); $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); } @@ -424,7 +425,9 @@ class Updater extends BasicEmitter { $ocApp->enable($app); } } catch (\Exception $ex) { - $this->log->logException($ex, ['app' => 'core']); + $this->log->error($ex->getMessage(), [ + 'exception' => $ex, + ]); } } } -- cgit v1.2.3 From df47445c014b83d8400bada6dad53d26d24fd803 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 19 Apr 2021 14:06:34 +0200 Subject: Fix unit tests Signed-off-by: Joas Schilling --- apps/files_sharing/tests/TestCase.php | 2 +- console.php | 2 +- core/Command/Maintenance/Install.php | 3 ++- lib/private/AppFramework/Bootstrap/Coordinator.php | 9 ++++---- .../DependencyInjection/DIContainer.php | 2 +- lib/private/Server.php | 9 ++++---- lib/private/legacy/OC_Util.php | 6 +++--- tests/lib/App/AppManagerTest.php | 6 +++--- tests/lib/App/AppStore/Fetcher/AppFetcherTest.php | 6 +++--- tests/lib/App/AppStore/Fetcher/FetcherBase.php | 6 +++--- .../lib/AppFramework/Bootstrap/CoordinatorTest.php | 6 +++--- .../Bootstrap/RegistrationContextTest.php | 6 +++--- .../Middleware/Security/SecurityMiddlewareTest.php | 6 +++--- tests/lib/AppTest.php | 7 +++--- tests/lib/Avatar/AvatarManagerTest.php | 8 +++---- tests/lib/Avatar/GuestAvatarTest.php | 6 +++--- tests/lib/Avatar/UserAvatarTest.php | 4 ++-- tests/lib/CapabilitiesManagerTest.php | 8 +++---- .../Collaborators/LookupPluginTest.php | 25 +++++++++++----------- tests/lib/Collaboration/Resources/ManagerTest.php | 8 +++---- .../Resources/ProviderManagerTest.php | 6 +++--- tests/lib/InitialStateServiceTest.php | 4 ++-- tests/lib/InstallerTest.php | 12 +++++------ tests/lib/SetupTest.php | 21 +++++++++--------- tests/lib/UpdaterTest.php | 13 +++++------ 25 files changed, 98 insertions(+), 93 deletions(-) (limited to 'lib/private') diff --git a/apps/files_sharing/tests/TestCase.php b/apps/files_sharing/tests/TestCase.php index f8966e3a83f..d772e6359ec 100644 --- a/apps/files_sharing/tests/TestCase.php +++ b/apps/files_sharing/tests/TestCase.php @@ -187,7 +187,7 @@ abstract class TestCase extends \Test\TestCase { $userObject = $userManager->createUser($user, $password); $group = $groupManager->createGroup('group'); - if ($group and $userObject) { + if ($group && $userObject) { $group->addUser($userObject); } } diff --git a/console.php b/console.php index 88456a9bd77..4aa6e214cb7 100644 --- a/console.php +++ b/console.php @@ -93,7 +93,7 @@ try { \OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest(), - \OC::$server->getLogger(), + \OC::$server->get(\Psr\Log\LoggerInterface::class), \OC::$server->query(\OC\MemoryInfo::class) ); $application->loadCommands(new ArgvInput(), new ConsoleOutput()); diff --git a/core/Command/Maintenance/Install.php b/core/Command/Maintenance/Install.php index fc219e79bcd..33bb967f08c 100644 --- a/core/Command/Maintenance/Install.php +++ b/core/Command/Maintenance/Install.php @@ -37,6 +37,7 @@ use OC\Installer; use OC\Setup; use OC\SystemConfig; use OCP\Defaults; +use Psr\Log\LoggerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; @@ -85,7 +86,7 @@ class Install extends Command { $this->iniGetWrapper, $server->getL10N('lib'), $server->query(Defaults::class), - $server->getLogger(), + $server->get(LoggerInterface::class), $server->getSecureRandom(), \OC::$server->query(Installer::class) ); diff --git a/lib/private/AppFramework/Bootstrap/Coordinator.php b/lib/private/AppFramework/Bootstrap/Coordinator.php index 627618f04fa..33b02c0291f 100644 --- a/lib/private/AppFramework/Bootstrap/Coordinator.php +++ b/lib/private/AppFramework/Bootstrap/Coordinator.php @@ -175,13 +175,12 @@ class Coordinator { $application->boot($context); } } catch (QueryException $e) { - $this->logger->logException($e, [ - 'message' => "Could not boot $appId" . $e->getMessage(), + $this->logger->error("Could not boot $appId" . $e->getMessage(), [ + 'exception' => $e, ]); } catch (Throwable $e) { - $this->logger->logException($e, [ - 'message' => "Could not boot $appId" . $e->getMessage(), - 'level' => ILogger::FATAL, + $this->logger->emergency("Could not boot $appId" . $e->getMessage(), [ + 'exception' => $e, ]); } } diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index 7395be703d3..db4f3d2c075 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -241,7 +241,7 @@ class DIContainer extends SimpleContainer implements IAppContainer { $c->get(IControllerMethodReflector::class), $c->get(INavigationManager::class), $c->get(IURLGenerator::class), - $server->query(ILogger::class), + $server->get(LoggerInterface::class), $c->get('AppName'), $server->getUserSession()->isLoggedIn(), $this->getUserId() !== null && $server->getGroupManager()->isAdmin($this->getUserId()), diff --git a/lib/private/Server.php b/lib/private/Server.php index c09ec0a8e18..f7eaf9f3591 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -145,6 +145,7 @@ use OC\Template\JSCombiner; use OCA\Theming\ImageManager; use OCA\Theming\ThemingDefaults; use OCA\Theming\Util; +use OCA\WorkflowEngine\Service\Logger; use OCP\Accounts\IAccountManager; use OCP\App\IAppManager; use OCP\Authentication\LoginCredentials\IStore; @@ -731,7 +732,7 @@ class Server extends ServerContainer implements IServerContainer { $c->get(\OC\User\Manager::class), $c->getAppDataDir('avatar'), $c->getL10N('lib'), - $c->get(ILogger::class), + $c->get(LoggerInterface::class), $c->get(\OCP\IConfig::class), $c->get(IAccountManager::class), $c->get(KnownUserService::class) @@ -877,7 +878,7 @@ class Server extends ServerContainer implements IServerContainer { $c->get(IGroupManager::class), $c->get(ICacheFactory::class), $c->get(SymfonyAdapter::class), - $c->get(ILogger::class) + $c->get(LoggerInterface::class) ); }); /** @deprecated 19.0.0 */ @@ -1091,7 +1092,7 @@ class Server extends ServerContainer implements IServerContainer { $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { - $manager = new CapabilitiesManager($c->get(ILogger::class)); + $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); $manager->registerCapability(function () use ($c) { return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); }); @@ -1334,7 +1335,7 @@ class Server extends ServerContainer implements IServerContainer { $c->get(AppFetcher::class), $c->get(IClientService::class), $c->get(ITempManager::class), - $c->get(ILogger::class), + $c->get(LoggerInterface::class), $c->get(\OCP\IConfig::class), \OC::$CLI ); diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index f1e88166e97..63eaf303759 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -747,10 +747,10 @@ class OC_Util { $config, \OC::$server->get(IniGetWrapper::class), \OC::$server->getL10N('lib'), - \OC::$server->query(\OCP\Defaults::class), - \OC::$server->getLogger(), + \OC::$server->get(\OCP\Defaults::class), + \OC::$server->get(LoggerInterface::class), \OC::$server->getSecureRandom(), - \OC::$server->query(\OC\Installer::class) + \OC::$server->get(\OC\Installer::class) ); $urlGenerator = \OC::$server->getURLGenerator(); diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php index 5b6fedb1cc2..db2f117cb9b 100644 --- a/tests/lib/App/AppManagerTest.php +++ b/tests/lib/App/AppManagerTest.php @@ -20,10 +20,10 @@ use OCP\ICacheFactory; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; -use OCP\ILogger; use OCP\IUser; use OCP\IUserSession; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\TestCase; @@ -93,7 +93,7 @@ class AppManagerTest extends TestCase { /** @var EventDispatcherInterface|MockObject */ protected $eventDispatcher; - /** @var ILogger|MockObject */ + /** @var LoggerInterface|MockObject */ protected $logger; /** @var IAppManager */ @@ -109,7 +109,7 @@ class AppManagerTest extends TestCase { $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->cache = $this->createMock(ICache::class); $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->cacheFactory->expects($this->any()) ->method('createDistributed') ->with('settings') diff --git a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php index f9696cc1b00..840d47ed802 100644 --- a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php +++ b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php @@ -34,7 +34,7 @@ use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\IConfig; -use OCP\ILogger; +use Psr\Log\LoggerInterface; use Test\TestCase; class AppFetcherTest extends TestCase { @@ -48,7 +48,7 @@ class AppFetcherTest extends TestCase { protected $config; /** @var CompareVersion|\PHPUnit\Framework\MockObject\MockObject */ protected $compareVersion; - /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ protected $logger; /** @var AppFetcher */ protected $fetcher; @@ -1848,7 +1848,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== $this->timeFactory = $this->createMock(ITimeFactory::class); $this->config = $this->createMock(IConfig::class); $this->compareVersion = new CompareVersion(); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->fetcher = new AppFetcher( $factory, diff --git a/tests/lib/App/AppStore/Fetcher/FetcherBase.php b/tests/lib/App/AppStore/Fetcher/FetcherBase.php index 531fdf41e78..735df939965 100644 --- a/tests/lib/App/AppStore/Fetcher/FetcherBase.php +++ b/tests/lib/App/AppStore/Fetcher/FetcherBase.php @@ -33,7 +33,7 @@ use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\IConfig; -use OCP\ILogger; +use Psr\Log\LoggerInterface; use Test\TestCase; abstract class FetcherBase extends TestCase { @@ -47,7 +47,7 @@ abstract class FetcherBase extends TestCase { protected $timeFactory; /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ protected $config; - /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ protected $logger; /** @var Fetcher */ protected $fetcher; @@ -67,7 +67,7 @@ abstract class FetcherBase extends TestCase { $this->clientService = $this->createMock(IClientService::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->config = $this->createMock(IConfig::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); } public function testGetWithAlreadyExistingFileAndUpToDateTimestampAndVersion() { diff --git a/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php b/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php index 1fca34423d5..05442455cb7 100644 --- a/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php +++ b/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php @@ -35,9 +35,9 @@ use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\QueryException; use OCP\Dashboard\IManager; use OCP\EventDispatcher\IEventDispatcher; -use OCP\ILogger; use OCP\IServerContainer; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Test\TestCase; class CoordinatorTest extends TestCase { @@ -57,7 +57,7 @@ class CoordinatorTest extends TestCase { /** @var IEventDispatcher|MockObject */ private $eventDispatcher; - /** @var ILogger|MockObject */ + /** @var LoggerInterface|MockObject */ private $logger; /** @var Coordinator */ @@ -71,7 +71,7 @@ class CoordinatorTest extends TestCase { $this->crashReporterRegistry = $this->createMock(Registry::class); $this->dashboardManager = $this->createMock(IManager::class); $this->eventDispatcher = $this->createMock(IEventDispatcher::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->coordinator = new Coordinator( $this->serverContainer, diff --git a/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php b/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php index e304a63cfc4..f97ac92e887 100644 --- a/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php +++ b/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php @@ -29,13 +29,13 @@ use OC\AppFramework\Bootstrap\RegistrationContext; use OCP\AppFramework\App; use OCP\AppFramework\IAppContainer; use OCP\EventDispatcher\IEventDispatcher; -use OCP\ILogger; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Test\TestCase; class RegistrationContextTest extends TestCase { - /** @var ILogger|MockObject */ + /** @var LoggerInterface|MockObject */ private $logger; /** @var RegistrationContext */ @@ -44,7 +44,7 @@ class RegistrationContextTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->context = new RegistrationContext( $this->logger diff --git a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php index a3c9efa557c..076f6588d94 100644 --- a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php @@ -39,11 +39,11 @@ use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IL10N; -use OCP\ILogger; use OCP\INavigationManager; use OCP\IRequest; use OCP\IURLGenerator; use OCP\Security\ISecureRandom; +use Psr\Log\LoggerInterface; class SecurityMiddlewareTest extends \Test\TestCase { @@ -59,7 +59,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { private $request; /** @var ControllerMethodReflector */ private $reader; - /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ private $logger; /** @var INavigationManager|\PHPUnit\Framework\MockObject\MockObject */ private $navigationManager; @@ -75,7 +75,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { $this->controller = $this->createMock(Controller::class); $this->reader = new ControllerMethodReflector(); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->navigationManager = $this->createMock(INavigationManager::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->request = $this->createMock(IRequest::class); diff --git a/tests/lib/AppTest.php b/tests/lib/AppTest.php index 7ada4ec746a..22fad4ab61f 100644 --- a/tests/lib/AppTest.php +++ b/tests/lib/AppTest.php @@ -13,6 +13,7 @@ use OC\App\AppManager; use OC\App\InfoParser; use OC\AppConfig; use OCP\IAppConfig; +use Psr\Log\LoggerInterface; /** * Class AppTest @@ -477,7 +478,7 @@ class AppTest extends \Test\TestCase { 'appforgroup2' => '["group2"]', 'appforgroup12' => '["group2","group1"]', ] - + ); $apps = \OC_App::getEnabledApps(false, $forceAll); @@ -512,7 +513,7 @@ class AppTest extends \Test\TestCase { 'app3' => 'yes', 'app2' => 'no', ] - + ); $apps = \OC_App::getEnabledApps(); @@ -554,7 +555,7 @@ class AppTest extends \Test\TestCase { \OC::$server->getGroupManager(), \OC::$server->getMemCacheFactory(), \OC::$server->getEventDispatcher(), - \OC::$server->getLogger() + \OC::$server->get(LoggerInterface::class) )); } diff --git a/tests/lib/Avatar/AvatarManagerTest.php b/tests/lib/Avatar/AvatarManagerTest.php index d3bc60efb59..ce6981a2a21 100644 --- a/tests/lib/Avatar/AvatarManagerTest.php +++ b/tests/lib/Avatar/AvatarManagerTest.php @@ -36,9 +36,9 @@ use OCP\Files\IAppData; use OCP\Files\SimpleFS\ISimpleFolder; use OCP\IConfig; use OCP\IL10N; -use OCP\ILogger; use OCP\IUser; use OCP\IUserSession; +use Psr\Log\LoggerInterface; /** * Class AvatarManagerTest @@ -52,7 +52,7 @@ class AvatarManagerTest extends \Test\TestCase { private $appData; /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */ private $l10n; - /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ private $logger; /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ private $config; @@ -70,7 +70,7 @@ class AvatarManagerTest extends \Test\TestCase { $this->userManager = $this->createMock(Manager::class); $this->appData = $this->createMock(IAppData::class); $this->l10n = $this->createMock(IL10N::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->config = $this->createMock(IConfig::class); $this->accountManager = $this->createMock(IAccountManager::class); $this->knownUserService = $this->createMock(KnownUserService::class); @@ -247,7 +247,7 @@ class AvatarManagerTest extends \Test\TestCase { } if ($expectedPlaceholder) { - $expected = new PlaceholderAvatar($folder, $user, $this->createMock(ILogger::class)); + $expected = new PlaceholderAvatar($folder, $user, $this->createMock(LoggerInterface::class)); } else { $expected = new UserAvatar($folder, $this->l10n, $user, $this->logger, $this->config); } diff --git a/tests/lib/Avatar/GuestAvatarTest.php b/tests/lib/Avatar/GuestAvatarTest.php index 1c424234f10..b8e6d8ae2e8 100644 --- a/tests/lib/Avatar/GuestAvatarTest.php +++ b/tests/lib/Avatar/GuestAvatarTest.php @@ -26,8 +26,8 @@ namespace Test\Avatar; use OC\Avatar\GuestAvatar; use OCP\Files\SimpleFS\InMemoryFile; -use OCP\ILogger; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Test\TestCase; /** @@ -48,8 +48,8 @@ class GuestAvatarTest extends TestCase { * @return void */ public function setupGuestAvatar() { - /* @var MockObject|ILogger $logger */ - $logger = $this->getMockBuilder(ILogger::class)->getMock(); + /* @var MockObject|LoggerInterface $logger */ + $logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); $this->guestAvatar = new GuestAvatar('einstein', $logger); } diff --git a/tests/lib/Avatar/UserAvatarTest.php b/tests/lib/Avatar/UserAvatarTest.php index 31f2a6ebf5b..3570f2017d5 100644 --- a/tests/lib/Avatar/UserAvatarTest.php +++ b/tests/lib/Avatar/UserAvatarTest.php @@ -16,7 +16,7 @@ use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; use OCP\IConfig; use OCP\IL10N; -use OCP\ILogger; +use Psr\Log\LoggerInterface; class UserAvatarTest extends \Test\TestCase { /** @var Folder | \PHPUnit\Framework\MockObject\MockObject */ @@ -309,7 +309,7 @@ class UserAvatarTest extends \Test\TestCase { $this->folder, $l, $user, - $this->createMock(ILogger::class), + $this->createMock(LoggerInterface::class), $this->config ); } diff --git a/tests/lib/CapabilitiesManagerTest.php b/tests/lib/CapabilitiesManagerTest.php index 536355f9697..4909272c4a8 100644 --- a/tests/lib/CapabilitiesManagerTest.php +++ b/tests/lib/CapabilitiesManagerTest.php @@ -25,19 +25,19 @@ use OC\CapabilitiesManager; use OCP\AppFramework\QueryException; use OCP\Capabilities\ICapability; use OCP\Capabilities\IPublicCapability; -use OCP\ILogger; +use Psr\Log\LoggerInterface; class CapabilitiesManagerTest extends TestCase { /** @var CapabilitiesManager */ private $manager; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; protected function setUp(): void { parent::setUp(); - $this->logger = $this->getMockBuilder(ILogger::class)->getMock(); + $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); $this->manager = new CapabilitiesManager($this->logger); } @@ -139,7 +139,7 @@ class CapabilitiesManagerTest extends TestCase { ] ] ]; - + $this->assertEquals($expected, $res); } diff --git a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php index 81279c4c569..3ec9e6f5efc 100644 --- a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php @@ -33,25 +33,26 @@ use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\IConfig; -use OCP\ILogger; use OCP\IUser; use OCP\IUserSession; use OCP\Share\IShare; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Test\TestCase; class LookupPluginTest extends TestCase { - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IConfig|MockObject */ protected $config; - /** @var IClientService|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IClientService|MockObject */ protected $clientService; - /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserSession|MockObject */ protected $userSession; - /** @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var ICloudIdManager|MockObject */ protected $cloudIdManager; /** @var LookupPlugin */ protected $plugin; - /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|MockObject */ protected $logger; protected function setUp(): void { @@ -60,7 +61,7 @@ class LookupPluginTest extends TestCase { $this->userSession = $this->createMock(IUserSession::class); $this->cloudIdManager = $this->createMock(ICloudIdManager::class); $this->config = $this->createMock(IConfig::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->clientService = $this->createMock(IClientService::class); $cloudId = $this->createMock(ICloudId::class); $cloudId->expects($this->any())->method('getRemote')->willReturn('myNextcloud.net'); @@ -108,7 +109,7 @@ class LookupPluginTest extends TestCase { $this->clientService->expects($this->never()) ->method('newClient'); - /** @var ISearchResult|\PHPUnit\Framework\MockObject\MockObject $searchResult */ + /** @var ISearchResult|MockObject $searchResult */ $searchResult = $this->createMock(ISearchResult::class); $this->plugin->search('foobar', 10, 0, $searchResult); @@ -132,7 +133,7 @@ class LookupPluginTest extends TestCase { $this->clientService->expects($this->never()) ->method('newClient'); - /** @var ISearchResult|\PHPUnit\Framework\MockObject\MockObject $searchResult */ + /** @var ISearchResult|MockObject $searchResult */ $searchResult = $this->createMock(ISearchResult::class); $this->plugin->search('foobar', 10, 0, $searchResult); @@ -145,7 +146,7 @@ class LookupPluginTest extends TestCase { public function testSearch(array $searchParams) { $type = new SearchResultType('lookup'); - /** @var ISearchResult|\PHPUnit\Framework\MockObject\MockObject $searchResult */ + /** @var ISearchResult|MockObject $searchResult */ $searchResult = $this->createMock(ISearchResult::class); $searchResult->expects($this->once()) ->method('addResultSet') @@ -207,7 +208,7 @@ class LookupPluginTest extends TestCase { public function testSearchEnableDisableLookupServer(array $searchParams, $GSEnabled, $LookupEnabled) { $type = new SearchResultType('lookup'); - /** @var ISearchResult|\PHPUnit\Framework\MockObject\MockObject $searchResult */ + /** @var ISearchResult|MockObject $searchResult */ $searchResult = $this->createMock(ISearchResult::class); $this->config->expects($this->once()) @@ -269,7 +270,7 @@ class LookupPluginTest extends TestCase { ->with('files_sharing', 'lookupServerEnabled', 'yes') ->willReturn('no'); - /** @var ISearchResult|\PHPUnit\Framework\MockObject\MockObject $searchResult */ + /** @var ISearchResult|MockObject $searchResult */ $searchResult = $this->createMock(ISearchResult::class); $searchResult->expects($this->never()) ->method('addResultSet'); diff --git a/tests/lib/Collaboration/Resources/ManagerTest.php b/tests/lib/Collaboration/Resources/ManagerTest.php index 092d4ffd39c..01a39660a7c 100644 --- a/tests/lib/Collaboration/Resources/ManagerTest.php +++ b/tests/lib/Collaboration/Resources/ManagerTest.php @@ -27,12 +27,12 @@ use OC\Collaboration\Resources\Manager; use OCP\Collaboration\Resources\IManager; use OCP\Collaboration\Resources\IProviderManager; use OCP\IDBConnection; -use OCP\ILogger; +use Psr\Log\LoggerInterface; use Test\TestCase; class ManagerTest extends TestCase { - /** @var ILogger */ + /** @var LoggerInterface */ protected $logger; /** @var IProviderManager */ protected $providerManager; @@ -42,14 +42,14 @@ class ManagerTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->providerManager = $this->createMock(IProviderManager::class); /** @var IDBConnection $connection */ $connection = $this->createMock(IDBConnection::class); $this->manager = new Manager($connection, $this->providerManager, $this->logger); } - + public function testRegisterResourceProvider(): void { $this->logger->expects($this->once()) ->method('debug') diff --git a/tests/lib/Collaboration/Resources/ProviderManagerTest.php b/tests/lib/Collaboration/Resources/ProviderManagerTest.php index 751e2cc1f8d..19a34962a56 100644 --- a/tests/lib/Collaboration/Resources/ProviderManagerTest.php +++ b/tests/lib/Collaboration/Resources/ProviderManagerTest.php @@ -27,15 +27,15 @@ use OC\Collaboration\Resources\ProviderManager; use OCA\Files\Collaboration\Resources\ResourceProvider; use OCP\AppFramework\QueryException; use OCP\Collaboration\Resources\IProviderManager; -use OCP\ILogger; use OCP\IServerContainer; +use Psr\Log\LoggerInterface; use Test\TestCase; class ProviderManagerTest extends TestCase { /** @var IServerContainer */ protected $serverContainer; - /** @var ILogger */ + /** @var LoggerInterface */ protected $logger; /** @var IProviderManager */ protected $providerManager; @@ -44,7 +44,7 @@ class ProviderManagerTest extends TestCase { parent::setUp(); $this->serverContainer = $this->createMock(IServerContainer::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->providerManager = new class($this->serverContainer, $this->logger) extends ProviderManager { public function countProviders(): int { diff --git a/tests/lib/InitialStateServiceTest.php b/tests/lib/InitialStateServiceTest.php index 30eca056206..2a23774baf1 100644 --- a/tests/lib/InitialStateServiceTest.php +++ b/tests/lib/InitialStateServiceTest.php @@ -27,10 +27,10 @@ namespace Test; use OC\AppFramework\Bootstrap\Coordinator; use OCP\IServerContainer; +use Psr\Log\LoggerInterface; use function json_encode; use JsonSerializable; use OC\InitialStateService; -use OCP\ILogger; use stdClass; class InitialStateServiceTest extends TestCase { @@ -42,7 +42,7 @@ class InitialStateServiceTest extends TestCase { parent::setUp(); $this->service = new InitialStateService( - $this->createMock(ILogger::class), + $this->createMock(LoggerInterface::class), $this->createMock(Coordinator::class), $this->createMock(IServerContainer::class) ); diff --git a/tests/lib/InstallerTest.php b/tests/lib/InstallerTest.php index 2626e047c74..c49f8bf76a5 100644 --- a/tests/lib/InstallerTest.php +++ b/tests/lib/InstallerTest.php @@ -14,8 +14,8 @@ use OC\Installer; use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\IConfig; -use OCP\ILogger; use OCP\ITempManager; +use Psr\Log\LoggerInterface; /** * Class InstallerTest @@ -32,7 +32,7 @@ class InstallerTest extends TestCase { private $clientService; /** @var ITempManager|\PHPUnit\Framework\MockObject\MockObject */ private $tempManager; - /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ private $logger; /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ private $config; @@ -43,7 +43,7 @@ class InstallerTest extends TestCase { $this->appFetcher = $this->createMock(AppFetcher::class); $this->clientService = $this->createMock(IClientService::class); $this->tempManager = $this->createMock(ITempManager::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->config = $this->createMock(IConfig::class); $config = \OC::$server->getConfig(); @@ -53,7 +53,7 @@ class InstallerTest extends TestCase { \OC::$server->getAppFetcher(), \OC::$server->getHTTPClientService(), \OC::$server->getTempManager(), - \OC::$server->getLogger(), + \OC::$server->get(LoggerInterface::class), $config, false ); @@ -76,7 +76,7 @@ class InstallerTest extends TestCase { \OC::$server->getAppFetcher(), \OC::$server->getHTTPClientService(), \OC::$server->getTempManager(), - \OC::$server->getLogger(), + \OC::$server->get(LoggerInterface::class), \OC::$server->getConfig(), false ); @@ -100,7 +100,7 @@ class InstallerTest extends TestCase { \OC::$server->getAppFetcher(), \OC::$server->getHTTPClientService(), \OC::$server->getTempManager(), - \OC::$server->getLogger(), + \OC::$server->get(LoggerInterface::class), \OC::$server->getConfig(), false ); diff --git a/tests/lib/SetupTest.php b/tests/lib/SetupTest.php index 696e1d69fbe..004fc9c866b 100644 --- a/tests/lib/SetupTest.php +++ b/tests/lib/SetupTest.php @@ -14,26 +14,27 @@ use OC\Setup; use OC\SystemConfig; use OCP\Defaults; use OCP\IL10N; -use OCP\ILogger; use OCP\Security\ISecureRandom; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; class SetupTest extends \Test\TestCase { - /** @var SystemConfig|\PHPUnit\Framework\MockObject\MockObject */ + /** @var SystemConfig|MockObject */ protected $config; - /** @var \bantu\IniGetWrapper\IniGetWrapper|\PHPUnit\Framework\MockObject\MockObject */ + /** @var \bantu\IniGetWrapper\IniGetWrapper|MockObject */ private $iniWrapper; - /** @var \OCP\IL10N|\PHPUnit\Framework\MockObject\MockObject */ + /** @var \OCP\IL10N|MockObject */ private $l10n; - /** @var Defaults|\PHPUnit\Framework\MockObject\MockObject */ + /** @var Defaults|MockObject */ private $defaults; - /** @var \OC\Setup|\PHPUnit\Framework\MockObject\MockObject */ + /** @var \OC\Setup|MockObject */ protected $setupClass; - /** @var \OCP\ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|MockObject */ protected $logger; - /** @var \OCP\Security\ISecureRandom|\PHPUnit\Framework\MockObject\MockObject */ + /** @var \OCP\Security\ISecureRandom|MockObject */ protected $random; - /** @var Installer|\PHPUnit\Framework\MockObject\MockObject */ + /** @var Installer|MockObject */ protected $installer; protected function setUp(): void { @@ -43,7 +44,7 @@ class SetupTest extends \Test\TestCase { $this->iniWrapper = $this->createMock(IniGetWrapper::class); $this->l10n = $this->createMock(IL10N::class); $this->defaults = $this->createMock(Defaults::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->random = $this->createMock(ISecureRandom::class); $this->installer = $this->createMock(Installer::class); $this->setupClass = $this->getMockBuilder(Setup::class) diff --git a/tests/lib/UpdaterTest.php b/tests/lib/UpdaterTest.php index 1affd6d020a..5a7422cbad5 100644 --- a/tests/lib/UpdaterTest.php +++ b/tests/lib/UpdaterTest.php @@ -22,22 +22,23 @@ namespace Test; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use OC\Installer; use OC\IntegrityCheck\Checker; use OC\Updater; use OCP\IConfig; -use OCP\ILogger; class UpdaterTest extends TestCase { - /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */ + /** @var IConfig|MockObject */ private $config; - /** @var ILogger | \PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|MockObject */ private $logger; /** @var Updater */ private $updater; - /** @var Checker | \PHPUnit\Framework\MockObject\MockObject */ + /** @var Checker|MockObject */ private $checker; - /** @var Installer|\PHPUnit\Framework\MockObject\MockObject */ + /** @var Installer|MockObject */ private $installer; protected function setUp(): void { @@ -45,7 +46,7 @@ class UpdaterTest extends TestCase { $this->config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); - $this->logger = $this->getMockBuilder(ILogger::class) + $this->logger = $this->getMockBuilder(LoggerInterface::class) ->disableOriginalConstructor() ->getMock(); $this->checker = $this->getMockBuilder(Checker::class) -- cgit v1.2.3 From 167efa19d706b1e430343554cdecd513cbb6610e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 22 Apr 2021 15:22:50 +0200 Subject: Fix psalm errors Signed-off-by: Joas Schilling --- core/Command/Upgrade.php | 14 ++++++-------- core/ajax/update.php | 2 +- core/register_command.php | 2 +- lib/base.php | 2 +- lib/private/Setup/MySQL.php | 9 +++++---- lib/private/Setup/PostgreSQL.php | 24 +++++++++++++++--------- 6 files changed, 29 insertions(+), 24 deletions(-) (limited to 'lib/private') diff --git a/core/Command/Upgrade.php b/core/Command/Upgrade.php index 9dc1c4642b5..7ad3360c1bc 100644 --- a/core/Command/Upgrade.php +++ b/core/Command/Upgrade.php @@ -37,8 +37,8 @@ use OC\Console\TimestampFormatter; use OC\Installer; use OC\Updater; use OCP\IConfig; -use OCP\ILogger; use OCP\Util; +use Psr\Log\LoggerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; @@ -56,15 +56,13 @@ class Upgrade extends Command { /** @var IConfig */ private $config; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; - /** - * @param IConfig $config - * @param ILogger $logger - * @param Installer $installer - */ - public function __construct(IConfig $config, ILogger $logger, Installer $installer) { + /** @var Installer */ + private $installer; + + public function __construct(IConfig $config, LoggerInterface $logger, Installer $installer) { parent::__construct(); $this->config = $config; $this->logger = $logger; diff --git a/core/ajax/update.php b/core/ajax/update.php index 6e655f42841..390ad0c2c47 100644 --- a/core/ajax/update.php +++ b/core/ajax/update.php @@ -117,7 +117,7 @@ if (\OCP\Util::needUpgrade()) { // avoid side effects \OC_User::setIncognitoMode(true); - $logger = \OC::$server->getLogger(); + $logger = \OC::$server->get(\Psr\Log\LoggerInterface::class); $config = \OC::$server->getConfig(); $updater = new \OC\Updater( $config, diff --git a/core/register_command.php b/core/register_command.php index 2a68cbcbe87..8741d8d1abe 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -160,7 +160,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) { $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); $application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory())); - $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class))); + $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->query(\OC\Installer::class))); $application->add(new OC\Core\Command\Maintenance\Repair( new \OC\Repair([], \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class)), \OC::$server->getConfig(), diff --git a/lib/base.php b/lib/base.php index 7e3f6d9567b..76d35ba754c 100644 --- a/lib/base.php +++ b/lib/base.php @@ -929,7 +929,7 @@ class OC { \OC::$server->get(\bantu\IniGetWrapper\IniGetWrapper::class), \OC::$server->getL10N('lib'), \OC::$server->query(\OCP\Defaults::class), - \OC::$server->getLogger(), + \OC::$server->get(\Psr\Log\LoggerInterface::class), \OC::$server->getSecureRandom(), \OC::$server->query(\OC\Installer::class) ); diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php index c2b0cd8aaac..7b90e1f715c 100644 --- a/lib/private/Setup/MySQL.php +++ b/lib/private/Setup/MySQL.php @@ -66,7 +66,9 @@ class MySQL extends AbstractDatabase { try { $connection->connect(); } catch (\Exception $e) { - $this->logger->logException($e); + $this->logger->error($e->getMessage(), [ + 'exception' => $e, + ]); throw new \OC\DatabaseSetupException($this->trans->t('MySQL username and/or password not valid'), $this->trans->t('You need to enter details of an existing account.'), 0, $e); } @@ -177,9 +179,8 @@ class MySQL extends AbstractDatabase { } } } catch (\Exception $ex) { - $this->logger->logException($ex, [ - 'message' => 'Can not create a new MySQL user, will continue with the provided user.', - 'level' => ILogger::INFO, + $this->logger->info('Can not create a new MySQL user, will continue with the provided user.', [ + 'exception' => $ex, 'app' => 'mysql.setup', ]); } diff --git a/lib/private/Setup/PostgreSQL.php b/lib/private/Setup/PostgreSQL.php index 7e59bf297f1..40386666341 100644 --- a/lib/private/Setup/PostgreSQL.php +++ b/lib/private/Setup/PostgreSQL.php @@ -82,8 +82,9 @@ class PostgreSQL extends AbstractDatabase { // the connection to dbname=postgres is not needed anymore $connection->close(); } catch (\Exception $e) { - $this->logger->logException($e); - $this->logger->warning('Error trying to connect as "postgres", assuming database is setup and tables need to be created'); + $this->logger->warning('Error trying to connect as "postgres", assuming database is setup and tables need to be created', [ + 'exception' => $e, + ]); $this->config->setValues([ 'dbuser' => $this->dbUser, 'dbpassword' => $this->dbPassword, @@ -97,7 +98,9 @@ class PostgreSQL extends AbstractDatabase { try { $connection->connect(); } catch (\Exception $e) { - $this->logger->logException($e); + $this->logger->error($e->getMessage(), [ + 'exception' => $e, + ]); throw new \OC\DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'), $this->trans->t('You need to enter details of an existing account.'), 0, $e); } @@ -110,16 +113,18 @@ class PostgreSQL extends AbstractDatabase { try { $query->execute(); } catch (DatabaseException $e) { - $this->logger->error('Error while trying to create database'); - $this->logger->logException($e); + $this->logger->error('Error while trying to create database', [ + 'exception' => $e, + ]); } } else { $query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE " . addslashes($this->dbName) . " FROM PUBLIC"); try { $query->execute(); } catch (DatabaseException $e) { - $this->logger->error('Error while trying to restrict database permissions'); - $this->logger->logException($e); + $this->logger->error('Error while trying to restrict database permissions', [ + 'exception' => $e, + ]); } } } @@ -161,8 +166,9 @@ class PostgreSQL extends AbstractDatabase { $query->execute(); } } catch (DatabaseException $e) { - $this->logger->error('Error while trying to create database user'); - $this->logger->logException($e); + $this->logger->error('Error while trying to create database user', [ + 'exception' => $e, + ]); } } } -- cgit v1.2.3 From 29a66a5e49ef79e39b27a2ad38e8755fa9aa1b76 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 22 Apr 2021 15:54:28 +0200 Subject: Fix PHP CS Signed-off-by: Joas Schilling --- lib/private/Setup/MySQL.php | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php index 7b90e1f715c..c5c921cecd8 100644 --- a/lib/private/Setup/MySQL.php +++ b/lib/private/Setup/MySQL.php @@ -34,7 +34,6 @@ namespace OC\Setup; use OC\DB\ConnectionAdapter; use OC\DB\MySqlTools; use OCP\IDBConnection; -use OCP\ILogger; use Doctrine\DBAL\Platforms\MySQL80Platform; use OCP\Security\ISecureRandom; -- cgit v1.2.3 From 2d75868935c7eedc5f94e63a45a27875e19053dc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 22 Apr 2021 15:58:11 +0200 Subject: Fix PHP CS Signed-off-by: Joas Schilling --- lib/private/App/AppStore/Fetcher/AppFetcher.php | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index cd6b005c0d1..7ed02fdf010 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -36,7 +36,6 @@ use OC\Files\AppData\Factory; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Http\Client\IClientService; use OCP\IConfig; -use OCP\ILogger; use Psr\Log\LoggerInterface; class AppFetcher extends Fetcher { -- cgit v1.2.3