Switch from OC::$server->get to OCP\Server::get
And add a bit more typing to some classes + psalm issues Signed-off-by: Carl Schwan <carl@carlschwan.eu>
This commit is contained in:
committed by
Julius Härtl
parent
2c7708dab1
commit
44481e1c2a
@@ -24,8 +24,10 @@
|
||||
namespace OCA\Deck\Db;
|
||||
|
||||
use OCA\Deck\Service\CirclesService;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Server;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Test\AppFramework\Db\MapperTestUtility;
|
||||
|
||||
@@ -46,15 +48,15 @@ class AclMapperTest extends MapperTestUtility {
|
||||
public function setup(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->dbConnection = \OC::$server->getDatabaseConnection();
|
||||
$this->dbConnection = Server::get(IDBConnection::class);
|
||||
$this->aclMapper = new AclMapper($this->dbConnection);
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||
$this->boardMapper = new BoardMapper(
|
||||
$this->dbConnection,
|
||||
\OC::$server->query(LabelMapper::class),
|
||||
Server::get(LabelMapper::class),
|
||||
$this->aclMapper,
|
||||
\OC::$server->query(StackMapper::class),
|
||||
Server::get(StackMapper::class),
|
||||
$this->userManager,
|
||||
$this->groupManager,
|
||||
$this->createMock(CirclesService::class),
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace OCA\Deck\Db;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Server;
|
||||
use Test\AppFramework\Db\MapperTestUtility;
|
||||
|
||||
/**
|
||||
@@ -52,7 +53,7 @@ class AttachmentMapperTest extends MapperTestUtility {
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->cardMapper = $this->createMock(CardMapper::class);
|
||||
|
||||
$this->dbConnection = \OC::$server->getDatabaseConnection();
|
||||
$this->dbConnection = Server::get(IDBConnection::class);
|
||||
$this->attachmentMapper = new AttachmentMapper(
|
||||
$this->dbConnection,
|
||||
$this->cardMapper,
|
||||
|
||||
@@ -27,6 +27,7 @@ use OCA\Deck\Service\CirclesService;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Server;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Test\AppFramework\Db\MapperTestUtility;
|
||||
|
||||
@@ -56,19 +57,19 @@ class BoardMapperTest extends MapperTestUtility {
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||
|
||||
$this->dbConnection = \OC::$server->getDatabaseConnection();
|
||||
$this->dbConnection = Server::get(IDBConnection::class);
|
||||
$this->boardMapper = new BoardMapper(
|
||||
$this->dbConnection,
|
||||
\OC::$server->query(LabelMapper::class),
|
||||
\OC::$server->query(AclMapper::class),
|
||||
\OC::$server->query(StackMapper::class),
|
||||
Server::get(LabelMapper::class),
|
||||
Server::get(AclMapper::class),
|
||||
Server::get(StackMapper::class),
|
||||
$this->userManager,
|
||||
$this->groupManager,
|
||||
$this->createMock(CirclesService::class),
|
||||
$this->createMock(LoggerInterface::class)
|
||||
);
|
||||
$this->aclMapper = \OC::$server->query(AclMapper::class);
|
||||
$this->labelMapper = \OC::$server->query(LabelMapper::class);
|
||||
$this->aclMapper = Server::get(AclMapper::class);
|
||||
$this->labelMapper = Server::get(LabelMapper::class);
|
||||
|
||||
$this->boards = [
|
||||
$this->boardMapper->insert($this->getBoard('MyBoard 1', 'user1')),
|
||||
@@ -89,8 +90,7 @@ class BoardMapperTest extends MapperTestUtility {
|
||||
$board->resetUpdatedFields();
|
||||
}
|
||||
}
|
||||
/** @return Acl */
|
||||
public function getAcl($type = 'user', $participant = 'admin', $edit = false, $share = false, $manage = false, $boardId = 123) {
|
||||
public function getAcl($type = 'user', $participant = 'admin', $edit = false, $share = false, $manage = false, $boardId = 123): ACL {
|
||||
$acl = new Acl();
|
||||
$acl->setParticipant($participant);
|
||||
$acl->setType('user');
|
||||
@@ -101,8 +101,7 @@ class BoardMapperTest extends MapperTestUtility {
|
||||
return $acl;
|
||||
}
|
||||
|
||||
/** @return Board */
|
||||
public function getBoard($title, $owner) {
|
||||
public function getBoard($title, $owner): Board {
|
||||
$board = new Board();
|
||||
$board->setTitle($title);
|
||||
$board->setOwner($owner);
|
||||
|
||||
@@ -33,6 +33,7 @@ use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\L10N\IFactory;
|
||||
use OCP\Notification\INotification;
|
||||
use OCP\Server;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class NotifierTest extends \Test\TestCase {
|
||||
@@ -70,7 +71,7 @@ class NotifierTest extends \Test\TestCase {
|
||||
$this->stackMapper,
|
||||
$this->boardMapper
|
||||
);
|
||||
$this->l10n = \OC::$server->getL10N('deck');
|
||||
$this->l10n = Server::get(IFactory::class)->get('deck');
|
||||
$this->l10nFactory->expects($this->once())
|
||||
->method('get')
|
||||
->willReturn($this->l10n);
|
||||
@@ -78,7 +79,7 @@ class NotifierTest extends \Test\TestCase {
|
||||
|
||||
public function testPrepareWrongApp() {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
/** @var INotification $notification */
|
||||
/** @var INotification|MockObject $notification */
|
||||
$notification = $this->createMock(INotification::class);
|
||||
$notification->expects($this->once())
|
||||
->method('getApp')
|
||||
@@ -88,7 +89,7 @@ class NotifierTest extends \Test\TestCase {
|
||||
}
|
||||
|
||||
public function testPrepareCardOverdue() {
|
||||
/** @var INotification $notification */
|
||||
/** @var INotification|MockObject $notification */
|
||||
$notification = $this->createMock(INotification::class);
|
||||
$notification->expects($this->once())
|
||||
->method('getApp')
|
||||
@@ -131,7 +132,7 @@ class NotifierTest extends \Test\TestCase {
|
||||
}
|
||||
|
||||
public function testPrepareCardCommentMentioned() {
|
||||
/** @var INotification $notification */
|
||||
/** @var INotification|MockObject $notification */
|
||||
$notification = $this->createMock(INotification::class);
|
||||
$notification->expects($this->once())
|
||||
->method('getApp')
|
||||
@@ -188,7 +189,7 @@ class NotifierTest extends \Test\TestCase {
|
||||
->method('findStackFromCardId')
|
||||
->willReturn($this->buildMockStack(123));
|
||||
|
||||
/** @var INotification $notification */
|
||||
/** @var INotification|MockObject $notification */
|
||||
$notification = $this->createMock(INotification::class);
|
||||
$notification->expects($this->once())
|
||||
->method('getApp')
|
||||
@@ -272,7 +273,7 @@ class NotifierTest extends \Test\TestCase {
|
||||
|
||||
/** @dataProvider dataPrepareBoardShared */
|
||||
public function testPrepareBoardShared($withUserFound = true) {
|
||||
/** @var INotification $notification */
|
||||
/** @var INotification|MockObject $notification */
|
||||
$notification = $this->createMock(INotification::class);
|
||||
$notification->expects($this->once())
|
||||
->method('getApp')
|
||||
|
||||
@@ -39,9 +39,11 @@ use OCA\Deck\NoPermissionException;
|
||||
use OCA\Deck\Notification\NotificationHelper;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IConfig;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IGroupManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use \Test\TestCase;
|
||||
use OCP\IURLGenerator;
|
||||
|
||||
@@ -80,6 +82,8 @@ class BoardServiceTest extends TestCase {
|
||||
private $userId = 'admin';
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
/** @var IDBConnection|MockObject */
|
||||
private $connection;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
@@ -99,6 +103,7 @@ class BoardServiceTest extends TestCase {
|
||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->connection = $this->createMock(IDBConnection::class);
|
||||
|
||||
$this->service = new BoardService(
|
||||
$this->boardMapper,
|
||||
@@ -117,6 +122,7 @@ class BoardServiceTest extends TestCase {
|
||||
$this->eventDispatcher,
|
||||
$this->changeHelper,
|
||||
$this->urlGenerator,
|
||||
$this->connection,
|
||||
$this->userId
|
||||
);
|
||||
|
||||
|
||||
@@ -38,9 +38,11 @@ use OCA\Deck\StatusException;
|
||||
use OCP\Activity\IEvent;
|
||||
use OCP\Comments\ICommentsManager;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Test\TestCase;
|
||||
use OCP\IURLGenerator;
|
||||
@@ -76,9 +78,12 @@ class CardServiceTest extends TestCase {
|
||||
private $eventDispatcher;
|
||||
/** @var ChangeHelper|MockObject */
|
||||
private $changeHelper;
|
||||
|
||||
/** @var IURLGenerator|MockObject */
|
||||
private $urlGenerator;
|
||||
/** @var IRequest|MockObject */
|
||||
private $request;
|
||||
/** @var LoggerInterface|MockObject */
|
||||
private $logger;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
@@ -97,6 +102,11 @@ class CardServiceTest extends TestCase {
|
||||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->request = $this->createMock(IRequest::class);
|
||||
|
||||
$this->logger->expects($this->any())->method('error');
|
||||
|
||||
$this->cardService = new CardService(
|
||||
$this->cardMapper,
|
||||
$this->stackMapper,
|
||||
@@ -113,6 +123,8 @@ class CardServiceTest extends TestCase {
|
||||
$this->changeHelper,
|
||||
$this->eventDispatcher,
|
||||
$this->urlGenerator,
|
||||
$this->logger,
|
||||
$this->request,
|
||||
'user1'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -27,11 +27,11 @@ use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Server;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class TrelloJsonServiceTest extends \Test\TestCase {
|
||||
/** @var TrelloJsonService */
|
||||
private $service;
|
||||
private TrelloJsonService $service;
|
||||
/** @var IURLGenerator|MockObject */
|
||||
private $urlGenerator;
|
||||
/** @var IUserManager|MockObject */
|
||||
@@ -128,7 +128,7 @@ class TrelloJsonServiceTest extends \Test\TestCase {
|
||||
}
|
||||
|
||||
public function testGetBoardWithSuccess() {
|
||||
$importService = \OC::$server->get(BoardImportService::class);
|
||||
$importService = Server::get(BoardImportService::class);
|
||||
|
||||
$data = json_decode(file_get_contents(__DIR__ . '/../../../../data/data-trelloJson.json'));
|
||||
$importService->setData($data);
|
||||
|
||||
@@ -33,6 +33,7 @@ use OCA\Deck\Db\Label;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
use OCA\Deck\Db\Stack;
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use \Test\TestCase;
|
||||
|
||||
/**
|
||||
@@ -67,6 +68,8 @@ class StackServiceTest extends TestCase {
|
||||
private $activityManager;
|
||||
/** @var ChangeHelper|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $changeHelper;
|
||||
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $logger;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
@@ -81,6 +84,7 @@ class StackServiceTest extends TestCase {
|
||||
$this->labelMapper = $this->createMock(LabelMapper::class);
|
||||
$this->activityManager = $this->createMock(ActivityManager::class);
|
||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
|
||||
$this->stackService = new StackService(
|
||||
$this->stackMapper,
|
||||
@@ -93,7 +97,8 @@ class StackServiceTest extends TestCase {
|
||||
$this->assignedUsersMapper,
|
||||
$this->attachmentService,
|
||||
$this->activityManager,
|
||||
$this->changeHelper
|
||||
$this->changeHelper,
|
||||
$this->logger
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ class BoardControllerTest extends \Test\TestCase {
|
||||
$this->boardService->expects($this->once())
|
||||
->method('deleteAcl')
|
||||
->with(1)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->deleteAcl(1));
|
||||
->willReturn(true);
|
||||
$this->assertEquals(true, $this->controller->deleteAcl(1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ use OCA\Deck\Service\PermissionService;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IInitialStateService;
|
||||
use OCP\IRequest;
|
||||
use OCP\IConfig;
|
||||
use OCP\IURLGenerator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -53,6 +54,8 @@ class PageControllerTest extends TestCase {
|
||||
* @var mixed|CardService|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $cardService;
|
||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $config;
|
||||
|
||||
public function setUp(): void {
|
||||
$this->request = $this->createMock(IRequest::class);
|
||||
@@ -63,6 +66,7 @@ class PageControllerTest extends TestCase {
|
||||
$this->cardMapper = $this->createMock(CardMapper::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->cardService = $this->createMock(CardService::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
|
||||
$this->controller = new PageController(
|
||||
'deck',
|
||||
@@ -73,7 +77,8 @@ class PageControllerTest extends TestCase {
|
||||
$this->eventDispatcher,
|
||||
$this->cardMapper,
|
||||
$this->urlGenerator,
|
||||
$this->cardService
|
||||
$this->cardService,
|
||||
$this->config
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user