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:
Carl Schwan
2022-05-11 11:38:07 +02:00
committed by Julius Härtl
parent 2c7708dab1
commit 44481e1c2a
45 changed files with 1034 additions and 506 deletions

View File

@@ -28,6 +28,10 @@ use OCA\Deck\Service\AssignmentService;
use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\StackService;
use OCA\Deck\Service\CardService;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Server;
/**
* @group DB
@@ -56,7 +60,7 @@ class AssignmentMapperTest extends \Test\TestCase {
$backend = new \Test\Util\User\Dummy();
\OC_User::useBackend($backend);
\OC::$server->getUserManager()->registerBackend($backend);
Server::get(IUserManager::class)->registerBackend($backend);
$backend->createUser(self::TEST_USER1, self::TEST_USER1);
$backend->createUser(self::TEST_USER2, self::TEST_USER2);
$backend->createUser(self::TEST_USER3, self::TEST_USER3);
@@ -75,17 +79,17 @@ class AssignmentMapperTest extends \Test\TestCase {
$groupBackend->addToGroup(self::TEST_USER3, 'group2');
$groupBackend->addToGroup(self::TEST_USER4, 'group3');
$groupBackend->addToGroup(self::TEST_USER2, self::TEST_GROUP1);
\OC::$server->getGroupManager()->addBackend($groupBackend);
Server::get(IGroupManager::class)->addBackend($groupBackend);
}
public function setUp(): void {
parent::setUp();
\OC::$server->getUserSession()->login(self::TEST_USER1, self::TEST_USER1);
$this->boardService = \OC::$server->query(BoardService::class);
$this->stackService = \OC::$server->query(StackService::class);
$this->cardService = \OC::$server->query(CardService::class);
$this->assignmentService = \OC::$server->query(AssignmentService::class);
$this->assignedUsersMapper = \OC::$server->query(AssignmentMapper::class);
Server::get(IUserSession::class)->login(self::TEST_USER1, self::TEST_USER1);
$this->boardService = Server::get(BoardService::class);
$this->stackService = Server::get(StackService::class);
$this->cardService = Server::get(CardService::class);
$this->assignmentService = Server::get(AssignmentService::class);
$this->assignedUsersMapper = Server::get(AssignmentMapper::class);
$this->createBoardWithExampleData();
}

View File

@@ -21,6 +21,12 @@
*
*/
use OCA\Deck\Db\Board;
use OCA\Deck\Service\BoardService;
use OCP\IGroupManager;
use OCP\IUserSession;
use OCP\Server;
/**
* @group DB
*/
@@ -31,7 +37,7 @@ class BoardDatabaseTest extends \Test\TestCase {
public const TEST_USER4 = "test-share-user4";
public const TEST_GROUP1 = "test-share-group1";
/** @var \OCA\Deck\Service\BoardService */
/** @var BoardService */
private $boardService;
public static function setUpBeforeClass(): void {
@@ -57,15 +63,15 @@ class BoardDatabaseTest extends \Test\TestCase {
$groupBackend->addToGroup(self::TEST_USER3, 'group2');
$groupBackend->addToGroup(self::TEST_USER4, 'group3');
$groupBackend->addToGroup(self::TEST_USER2, self::TEST_GROUP1);
\OC::$server->getGroupManager()->addBackend($groupBackend);
Server::get(IGroupManager::class)->addBackend($groupBackend);
}
public function setUp(): void {
parent::setUp();
\OC::$server->getUserSession()->login(self::TEST_USER1, self::TEST_USER1);
$this->boardService = \OC::$server->query("\OCA\Deck\Service\BoardService");
Server::get(IUserSession::class)->login(self::TEST_USER1, self::TEST_USER1);
$this->boardService = Server::get(BoardService::class);
}
public function testCreate() {
$board = new \OCA\Deck\Db\Board();
$board = new Board();
$board->setTitle('Test');
$board->setOwner(self::TEST_USER1);
$board->setColor('000000');

View File

@@ -7,6 +7,10 @@ use OCA\Deck\Db\Assignment;
use OCA\Deck\Db\AssignmentMapper;
use OCA\Deck\Db\Board;
use OCA\Deck\Db\Card;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Server;
/**
* @group DB
@@ -38,7 +42,7 @@ class TransferOwnershipTest extends \Test\TestCase {
$backend = new \Test\Util\User\Dummy();
\OC_User::useBackend($backend);
\OC::$server->getUserManager()->registerBackend($backend);
Server::get(IUserManager::class)->registerBackend($backend);
$backend->createUser(self::TEST_USER_1, self::TEST_USER_1);
$backend->createUser(self::TEST_USER_2, self::TEST_USER_2);
$backend->createUser(self::TEST_USER_3, self::TEST_USER_3);
@@ -46,17 +50,17 @@ class TransferOwnershipTest extends \Test\TestCase {
$groupBackend = new \Test\Util\Group\Dummy();
$groupBackend->createGroup(self::TEST_GROUP);
$groupBackend->addToGroup(self::TEST_USER_1, self::TEST_GROUP);
\OC::$server->getGroupManager()->addBackend($groupBackend);
Server::get(IGroupManager::class)->addBackend($groupBackend);
}
public function setUp(): void {
parent::setUp();
\OC::$server->getUserSession()->login(self::TEST_USER_1, self::TEST_USER_1);
$this->boardService = \OC::$server->query(BoardService::class);
$this->stackService = \OC::$server->query(StackService::class);
$this->cardService = \OC::$server->query(CardService::class);
$this->assignmentService = \OC::$server->query(AssignmentService::class);
$this->assignmentMapper = \OC::$server->query(AssignmentMapper::class);
Server::get(IUserSession::class)->login(self::TEST_USER_1, self::TEST_USER_1);
$this->boardService = Server::get(BoardService::class);
$this->stackService = Server::get(StackService::class);
$this->cardService = Server::get(CardService::class);
$this->assignmentService = Server::get(AssignmentService::class);
$this->assignmentMapper = Server::get(AssignmentMapper::class);
$this->createBoardWithExampleData();
}

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.22.0@fc2c6ab4d5fa5d644d8617089f012f3bb84b8703">
<files psalm-version="4.23.0@f1fe6ff483bf325c803df9f510d09a03fd796f88">
<file src="lib/Activity/ActivityManager.php">
<TypeDoesNotContainType occurrences="1">
<code>$message !== null</code>
@@ -81,29 +81,6 @@
<code>NotFound</code>
</UndefinedClass>
</file>
<file src="lib/Db/AclMapper.php">
<ParamNameMismatch occurrences="1">
<code>$aclId</code>
</ParamNameMismatch>
</file>
<file src="lib/Db/AssignmentMapper.php">
<ParamNameMismatch occurrences="1">
<code>$cardId</code>
</ParamNameMismatch>
</file>
<file src="lib/Db/BoardMapper.php">
<ParamNameMismatch occurrences="1">
<code>$boardId</code>
</ParamNameMismatch>
<TypeDoesNotContainType occurrences="6">
<code>$limit !== null</code>
<code>$limit !== null</code>
<code>$limit !== null</code>
<code>$offset !== null</code>
<code>$offset !== null</code>
<code>$offset !== null</code>
</TypeDoesNotContainType>
</file>
<file src="lib/Db/Card.php">
<UndefinedClass occurrences="2">
<code>VCalendar</code>
@@ -114,39 +91,10 @@
<InvalidScalarArgument occurrences="1">
<code>$entity-&gt;getId()</code>
</InvalidScalarArgument>
<ParamNameMismatch occurrences="1">
<code>$cardId</code>
</ParamNameMismatch>
<UndefinedInterfaceMethod occurrences="1">
<code>getUserIdGroups</code>
</UndefinedInterfaceMethod>
</file>
<file src="lib/Db/ChangeHelper.php">
<UndefinedThisPropertyAssignment occurrences="3">
<code>$this-&gt;cache</code>
<code>$this-&gt;request</code>
<code>$this-&gt;userId</code>
</UndefinedThisPropertyAssignment>
<UndefinedThisPropertyFetch occurrences="6">
<code>$this-&gt;cache</code>
<code>$this-&gt;cache</code>
<code>$this-&gt;cache</code>
<code>$this-&gt;cache</code>
<code>$this-&gt;request</code>
<code>$this-&gt;userId</code>
</UndefinedThisPropertyFetch>
</file>
<file src="lib/Db/Circle.php">
<UndefinedClass occurrences="1">
<code>\OCA\Circles\Model\Circle</code>
</UndefinedClass>
<UndefinedDocblockClass occurrences="4">
<code>$this-&gt;object</code>
<code>$this-&gt;object</code>
<code>$this-&gt;object</code>
<code>\OCA\Circles\Model\Circle</code>
</UndefinedDocblockClass>
</file>
<file src="lib/Db/LabelMapper.php">
<ParamNameMismatch occurrences="1">
<code>$labelId</code>
@@ -158,29 +106,11 @@
<code>VCalendar</code>
</UndefinedClass>
</file>
<file src="lib/Db/StackMapper.php">
<ParamNameMismatch occurrences="1">
<code>$stackId</code>
</ParamNameMismatch>
</file>
<file src="lib/Migration/Version10800Date20220422061816.php">
<MoreSpecificImplementedParamType occurrences="1">
<code>$schemaClosure</code>
</MoreSpecificImplementedParamType>
</file>
<file src="lib/Notification/Notifier.php">
<RedundantCast occurrences="4">
<code>(string) $l-&gt;t('%s has mentioned you in a comment on "%s".', [$dn, $params[0]])</code>
<code>(string) $l-&gt;t('The board "%s" has been shared with you by %s.', [$params[0], $dn])</code>
<code>(string) $l-&gt;t('The card "%s" on "%s" has been assigned to you by %s.', [$params[0], $params[1], $dn])</code>
<code>(string) $l-&gt;t('The card "%s" on "%s" has reached its due date.', $params)</code>
</RedundantCast>
</file>
<file src="lib/Provider/DeckProvider.php">
<InvalidPropertyAssignmentValue occurrences="1">
<code>[]</code>
</InvalidPropertyAssignmentValue>
</file>
<file src="lib/Service/AssignmentService.php">
<InvalidScalarArgument occurrences="2">
<code>$cardId</code>
@@ -196,75 +126,15 @@
<code>findAll</code>
</TooManyArguments>
</file>
<file src="lib/Service/CardService.php">
<UndefinedDocblockClass occurrences="1">
<code>\OCP\AppFramework\Db\</code>
</UndefinedDocblockClass>
</file>
<file src="lib/Service/CirclesService.php">
<UndefinedClass occurrences="1">
<code>?Circle</code>
</UndefinedClass>
<UndefinedDocblockClass occurrences="3">
<code>$circlesManager</code>
<code>$circlesManager</code>
<code>$circlesManager</code>
</UndefinedDocblockClass>
</file>
<file src="lib/Service/CommentService.php">
<UndefinedThisPropertyAssignment occurrences="2">
<code>$this-&gt;cardMapper</code>
<code>$this-&gt;permissionService</code>
</UndefinedThisPropertyAssignment>
<UndefinedThisPropertyFetch occurrences="8">
<code>$this-&gt;cardMapper</code>
<code>$this-&gt;cardMapper</code>
<code>$this-&gt;cardMapper</code>
<code>$this-&gt;cardMapper</code>
<code>$this-&gt;permissionService</code>
<code>$this-&gt;permissionService</code>
<code>$this-&gt;permissionService</code>
<code>$this-&gt;permissionService</code>
</UndefinedThisPropertyFetch>
</file>
<file src="lib/Service/DefaultBoardService.php">
<TypeDoesNotContainNull occurrences="6">
<code>$color === false || $color === null</code>
<code>$color === null</code>
<code>$title === false || $title === null</code>
<code>$title === null</code>
<code>$userId === false || $userId === null</code>
<code>$userId === null</code>
</TypeDoesNotContainNull>
<TypeDoesNotContainType occurrences="3">
<code>$color === false</code>
<code>$title === false</code>
<code>$userId === false</code>
</TypeDoesNotContainType>
<UndefinedClass occurrences="1"/>
</file>
<file src="lib/Service/FileService.php">
<MissingDependency occurrences="2">
<code>$this-&gt;rootFolder</code>
<code>IRootFolder</code>
</MissingDependency>
<RedundantCondition occurrences="2">
<code>is_resource($content)</code>
<code>is_resource($content)</code>
</RedundantCondition>
</file>
<file src="lib/Service/FilesAppService.php">
<MissingDependency occurrences="3">
<code>$this-&gt;rootFolder</code>
<code>$this-&gt;rootFolder</code>
<code>IRootFolder</code>
</MissingDependency>
</file>
<file src="lib/Service/PermissionService.php">
<UndefinedClass occurrences="2">
<code>$circle</code>
<code>Member</code>
</UndefinedClass>
</file>
<file src="lib/Service/StackService.php">
<UndefinedClass occurrences="1">
<code>BadRquestException</code>

642
tests/stub.phpstub Normal file
View File

@@ -0,0 +1,642 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2021 Robin Appelman <robin@icewind.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model {
class Member {
public const LEVEL_NONE = 0;
public const LEVEL_MEMBER = 1;
public const LEVEL_MODERATOR = 4;
public const LEVEL_ADMIN = 8;
public const LEVEL_OWNER = 9;
public const TYPE_SINGLE = 0;
public const TYPE_USER = 1;
public const TYPE_GROUP = 2;
public const TYPE_MAIL = 4;
public const TYPE_CONTACT = 8;
public const TYPE_CIRCLE = 16;
public const TYPE_APP = 10000;
public const ALLOWING_ALL_TYPES = 31;
public const APP_CIRCLES = 10001;
public const APP_OCC = 10002;
public const APP_DEFAULT = 11000;
}
class Circle {
public function getUniqueId(): string {}
public function getDisplayName(): string {}
public function getOwner(): string {}
public function getSingleId(): string {}
public function getInheritedMembers(): array {}
}
}
namespace OCA\Circles\Model\Probes {
class CircleProble {
public function __construct() {}
}
}
namespace OCA\Circles {
class CirclesManager {
}
}
namespace {
use OCP\IServerContainer;
class OC {
static $CLI = false;
/** @var IServerContainer */
static $server;
}
}
namespace OC\Files\Node {
use OCP\Files\FileInfo;
abstract class Node implements \OCP\Files\Node {
/** @return FileInfo|\ArrayAccess */
public function getFileInfo() {}
/** @return \OCP\Files\Mount\IMountPoint */
public function getMountPoint() {}
}
}
namespace OC\Hooks {
class Emitter {
public function emit(string $class, string $value, array $option) {}
/** Closure $closure */
public function listen(string $class, string $value, $closure) {}
}
class BasicEmitter extends Emitter {
}
}
namespace OC\Cache {
/**
* @template T
*/
class CappedMemoryCache implements \ArrayAccess {
/** @return ?T */
public function get($key) {}
/** @param T $value */
public function set($key, $value, $ttl = '') {}
#[\ReturnTypeWillChange]
public function &offsetGet($offset) { }
public function offsetSet($offset, $value): void { }
public function offsetUnset($offset): void { }
}
}
namespace OC\Core\Command {
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Base {
public const OUTPUT_FORMAT_PLAIN = 'plain';
public const OUTPUT_FORMAT_JSON = 'json';
public const OUTPUT_FORMAT_JSON_PRETTY = 'json_pretty';
public function __construct() {}
protected function configure() {}
public function run(InputInterface $input, OutputInterface $output) {}
public function setName(string $name) {}
public function getHelper(string $name) {}
protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, $items, $prefix = ' - ') {
}
}
}
namespace OC\Files\ObjectStore {
class NoopScanner {}
}
namespace Symfony\Component\Console\Helper {
use Symfony\Component\Console\Output\OutputInterface;
class Table {
public function __construct(OutputInterface $text) {}
public function setHeaders(array $header) {}
public function setRows(array $rows) {}
public function render() {}
}
}
namespace Symfony\Component\Console\Input {
class InputInterface {
public function getOption(string $key) {}
public function setOption(string $key, $value) {}
public function getArgument(string $key) {}
}
class InputArgument {
const REQUIRED = 0;
const OPTIONAL = 1;
const IS_ARRAY = 1;
}
class InputOption {
const VALUE_NONE = 1;
const VALUE_REQUIRED = 1;
const VALUE_OPTIONAL = 1;
}
}
namespace Symfony\Component\Console\Question {
class ConfirmationQuestion {
public function __construct(string $text, bool $default) {}
}
}
namespace Symfony\Component\Console\Output {
class OutputInterface {
public const VERBOSITY_VERBOSE = 1;
public function writeln($text, int $flat = 0) {}
}
}
namespace OC\Files\Cache {
use OCP\Files\Cache\ICache;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Search\ISearchQuery;
use OCP\Files\Search\ISearchOperator;
use OCP\Files\Search\ISearchQuery;
use OCP\Files\IMimeTypeLoader;
class Cache implements ICache {
/**
* @param \OCP\Files\Cache\ICache $cache
*/
public function __construct($cache) {
$this->cache = $cache;
}
public function getNumericStorageId() { }
public function get() { }
public function getIncomplete() {}
public function getPathById($id) {}
public function getAll() {}
public function get($file) {}
public function getFolderContents($folder) {}
public function getFolderContentsById($fileId) {}
public function put($file, array $data) {}
public function insert($file, array $data) {}
public function update($id, array $data) {}
public function getId($file) {}
public function getParentId($file) {}
public function inCache($file) {}
public function remove($file) {}
public function move($source, $target) {}
public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {}
public function clear() {}
public function getStatus($file) {}
public function search($pattern) {}
public function searchByMime($mimetype) {}
public function searchQuery(ISearchQuery $query) {}
public function correctFolderSize($path, $data = null, $isBackgroundScan = false) {}
public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int {}
public function normalize($path) {}
public function getQueryFilterForStorage(): ISearchOperator {}
public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEntry {}
public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader): ICacheEntry {}
}
}
namespace OC\Files\Cache\Wrapper {
use OC\Files\Cache\Cache;
class CacheWrapper extends Cache {}
}
namespace OC\Files {
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Mount\IMountPoint;
use OCP\IUser;
class Filesystem {
public static function addStorageWrapper(string $wrapperName, callable $wrapper, int $priority = 50) {
}
public static function normalizePath(string $path): string {}
}
class FileInfo implements \OCP\Files\FileInfo {
/**
* @param string|boolean $path
* @param \OCP\Files\Storage\IStorage $storage
* @param string $internalPath
* @param array|ICacheEntry $data
* @param \OCP\Files\Mount\IMountPoint $mount
* @param \OCP\IUser|null $owner
*/
public function __construct($path, $storage, $internalPath, $data, $mount, $owner = null) {}
}
class View {
public function __construct(string $path) {}
public function unlink($path) {}
public function is_dir($path): bool {}
public function mkdir($path) {}
public function getRoot(): string {}
public function getOwner(string $path): string {}
}
}
namespace OC\User {
use OCP\UserInterface;
use OCP\IUser;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class User implements IUser {
public function __construct(string $uid, ?UserInterface $backend, EventDispatcherInterface $dispatcher, $emitter = null, IConfig $config = null, $urlGenerator = null) {}
}
}
namespace OCA\DAV\Upload {
use Sabre\DAV\File;
abstract class FutureFile extends File {}
}
namespace OCA\DAV\Connector\Sabre {
class Node {
public function getFileInfo(): \OCP\Files\FileInfo {}
}
}
namespace OC\BackgroundJob {
use OCP\BackgroundJob\IJob;
use OCP\BackgroundJob\IJobList;
use OCP\ILogger;
abstract class TimedJob implements IJob {
public function execute(IJobList $jobList, ILogger $logger = null) {
}
abstract protected function run($argument);
public function setId(int $id) {
}
public function setLastRun(int $lastRun) {
}
public function setArgument($argument) {
}
public function getId() {
}
public function getLastRun() {
}
public function getArgument() {
}
}
}
namespace OC\Files\Mount {
use OC\Files\Filesystem;
use OC\Files\Storage\Storage;
use OC\Files\Storage\StorageFactory;
use OCP\Files\Mount\IMountPoint;
class MountPoint implements IMountPoint {
/**
* @var \OC\Files\Storage\Storage $storage
*/
protected $storage = null;
protected $class;
protected $storageId;
protected $rootId = null;
/** @var int|null */
protected $mountId;
/**
* @param string|\OCP\Files\Storage\IStorage $storage
* @param string $mountpoint
* @param array $arguments (optional) configuration for the storage backend
* @param \OCP\Files\Storage\IStorageFactory $loader
* @param array $mountOptions mount specific options
* @param int|null $mountId
* @throws \Exception
*/
public function __construct($storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) {
throw new \Exception('stub');
}
/**
* get complete path to the mount point, relative to data/
*
* @return string
*/
public function getMountPoint() {
throw new \Exception('stub');
}
/**
* Sets the mount point path, relative to data/
*
* @param string $mountPoint new mount point
*/
public function setMountPoint($mountPoint) {
throw new \Exception('stub');
}
/**
* @return \OCP\Files\Storage\IStorage
*/
public function getStorage() {
throw new \Exception('stub');
}
/**
* @return string
*/
public function getStorageId() {
throw new \Exception('stub');
}
/**
* @return int
*/
public function getNumericStorageId() {
throw new \Exception('stub');
}
/**
* @param string $path
* @return string
*/
public function getInternalPath($path) {
throw new \Exception('stub');
}
/**
* @param callable $wrapper
*/
public function wrapStorage($wrapper) {
throw new \Exception('stub');
}
/**
* Get a mount option
*
* @param string $name Name of the mount option to get
* @param mixed $default Default value for the mount option
* @return mixed
*/
public function getOption($name, $default) {
throw new \Exception('stub');
}
/**
* Get all options for the mount
*
* @return array
*/
public function getOptions() {
throw new \Exception('stub');
}
/**
* @return int
*/
public function getStorageRootId() {
throw new \Exception('stub');
}
public function getMountId() {
throw new \Exception('stub');
}
public function getMountType() {
throw new \Exception('stub');
}
public function getMountProvider(): string {
throw new \Exception('stub');
}
}
}
namespace OC\Files\Storage\Wrapper{
use OCP\Files\Cache\ICache;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Search\ISearchQuery;
use OCP\Files\Storage\IStorage;
class Wrapper implements IStorage {
public function __construct(array $parameters) {
}
public function getWrapperStorage(): ?IStorage {}
public function getId() {}
public function mkdir($path) {}
public function rmdir($path) {}
public function opendir($path) {
throw new \Exception('stub');
}
public function is_dir($path) {
throw new \Exception('stub');
}
public function is_file($path) {
throw new \Exception('stub');
}
public function stat($path) {
throw new \Exception('stub');
}
public function filetype($path) {
throw new \Exception('stub');
}
public function filesize($path) {
throw new \Exception('stub');
}
public function isCreatable($path) {
throw new \Exception('stub');
}
public function isReadable($path) {
throw new \Exception('stub');
}
public function isUpdatable($path) {
throw new \Exception('stub');
}
public function isDeletable($path) {
throw new \Exception('stub');
}
public function isSharable($path) {
throw new \Exception('stub');
}
public function getPermissions($path) {
throw new \Exception('stub');
}
public function file_exists($path) {
throw new \Exception('stub');
}
public function filemtime($path) {
throw new \Exception('stub');
}
public function file_get_contents($path) {
throw new \Exception('stub');
}
public function file_put_contents($path, $data) {
throw new \Exception('stub');
}
public function unlink($path) {
throw new \Exception('stub');
}
public function rename($path1, $path2) {
throw new \Exception('stub');
}
public function copy($path1, $path2) {
throw new \Exception('stub');
}
public function fopen($path, $mode) {
throw new \Exception('stub');
}
public function getMimeType($path) {
throw new \Exception('stub');
}
public function hash($type, $path, $raw = false) {
throw new \Exception('stub');
}
public function free_space($path) {
throw new \Exception('stub');
}
public function touch($path, $mtime = null) {
throw new \Exception('stub');
}
public function getLocalFile($path) {
throw new \Exception('stub');
}
public function hasUpdated($path, $time) {
throw new \Exception('stub');
}
public function getETag($path) {
throw new \Exception('stub');
}
public function isLocal() {
throw new \Exception('stub');
}
public function instanceOfStorage($class) {
throw new \Exception('stub');
}
public function getDirectDownload($path) {
throw new \Exception('stub');
}
public function verifyPath($path, $fileName) {
throw new \Exception('stub');
}
public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
throw new \Exception('stub');
}
public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
throw new \Exception('stub');
}
public function test() {
throw new \Exception('stub');
}
public function getAvailability() {
throw new \Exception('stub');
}
public function setAvailability($isAvailable) {
throw new \Exception('stub');
}
public function getOwner($path) {
throw new \Exception('stub');
}
public function getCache() {
throw new \Exception('stub');
}
public function getPropagator() {
throw new \Exception('stub');
}
public function getScanner() {
throw new \Exception('stub');
}
public function getUpdater() {
throw new \Exception('stub');
}
public function getWatcher() {
throw new \Exception('stub');
}
}
class Jail extends Wrapper {
public function getUnjailedPath(string $path): string {}
}
class Quota extends Wrapper {
public function getQuota() {}
}
class PermissionsMask extends Wrapper {
public function getQuota() {}
}
}

View File

@@ -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),

View File

@@ -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,

View File

@@ -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);

View File

@@ -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')

View File

@@ -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
);

View File

@@ -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'
);
}

View File

@@ -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);

View File

@@ -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
);
}

View File

@@ -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));
}
}

View File

@@ -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
);
}