diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-10-03 17:03:53 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-10-04 16:07:08 +0300 |
commit | 759a3a70eb015564b4633d08454acfd21d499142 (patch) | |
tree | c4efcea69fa67737eb30c0c484e882685be8811b | |
parent | 2177092693588e9d6adbfe842caa191352634742 (diff) |
Migrate controllers to the PSR logger interface
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
-rw-r--r-- | lib/Controller/AccountsController.php | 8 | ||||
-rwxr-xr-x | lib/Controller/MessagesController.php | 8 | ||||
-rw-r--r-- | lib/Controller/PageController.php | 11 | ||||
-rw-r--r-- | tests/Unit/Controller/AccountsControllerTest.php | 6 | ||||
-rw-r--r-- | tests/Unit/Controller/MessagesControllerTest.php | 10 | ||||
-rw-r--r-- | tests/Unit/Controller/PageControllerTest.php | 6 |
6 files changed, 25 insertions, 24 deletions
diff --git a/lib/Controller/AccountsController.php b/lib/Controller/AccountsController.php index 4e0005738..c51c7aaab 100644 --- a/lib/Controller/AccountsController.php +++ b/lib/Controller/AccountsController.php @@ -48,8 +48,8 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; use OCP\IL10N; -use OCP\ILogger; use OCP\IRequest; +use Psr\Log\LoggerInterface; class AccountsController extends Controller { @@ -62,7 +62,7 @@ class AccountsController extends Controller { /** @var string */ private $currentUserId; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var IL10N */ @@ -91,7 +91,7 @@ class AccountsController extends Controller { * @param AccountService $accountService * @param GroupsIntegration $groupsIntegration * @param $UserId - * @param ILogger $logger + * @param LoggerInterface $logger * @param IL10N $l10n * @param AliasesService $aliasesService * @param IMailTransmission $mailTransmission @@ -104,7 +104,7 @@ class AccountsController extends Controller { AccountService $accountService, GroupsIntegration $groupsIntegration, $UserId, - ILogger $logger, + LoggerInterface $logger, IL10N $l10n, AliasesService $aliasesService, IMailTransmission $mailTransmission, diff --git a/lib/Controller/MessagesController.php b/lib/Controller/MessagesController.php index ba284e76c..10a64502a 100755 --- a/lib/Controller/MessagesController.php +++ b/lib/Controller/MessagesController.php @@ -50,9 +50,9 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\Files\Folder; use OCP\Files\IMimeTypeDetector; use OCP\IL10N; -use OCP\ILogger; use OCP\IRequest; use OCP\IURLGenerator; +use Psr\Log\LoggerInterface; use function array_map; class MessagesController extends Controller { @@ -72,7 +72,7 @@ class MessagesController extends Controller { /** @var string */ private $currentUserId; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var Folder */ @@ -93,7 +93,7 @@ class MessagesController extends Controller { * @param AccountService $accountService * @param string $UserId * @param $userFolder - * @param ILogger $logger + * @param LoggerInterface $logger * @param IL10N $l10n * @param IMimeTypeDetector $mimeTypeDetector * @param IURLGenerator $urlGenerator @@ -106,7 +106,7 @@ class MessagesController extends Controller { ItineraryService $itineraryService, string $UserId, $userFolder, - ILogger $logger, + LoggerInterface $logger, IL10N $l10n, IMimeTypeDetector $mimeTypeDetector, IURLGenerator $urlGenerator) { diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 6ec957773..ce67d0300 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -38,10 +38,10 @@ use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IInitialStateService; -use OCP\ILogger; use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUserSession; +use Psr\Log\LoggerInterface; class PageController extends Controller { @@ -72,7 +72,7 @@ class PageController extends Controller { /** @var IInitialStateService */ private $initialStateService; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; public function __construct(string $appName, @@ -86,7 +86,7 @@ class PageController extends Controller { IUserPreferences $preferences, IMailManager $mailManager, IInitialStateService $initialStateService, - ILogger $logger) { + LoggerInterface $logger) { parent::__construct($appName, $request); $this->urlGenerator = $urlGenerator; @@ -119,9 +119,8 @@ class PageController extends Controller { $mailboxes = $this->mailManager->getMailboxes($mailAccount); $json['mailboxes'] = $mailboxes; } catch (Exception $ex) { - $this->logger->logException($ex, [ - 'message' => 'Could not load account mailboxes: ' . $ex->getMessage(), - 'level' => ILogger::FATAL, + $this->logger->critical('Could not load account mailboxes: ' . $ex->getMessage(), [ + 'exception' => $ex, ]); $json['mailboxes'] = []; $json['error'] = true; diff --git a/tests/Unit/Controller/AccountsControllerTest.php b/tests/Unit/Controller/AccountsControllerTest.php index c3f4b56d5..af2436ce6 100644 --- a/tests/Unit/Controller/AccountsControllerTest.php +++ b/tests/Unit/Controller/AccountsControllerTest.php @@ -46,10 +46,10 @@ use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; use OCP\IL10N; -use OCP\ILogger; use OCP\IRequest; use OCP\Security\ICrypto; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; class AccountsControllerTest extends TestCase { @@ -71,7 +71,7 @@ class AccountsControllerTest extends TestCase { /** @var AutoConfig|MockObject */ private $autoConfig; - /** @var ILogger|MockObject */ + /** @var LoggerInterface|MockObject */ private $logger; /** @var IL10N|MockObject */ @@ -116,7 +116,7 @@ class AccountsControllerTest extends TestCase { ->will($this->returnArgument(0)); $this->userId = 'manfred'; $this->autoConfig = $this->createMock(AutoConfig::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->l10n = $this->createMock(IL10N::class); $this->crypto = $this->createMock(ICrypto::class); $this->aliasesService = $this->createMock(AliasesService::class); diff --git a/tests/Unit/Controller/MessagesControllerTest.php b/tests/Unit/Controller/MessagesControllerTest.php index b078db77c..52690dbf7 100644 --- a/tests/Unit/Controller/MessagesControllerTest.php +++ b/tests/Unit/Controller/MessagesControllerTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /** * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Lukas Reschke <lukas@owncloud.com> @@ -46,10 +48,10 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\Files\Folder; use OCP\Files\IMimeTypeDetector; use OCP\IL10N; -use OCP\ILogger; use OCP\IRequest; use OCP\IURLGenerator; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; class MessagesControllerTest extends TestCase { @@ -77,7 +79,7 @@ class MessagesControllerTest extends TestCase { /** @var MockObject|Folder */ private $userFolder; - /** @var MockObject|ILogger */ + /** @var MockObject|LoggerInterface */ private $logger; /** @var MockObject|IL10N */ @@ -119,7 +121,7 @@ class MessagesControllerTest extends TestCase { $this->userId = 'john'; $this->userFolder = $this->createMock(Folder::class); $this->request = $this->createMock(Request::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->l10n = $this->createMock(IL10N::class); $this->mimeTypeDetector = $this->createMock(IMimeTypeDetector::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); @@ -215,7 +217,7 @@ class MessagesControllerTest extends TestCase { $mailboxId = 987; $id = 123; $uid = 321; - $attachmentId = 3; + $attachmentId = "3"; // Attachment data $contents = 'abcdef'; diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index cad8c87a3..2b93ef010 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -36,12 +36,12 @@ use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IInitialStateService; -use OCP\ILogger; use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserSession; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; class PageControllerTest extends TestCase { @@ -81,7 +81,7 @@ class PageControllerTest extends TestCase { /** @var PageController */ private $controller; - /** @var ILogger|MockObject */ + /** @var LoggerInterface|MockObject */ private $logger; protected function setUp(): void { @@ -98,7 +98,7 @@ class PageControllerTest extends TestCase { $this->preferences = $this->createMock(IUserPreferences::class); $this->mailManager = $this->createMock(MailManager::class); $this->initialState = $this->createMock(IInitialStateService::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->controller = new PageController( $this->appName, |