PSR logger for accounts

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-10-13 16:33:53 +02:00
parent 851e8c0ded
commit 4bc821edd9
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
5 changed files with 19 additions and 30 deletions

View File

@ -854,7 +854,7 @@ class OC {
}
private static function registerAccountHooks() {
$hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger());
$hookHandler = new \OC\Accounts\Hooks(\OC::$server->get(\Psr\Log\LoggerInterface::class));
\OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook');
}

View File

@ -35,8 +35,8 @@ use OCP\Accounts\IAccount;
use OCP\Accounts\IAccountManager;
use OCP\BackgroundJob\IJobList;
use OCP\IDBConnection;
use OCP\ILogger;
use OCP\IUser;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use function json_decode;
@ -64,20 +64,13 @@ class AccountManager implements IAccountManager {
/** @var IJobList */
private $jobList;
/** @var ILogger */
/** @var LoggerInterface */
private $logger;
/**
* AccountManager constructor.
*
* @param IDBConnection $connection
* @param EventDispatcherInterface $eventDispatcher
* @param IJobList $jobList
*/
public function __construct(IDBConnection $connection,
EventDispatcherInterface $eventDispatcher,
IJobList $jobList,
ILogger $logger) {
LoggerInterface $logger) {
$this->connection = $connection;
$this->eventDispatcher = $eventDispatcher;
$this->jobList = $jobList;

View File

@ -24,23 +24,18 @@
namespace OC\Accounts;
use OCP\ILogger;
use OCP\IUser;
use Psr\Log\LoggerInterface;
class Hooks {
/** @var AccountManager */
private $accountManager = null;
/** @var AccountManager|null */
private $accountManager;
/** @var ILogger */
/** @var LoggerInterface */
private $logger;
/**
* Hooks constructor.
*
* @param ILogger $logger
*/
public function __construct(ILogger $logger) {
public function __construct(LoggerInterface $logger) {
$this->logger = $logger;
}
@ -85,7 +80,7 @@ class Hooks {
*
* @return AccountManager
*/
protected function getAccountManager() {
protected function getAccountManager(): AccountManager {
if ($this->accountManager === null) {
$this->accountManager = \OC::$server->query(AccountManager::class);
}

View File

@ -25,9 +25,9 @@ use OC\Accounts\Account;
use OC\Accounts\AccountManager;
use OCP\Accounts\IAccountManager;
use OCP\BackgroundJob\IJobList;
use OCP\ILogger;
use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Test\TestCase;
@ -52,7 +52,7 @@ class AccountsManagerTest extends TestCase {
/** @var string accounts table name */
private $table = 'accounts';
/** @var ILogger|MockObject */
/** @var LoggerInterface|MockObject */
private $logger;
protected function setUp(): void {
@ -60,7 +60,7 @@ class AccountsManagerTest extends TestCase {
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->connection = \OC::$server->getDatabaseConnection();
$this->jobList = $this->createMock(IJobList::class);
$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(LoggerInterface::class);
}
protected function tearDown(): void {

View File

@ -23,8 +23,9 @@ namespace Test\Accounts;
use OC\Accounts\AccountManager;
use OC\Accounts\Hooks;
use OCP\ILogger;
use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
/**
@ -35,19 +36,19 @@ use Test\TestCase;
*/
class HooksTest extends TestCase {
/** @var ILogger | \PHPUnit\Framework\MockObject\MockObject */
/** @var LoggerInterface|MockObject */
private $logger;
/** @var AccountManager | \PHPUnit\Framework\MockObject\MockObject */
/** @var AccountManager|MockObject */
private $accountManager;
/** @var Hooks | \PHPUnit\Framework\MockObject\MockObject */
/** @var Hooks|MockObject */
private $hooks;
protected function setUp(): void {
parent::setUp();
$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->accountManager = $this->getMockBuilder(AccountManager::class)
->disableOriginalConstructor()->getMock();