Skip to content
Prev Previous commit
Next Next commit
Migrate from ILogger to LoggerInterface where needed in the tests
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Mar 24, 2022
commit 61f7f13bd81948f6179bb8f70b6711c002ddd70e
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\ILogger;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use Test\TestCase;

class CleanPreviewsBackgroundJobTest extends TestCase {
/** @var IRootFolder|\PHPUnit_Framework_MockObject_MockObject */
private $rootFolder;

/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
/** @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject */
private $logger;

/** @var IJobList|\PHPUnit_Framework_MockObject_MockObject */
Expand All @@ -56,7 +56,7 @@ public function setUp(): void {
parent::setUp();

$this->rootFolder = $this->createMock(IRootFolder::class);
$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->jobList = $this->createMock(IJobList::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->userManager = $this->createMock(IUserManager::class);
Expand Down
14 changes: 7 additions & 7 deletions tests/lib/AppFramework/Routing/RoutingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
use OC\AppFramework\Routing\RouteConfig;
use OC\Route\Route;
use OC\Route\Router;
use OCP\ILogger;
use OCP\Route\IRouter;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;

class RoutingTest extends \Test\TestCase {
public function testSimpleRoute() {
Expand Down Expand Up @@ -133,7 +133,7 @@ public function testSimpleRouteWithBrokenName() {
/** @var IRouter|MockObject $router */
$router = $this->getMockBuilder(Router::class)
->onlyMethods(['create'])
->setConstructorArgs([$this->createMock(ILogger::class)])
->setConstructorArgs([$this->createMock(LoggerInterface::class)])
->getMock();

// load route configuration
Expand All @@ -154,7 +154,7 @@ public function testSimpleOCSRouteWithBrokenName() {
/** @var IRouter|MockObject $router */
$router = $this->getMockBuilder(Router::class)
->onlyMethods(['create'])
->setConstructorArgs([$this->createMock(ILogger::class)])
->setConstructorArgs([$this->createMock(LoggerInterface::class)])
->getMock();

// load route configuration
Expand Down Expand Up @@ -214,7 +214,7 @@ private function assertSimpleRoute($routes, $name, $verb, $url, $controllerName,
/** @var IRouter|MockObject $router */
$router = $this->getMockBuilder(Router::class)
->onlyMethods(['create'])
->setConstructorArgs([$this->createMock(ILogger::class)])
->setConstructorArgs([$this->createMock(LoggerInterface::class)])
->getMock();

// we expect create to be called once:
Expand Down Expand Up @@ -264,7 +264,7 @@ private function assertSimpleOCSRoute($routes,
/** @var IRouter|MockObject $router */
$router = $this->getMockBuilder(Router::class)
->onlyMethods(['create'])
->setConstructorArgs([$this->createMock(ILogger::class)])
->setConstructorArgs([$this->createMock(LoggerInterface::class)])
->getMock();

// we expect create to be called once:
Expand All @@ -291,7 +291,7 @@ private function assertOCSResource($yaml, $resourceName, $url, $controllerName,
/** @var IRouter|MockObject $router */
$router = $this->getMockBuilder(Router::class)
->onlyMethods(['create'])
->setConstructorArgs([$this->createMock(ILogger::class)])
->setConstructorArgs([$this->createMock(LoggerInterface::class)])
->getMock();

// route mocks
Expand Down Expand Up @@ -351,7 +351,7 @@ private function assertResource($yaml, $resourceName, $url, $controllerName, $pa
/** @var IRouter|MockObject $router */
$router = $this->getMockBuilder(Router::class)
->onlyMethods(['create'])
->setConstructorArgs([$this->createMock(ILogger::class)])
->setConstructorArgs([$this->createMock(LoggerInterface::class)])
->getMock();

// route mocks
Expand Down
32 changes: 16 additions & 16 deletions tests/lib/DB/QueryBuilder/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
use OC\SystemConfig;
use OCP\DB\QueryBuilder\IQueryFunction;
use OCP\IDBConnection;
use OCP\ILogger;
use Psr\Log\LoggerInterface;

/**
* Class QueryBuilderTest
Expand All @@ -49,15 +49,15 @@ class QueryBuilderTest extends \Test\TestCase {
/** @var SystemConfig|\PHPUnit\Framework\MockObject\MockObject */
protected $config;

/** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
protected $logger;

protected function setUp(): void {
parent::setUp();

$this->connection = \OC::$server->getDatabaseConnection();
$this->config = $this->createMock(SystemConfig::class);
$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->queryBuilder = new QueryBuilder($this->connection, $this->config, $this->logger);
}

Expand Down Expand Up @@ -176,7 +176,7 @@ public function testMaxResults($maxResult, $expectedSet) {

public function dataSelect() {
$config = $this->createMock(SystemConfig::class);
$logger = $this->createMock(ILogger::class);
$logger = $this->createMock(LoggerInterface::class);
$queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger);
return [
// select('column1')
Expand Down Expand Up @@ -244,7 +244,7 @@ public function testSelect($selectArguments, $expected, $expectedLiteral = '') {

public function dataSelectAlias() {
$config = $this->createMock(SystemConfig::class);
$logger = $this->createMock(ILogger::class);
$logger = $this->createMock(LoggerInterface::class);
$queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger);
return [
['configvalue', 'cv', ['cv' => '99']],
Expand Down Expand Up @@ -353,7 +353,7 @@ public function testSelectDistinctMultiple() {

public function dataAddSelect() {
$config = $this->createMock(SystemConfig::class);
$logger = $this->createMock(ILogger::class);
$logger = $this->createMock(LoggerInterface::class);
$queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger);
return [
// addSelect('column1')
Expand Down Expand Up @@ -508,7 +508,7 @@ public function testInsert($tableName, $expectedQueryPart, $expectedQuery) {

public function dataFrom() {
$config = $this->createMock(SystemConfig::class);
$logger = $this->createMock(ILogger::class);
$logger = $this->createMock(LoggerInterface::class);
$qb = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger);
return [
[$qb->createFunction('(' . $qb->select('*')->from('test')->getSQL() . ')'), 'q', null, null, [
Expand Down Expand Up @@ -1212,7 +1212,7 @@ public function testGetLastInsertId() {

public function dataGetTableName() {
$config = $this->createMock(SystemConfig::class);
$logger = $this->createMock(ILogger::class);
$logger = $this->createMock(LoggerInterface::class);
$qb = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger);
return [
['*PREFIX*table', null, '`*PREFIX*table`'],
Expand Down Expand Up @@ -1414,12 +1414,12 @@ public function testExecuteWithParameterTooLarge() {
->willReturn($this->createMock(Result::class));
$this->logger
->expects($this->once())
->method('logException')
->willReturnCallback(function ($e, $parameters) {
$this->assertInstanceOf(QueryException::class, $e);
->method('error')
->willReturnCallback(function ($message, $parameters) {
$this->assertInstanceOf(QueryException::class, $parameters['exception']);
$this->assertSame(
'More than 1000 expressions in a list are not allowed on Oracle.',
$parameters['message']
$message
);
});
$this->config
Expand Down Expand Up @@ -1449,12 +1449,12 @@ public function testExecuteWithParametersTooMany() {
->willReturn($this->createMock(Result::class));
$this->logger
->expects($this->once())
->method('logException')
->willReturnCallback(function ($e, $parameters) {
$this->assertInstanceOf(QueryException::class, $e);
->method('error')
->willReturnCallback(function ($message, $parameters) {
$this->assertInstanceOf(QueryException::class, $parameters['exception']);
$this->assertSame(
'The number of parameters must not exceed 65535. Restriction by PostgreSQL.',
$parameters['message']
$message
);
});
$this->config
Expand Down
7 changes: 3 additions & 4 deletions tests/lib/Encryption/EncryptionWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
use OC\Encryption\Manager;
use OC\Memcache\ArrayCache;
use OCP\Files\Storage;
use OCP\ILogger;
use Psr\Log\LoggerInterface;
use Test\TestCase;

class EncryptionWrapperTest extends TestCase {

/** @var EncryptionWrapper */
private $instance;

/** @var \PHPUnit\Framework\MockObject\MockObject | \OCP\ILogger */
/** @var \PHPUnit\Framework\MockObject\MockObject | LoggerInterface */
private $logger;

/** @var \PHPUnit\Framework\MockObject\MockObject | \OC\Encryption\Manager */
Expand All @@ -47,8 +47,7 @@ protected function setUp(): void {

$this->arrayCache = $this->createMock(ArrayCache::class);
$this->manager = $this->createMock(Manager::class);
$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(LoggerInterface::class);

$this->instance = new EncryptionWrapper($this->arrayCache, $this->manager, $this->logger);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/Encryption/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use OCP\Encryption\IEncryptionModule;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use Psr\Log\LoggerInterface;
use Test\TestCase;

class ManagerTest extends TestCase {
Expand All @@ -20,7 +20,7 @@ class ManagerTest extends TestCase {
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
private $config;

/** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
private $logger;

/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
Expand All @@ -38,7 +38,7 @@ class ManagerTest extends TestCase {
protected function setUp(): void {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->l10n = $this->createMock(IL10N::class);
$this->view = $this->createMock(View::class);
$this->util = $this->createMock(Util::class);
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/EventDispatcher/SymfonyAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
use OC\EventDispatcher\SymfonyAdapter;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\GenericEvent;
use OCP\ILogger;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\Event as SymfonyEvent;
use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand All @@ -43,7 +43,7 @@ class SymfonyAdapterTest extends TestCase {
/** @var EventDispatcher|MockObject */
private $eventDispatcher;

/** @var ILogger|MockObject */
/** @var LoggerInterface|MockObject */
private $logger;

/** @var EventDispatcherInterface */
Expand All @@ -53,7 +53,7 @@ protected function setUp(): void {
parent::setUp();

$this->eventDispatcher = $this->createMock(EventDispatcher::class);
$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(LoggerInterface::class);

$this->adapter = new SymfonyAdapter(
$this->eventDispatcher,
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Files/Config/UserMountCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
use OC\DB\QueryBuilder\Literal;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Storage;
use OC\Log;
use OC\User\Manager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\ICachedMountInfo;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
use Test\Util\User\Dummy;
Expand Down Expand Up @@ -66,7 +66,7 @@ protected function setUp(): void {
$userBackend->createUser('u2', '');
$userBackend->createUser('u3', '');
$this->userManager->registerBackend($userBackend);
$this->cache = new \OC\Files\Config\UserMountCache($this->connection, $this->userManager, $this->createMock(Log::class));
$this->cache = new \OC\Files\Config\UserMountCache($this->connection, $this->userManager, $this->createMock(LoggerInterface::class));
}

protected function tearDown(): void {
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/Files/EtagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OC\Files\Filesystem;
use OCP\EventDispatcher\IEventDispatcher;
use OCA\Files_Sharing\AppInfo\Application;
use Psr\Log\LoggerInterface;

/**
* Class EtagTest
Expand Down Expand Up @@ -69,7 +70,7 @@ public function testNewUser() {
$files = ['/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt'];
$originalEtags = $this->getEtags($files);

$scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection(), \OC::$server->query(IEventDispatcher::class), \OC::$server->getLogger());
$scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection(), \OC::$server->query(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
$scanner->backgroundScan('/');

$newEtags = $this->getEtags($files);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
use OC\Files\Storage\StorageFactory;
use OCP\Files\Storage\IStorageFactory;
use OCP\IConfig;
use OCP\ILogger;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;

/**
* @group DB
Expand All @@ -43,7 +43,7 @@ class ObjectStorePreviewCacheMountProviderTest extends \Test\TestCase {
/** @var ObjectStorePreviewCacheMountProvider */
protected $provider;

/** @var ILogger|MockObject */
/** @var LoggerInterface|MockObject */
protected $logger;
/** @var IConfig|MockObject */
protected $config;
Expand All @@ -54,7 +54,7 @@ class ObjectStorePreviewCacheMountProviderTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();

$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->config = $this->createMock(IConfig::class);
$this->loader = $this->createMock(StorageFactory::class);

Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Files/Node/HookConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
use OCP\Files\Events\Node\NodeTouchedEvent;
use OCP\Files\Events\Node\NodeWrittenEvent;
use OCP\Files\Node;
use OCP\ILogger;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Test\TestCase;
Expand Down Expand Up @@ -77,7 +77,7 @@ protected function setUp(): void {
$this->view,
\OC::$server->getUserManager()->get($this->userId),
\OC::$server->getUserMountCache(),
$this->createMock(ILogger::class),
$this->createMock(LoggerInterface::class),
$this->createMock(IUserManager::class),
$this->createMock(IEventDispatcher::class)
);
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Files/Node/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use OC\Files\View;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Mount\IMountManager;
use OCP\ILogger;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use Test\Traits\UserTrait;

/**
Expand Down Expand Up @@ -59,7 +59,7 @@ protected function setUp(): void {
$this->view,
$user,
\OC::$server->getUserMountCache(),
$this->createMock(ILogger::class),
$this->createMock(LoggerInterface::class),
$this->createMock(IUserManager::class),
$this->createMock(IEventDispatcher::class)
);
Expand Down
Loading