Browse Source
			
			
			PSR logger for accounts
			
				Signed-off-by: Joas Schilling <coding@schilljs.com>
			
			
				pull/23417/head
			
			
		 
		
			
				
					
						 Joas Schilling
					
					5 years ago
						Joas Schilling
					
					5 years ago
					
				 
				
			 
		 
		
			
				
				  
				  No known key found for this signature in database
				  
				  	
						GPG Key ID: 7076EA9751AACDDA
				  	
				  
				
			
		
		
		
	
		
			
				 5 changed files with 
19 additions and 
30 deletions
			 
			
		 
		
			
				- 
					
					
					 
					lib/base.php
				
- 
					
					
					 
					lib/private/Accounts/AccountManager.php
				
- 
					
					
					 
					lib/private/Accounts/Hooks.php
				
- 
					
					
					 
					tests/lib/Accounts/AccountsManagerTest.php
				
- 
					
					
					 
					tests/lib/Accounts/HooksTest.php
				
					
					
						
							
								
									
										
											
	
		
			
				
					|  |  | @ -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'); | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
										
									
								
							
						 
					 
				 
			
		
			
				
					
					
						
							
								
									
										
											
	
		
			
				
					|  |  | @ -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; | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
										
									
								
							
						 
					 
				 
			
		
			
				
					
					
						
							
								
									
										
											
	
		
			
				
					|  |  | @ -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); | 
			
		
	
		
			
				
					|  |  |  | 		} | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
										
									
								
							
						 
					 
				 
			
		
			
				
					
					
						
							
								
									
										
											
	
		
			
				
					|  |  | @ -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 { | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
										
									
								
							
						 
					 
				 
			
		
			
				
					
					
						
							
								
									
										
											
	
		
			
				
					|  |  | @ -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(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | 
 |