<code>$this->application</code>
</UndefinedThisPropertyFetch>
</file>
- <file src="lib/private/Contacts/ContactsMenu/Manager.php">
- <InvalidNullableReturnType occurrences="1">
- <code>IEntry</code>
- </InvalidNullableReturnType>
- <NullableReturnStatement occurrences="1">
- <code>$entry</code>
- </NullableReturnStatement>
- </file>
<file src="lib/private/ContactsManager.php">
<InvalidNullableReturnType occurrences="3">
<code>IAddressBook</code>
*/
namespace OC\Core\Controller;
+use Exception;
use OC\Contacts\ContactsMenu\Manager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\IUserSession;
class ContactsMenuController extends Controller {
+ private Manager $manager;
+ private IUserSession $userSession;
- /** @var Manager */
- private $manager;
-
- /** @var IUserSession */
- private $userSession;
-
- /**
- * @param IRequest $request
- * @param IUserSession $userSession
- * @param Manager $manager
- */
public function __construct(IRequest $request, IUserSession $userSession, Manager $manager) {
parent::__construct('core', $request);
$this->userSession = $userSession;
/**
* @NoAdminRequired
*
- * @param string|null filter
* @return \JsonSerializable[]
+ * @throws Exception
*/
- public function index($filter = null) {
+ public function index(?string $filter = null): array {
return $this->manager->getEntries($this->userSession->getUser(), $filter);
}
/**
* @NoAdminRequired
*
- * @param integer $shareType
- * @param string $shareWith
* @return JSONResponse|\JsonSerializable
+ * @throws Exception
*/
- public function findOne($shareType, $shareWith) {
+ public function findOne(int $shareType, string $shareWith) {
$contact = $this->manager->findOne($this->userSession->getUser(), $shareType, $shareWith);
if ($contact) {
use Psr\Log\LoggerInterface;
class ActionProviderStore {
-
- /** @var IServerContainer */
- private $serverContainer;
-
- /** @var AppManager */
- private $appManager;
-
- /** @var LoggerInterface */
- private $logger;
+ private IServerContainer $serverContainer;
+ private AppManager $appManager;
+ private LoggerInterface $logger;
public function __construct(IServerContainer $serverContainer, AppManager $appManager, LoggerInterface $logger) {
$this->serverContainer = $serverContainer;
foreach ($allClasses as $class) {
try {
- $providers[] = $this->serverContainer->query($class);
+ $providers[] = $this->serverContainer->get($class);
} catch (QueryException $ex) {
$this->logger->error(
'Could not load contacts menu action provider ' . $class,
use OCP\Contacts\ContactsMenu\ILinkAction;
class LinkAction implements ILinkAction {
-
- /** @var string */
- private $icon;
-
- /** @var string */
- private $name;
-
- /** @var string */
- private $href;
-
- /** @var int */
- private $priority = 10;
-
- /** @var string */
- private $appId;
+ private string $icon = '';
+ private string $name = '';
+ private string $href = '';
+ private int $priority = 10;
+ private string $appId = '';
/**
* @param string $icon absolute URI to an icon
*/
- public function setIcon($icon) {
+ public function setIcon(string $icon) {
$this->icon = $icon;
}
- /**
- * @param string $name
- */
- public function setName($name) {
+ public function setName(string $name) {
$this->name = $name;
}
- /**
- * @return string
- */
- public function getName() {
+ public function getName(): string {
return $this->name;
}
- /**
- * @param int $priority
- */
- public function setPriority($priority) {
+ public function setPriority(int $priority) {
$this->priority = $priority;
}
- /**
- * @return int
- */
- public function getPriority() {
+ public function getPriority(): int {
return $this->priority;
}
- /**
- * @param string $href
- */
- public function setHref($href) {
+ public function setHref(string $href) {
$this->href = $href;
}
- /**
- * @return string
- */
- public function getHref() {
+ public function getHref(): string {
return $this->href;
}
/**
- * @param string $appId
* @since 23.0.0
*/
public function setAppId(string $appId) {
}
/**
- * @return string
* @since 23.0.0
*/
public function getAppId(): string {
use OCP\L10N\IFactory as IL10NFactory;
class ContactsStore implements IContactsStore {
-
- /** @var IManager */
- private $contactsManager;
-
- /** @var IConfig */
- private $config;
-
- /** @var ProfileManager */
- private $profileManager;
-
- /** @var IUserManager */
- private $userManager;
-
- /** @var IURLGenerator */
- private $urlGenerator;
-
- /** @var IGroupManager */
- private $groupManager;
-
- /** @var KnownUserService */
- private $knownUserService;
-
- /** @var IL10NFactory */
- private $l10nFactory;
+ private IManager $contactsManager;
+ private IConfig $config;
+ private ProfileManager $profileManager;
+ private IUserManager $userManager;
+ private IURLGenerator $urlGenerator;
+ private IGroupManager $groupManager;
+ private KnownUserService $knownUserService;
+ private IL10NFactory $l10nFactory;
public function __construct(
IManager $contactsManager,
}
/**
- * @param IUser $user
- * @param string|null $filter
* @return IEntry[]
*/
- public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offset = null) {
+ public function getContacts(IUser $user, ?string $filter, ?int $limit = null, ?int $offset = null): array {
$options = [
'enumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes',
'fullmatch' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes',
private function filterContacts(
IUser $self,
array $entries,
- $filter
- ) {
+ ?string $filter
+ ): array {
$disallowEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes';
$restrictEnumerationGroup = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
$restrictEnumerationPhone = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
$selfGroups = $this->groupManager->getUserGroupIds($self);
if ($excludedGroups) {
- $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
+ $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list');
$decodedExcludeGroups = json_decode($excludedGroups, true);
$excludeGroupsList = $decodedExcludeGroups ?? [];
}));
}
- /**
- * @param IUser $user
- * @param integer $shareType
- * @param string $shareWith
- * @return IEntry|null
- */
- public function findOne(IUser $user, $shareType, $shareWith) {
+ public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry {
switch ($shareType) {
case 0:
case 6:
return $match;
}
- /**
- * @param array $contact
- * @return Entry
- */
- private function contactArrayToEntry(array $contact) {
+ private function contactArrayToEntry(array $contact): Entry {
$entry = new Entry();
if (isset($contact['id'])) {
/** @var string|int|null */
private $id = null;
- /** @var string */
- private $fullName = '';
+ private string $fullName = '';
/** @var string[] */
- private $emailAddresses = [];
+ private array $emailAddresses = [];
- /** @var string|null */
- private $avatar;
+ private ?string $avatar = null;
- /** @var string|null */
- private $profileTitle;
+ private ?string $profileTitle = null;
- /** @var string|null */
- private $profileUrl;
+ private ?string $profileUrl = null;
/** @var IAction[] */
- private $actions = [];
+ private array $actions = [];
- /** @var array */
- private $properties = [];
+ private array $properties = [];
- /**
- * @param string $id
- */
public function setId(string $id): void {
$this->id = $id;
}
- /**
- * @param string $displayName
- */
public function setFullName(string $displayName): void {
$this->fullName = $displayName;
}
- /**
- * @return string
- */
public function getFullName(): string {
return $this->fullName;
}
- /**
- * @param string $address
- */
public function addEMailAddress(string $address): void {
$this->emailAddresses[] = $address;
}
return $this->emailAddresses;
}
- /**
- * @param string $avatar
- */
public function setAvatar(string $avatar): void {
$this->avatar = $avatar;
}
- /**
- * @return string
- */
public function getAvatar(): ?string {
return $this->avatar;
}
- /**
- * @param string $profileTitle
- */
public function setProfileTitle(string $profileTitle): void {
$this->profileTitle = $profileTitle;
}
- /**
- * @return string
- */
public function getProfileTitle(): ?string {
return $this->profileTitle;
}
- /**
- * @param string $profileUrl
- */
public function setProfileUrl(string $profileUrl): void {
$this->profileUrl = $profileUrl;
}
- /**
- * @return string
- */
public function getProfileUrl(): ?string {
return $this->profileUrl;
}
- /**
- * @param IAction $action
- */
public function addAction(IAction $action): void {
$this->actions[] = $action;
$this->sortActions();
*/
namespace OC\Contacts\ContactsMenu;
+use Exception;
use OCP\App\IAppManager;
use OCP\Constants;
use OCP\Contacts\ContactsMenu\IEntry;
use OCP\IUser;
class Manager {
+ private ContactsStore $store;
+ private ActionProviderStore $actionProviderStore;
+ private IAppManager $appManager;
+ private IConfig $config;
- /** @var ContactsStore */
- private $store;
-
- /** @var ActionProviderStore */
- private $actionProviderStore;
-
- /** @var IAppManager */
- private $appManager;
-
- /** @var IConfig */
- private $config;
-
- /**
- * @param ContactsStore $store
- * @param ActionProviderStore $actionProviderStore
- * @param IAppManager $appManager
- */
public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager, IConfig $config) {
$this->store = $store;
$this->actionProviderStore = $actionProviderStore;
* @param IUser $user
* @param string|null $filter
* @return array
+ * @throws Exception
*/
- public function getEntries(IUser $user, $filter) {
+ public function getEntries(IUser $user, ?string $filter): array {
$maxAutocompleteResults = max(0, $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT));
- $minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0);
+ $minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength');
$topEntries = [];
if (strlen($filter ?? '') >= $minSearchStringLength) {
$entries = $this->store->getContacts($user, $filter, $maxAutocompleteResults);
}
/**
- * @param IUser $user
- * @param integer $shareType
- * @param string $shareWith
- * @return IEntry
+ * @throws Exception
*/
- public function findOne(IUser $user, $shareType, $shareWith) {
+ public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry {
$entry = $this->store->findOne($user, $shareType, $shareWith);
if ($entry) {
$this->processEntries([$entry], $user);
* @param IEntry[] $entries
* @return IEntry[]
*/
- private function sortEntries(array $entries) {
+ private function sortEntries(array $entries): array {
usort($entries, function (IEntry $entryA, IEntry $entryB) {
return strcasecmp($entryA->getFullName(), $entryB->getFullName());
});
/**
* @param IEntry[] $entries
* @param IUser $user
+ * @throws Exception
*/
private function processEntries(array $entries, IUser $user) {
$providers = $this->actionProviderStore->getProviders($user);
use OCP\IURLGenerator;
class EMailProvider implements IProvider {
+ private IActionFactory $actionFactory;
+ private IURLGenerator $urlGenerator;
- /** @var IActionFactory */
- private $actionFactory;
-
- /** @var IURLGenerator */
- private $urlGenerator;
-
- /**
- * @param IActionFactory $actionFactory
- * @param IURLGenerator $urlGenerator
- */
public function __construct(IActionFactory $actionFactory, IURLGenerator $urlGenerator) {
$this->actionFactory = $actionFactory;
$this->urlGenerator = $urlGenerator;
use OCP\L10N\IFactory as IL10NFactory;
class ProfileProvider implements IProvider {
+ private IActionFactory $actionFactory;
+ private ProfileManager $profileManager;
+ private IL10NFactory $l10nFactory;
+ private IURLGenerator $urlGenerator;
+ private IUserManager $userManager;
- /** @var IActionFactory */
- private $actionFactory;
-
- /** @var ProfileManager */
- private $profileManager;
-
- /** @var IL10NFactory */
- private $l10nFactory;
-
- /** @var IURLGenerator */
- private $urlGenerator;
-
- /** @var IUserManager */
- private $userManager;
-
- /**
- * @param IActionFactory $actionFactory
- * @param ProfileManager $profileManager
- * @param IL10NFactory $l10nFactory
- * @param IURLGenerator $urlGenerator
- * @param IUserManager $userManager
- */
public function __construct(
IActionFactory $actionFactory,
ProfileManager $profileManager,
* @param string $icon absolute URI to an icon
* @since 12.0
*/
- public function setIcon($icon);
+ public function setIcon(string $icon);
/**
* @return string localized action name, e.g. 'Call'
* @since 12.0
*/
- public function getName();
+ public function getName(): string;
/**
* @param string $name localized action name, e.g. 'Call'
* @since 12.0
*/
- public function setName($name);
+ public function setName(string $name);
/**
* @param int $priority priorize actions, high order ones are shown on top
* @since 12.0
*/
- public function setPriority($priority);
+ public function setPriority(int $priority);
/**
* @return int priority to priorize actions, high order ones are shown on top
* @since 12.0
*/
- public function getPriority();
+ public function getPriority(): int;
/**
* @param string $appId
/**
* @param IUser $user
- * @param string $filter
- * @param int $limit added 19.0.2
- * @param int $offset added 19.0.2
+ * @param string|null $filter
+ * @param int|null $limit added 19.0.2
+ * @param int|null $offset added 19.0.2
* @return IEntry[]
* @since 13.0.0
*/
- public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offset = null);
+ public function getContacts(IUser $user, ?string $filter, ?int $limit = null, ?int $offset = null): array;
/**
* @brief finds a contact by specifying the property to search on ($shareType) and the value ($shareWith)
- * @param IUser $user
- * @param integer $shareType
- * @param string $shareWith
- * @return IEntry|null
* @since 13.0.0
*/
- public function findOne(IUser $user, $shareType, $shareWith);
+ public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry;
}
interface ILinkAction extends IAction {
/**
- * @since 12.0
* @param string $href the target URL of the action
+ * @since 12.0
*/
- public function setHref($href);
+ public function setHref(string $href);
/**
* @since 12.0
* @return string
*/
- public function getHref();
+ public function getHref(): string;
}
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ContactsMenuControllerTest extends TestCase {
- /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
- private $request;
-
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IUserSession|MockObject */
private $userSession;
- /** @var Manager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var Manager|MockObject */
private $contactsManager;
- /** @var ContactsMenuController */
- private $controller;
+ private ContactsMenuController $controller;
protected function setUp(): void {
parent::setUp();
- $this->request = $this->createMock(IRequest::class);
+ $request = $this->createMock(IRequest::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->contactsManager = $this->createMock(Manager::class);
- $this->controller = new ContactsMenuController($this->request, $this->userSession, $this->contactsManager);
+ $this->controller = new ContactsMenuController($request, $this->userSession, $this->contactsManager);
}
public function testIndex() {
use Test\TestCase;
class ActionFactoryTest extends TestCase {
-
- /** @var ActionFactory */
- private $actionFactory;
+ private ActionFactory $actionFactory;
protected function setUp(): void {
parent::setUp();
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IServerContainer;
use OCP\IUser;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
class ActionProviderStoreTest extends TestCase {
- /** @var IServerContainer|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IServerContainer|MockObject */
private $serverContainer;
- /** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IAppManager|MockObject */
private $appManager;
- /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
- private $logger;
-
- /** @var ActionProviderStore */
- private $actionProviderStore;
+ private ActionProviderStore $actionProviderStore;
protected function setUp(): void {
parent::setUp();
$this->serverContainer = $this->createMock(IServerContainer::class);
$this->appManager = $this->createMock(AppManager::class);
- $this->logger = $this->createMock(LoggerInterface::class);
+ $logger = $this->createMock(LoggerInterface::class);
- $this->actionProviderStore = new ActionProviderStore($this->serverContainer, $this->appManager, $this->logger);
+ $this->actionProviderStore = new ActionProviderStore($this->serverContainer, $this->appManager, $logger);
}
public function testGetProviders() {
],
]);
$this->serverContainer->expects($this->exactly(3))
- ->method('query')
+ ->method('get')
->willReturnMap([
- [ProfileProvider::class, true, $provider1],
- [EMailProvider::class, true, $provider2],
- ['OCA\Contacts\Provider1', true, $provider3]
+ [ProfileProvider::class, $provider1],
+ [EMailProvider::class, $provider2],
+ ['OCA\Contacts\Provider1', $provider3]
]);
$providers = $this->actionProviderStore->getProviders($user);
->with('contacts')
->willReturn([/* Empty info.xml */]);
$this->serverContainer->expects($this->exactly(2))
- ->method('query')
+ ->method('get')
->willReturnMap([
- [ProfileProvider::class, true, $provider1],
- [EMailProvider::class, true, $provider2],
+ [ProfileProvider::class, $provider1],
+ [EMailProvider::class, $provider2],
]);
$providers = $this->actionProviderStore->getProviders($user);
->with($user)
->willReturn([]);
$this->serverContainer->expects($this->once())
- ->method('query')
+ ->method('get')
->willThrowException(new QueryException());
$this->actionProviderStore->getProviders($user);
use Test\TestCase;
class LinkActionTest extends TestCase {
- private $action;
+ private LinkAction $action;
protected function setUp(): void {
parent::setUp();
public function testGetSetName() {
$name = 'Jane Doe';
- $this->assertNull($this->action->getName());
+ $this->assertEmpty($this->action->getName());
$this->action->setName($name);
$this->assertEquals($name, $this->action->getName());
}
$json = $this->action->jsonSerialize();
$this->assertArrayHasKey('hyperlink', $json);
- $this->assertEquals($json['hyperlink'], '/some/url');
+ $this->assertEquals('/some/url', $json['hyperlink']);
}
public function testJsonSerialize() {
use Test\TestCase;
class ContactsStoreTest extends TestCase {
- /** @var ContactsStore */
- private $contactsStore;
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
+ private ContactsStore $contactsStore;
+ /** @var IManager|MockObject */
private $contactsManager;
/** @var ProfileManager */
private $profileManager;
- /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IUserManager|MockObject */
private $userManager;
/** @var IURLGenerator */
private $urlGenerator;
- /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IGroupManager|MockObject */
private $groupManager;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IConfig|MockObject */
private $config;
/** @var KnownUserService|MockObject */
private $knownUserService;
}
public function testGetContactsWithoutFilter() {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
->method('search')
}
public function testGetContactsHidesOwnEntry() {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
->method('search')
}
public function testGetContactsWithoutBinaryImage() {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
->method('search')
}
public function testGetContactsWithoutAvatarURI() {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
->method('search')
['core', 'shareapi_exclude_groups_list', '', '["group1", "group5", "group6"]'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
+ /** @var IUser|MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->exactly(2))
->method('getUID')
['core', 'shareapi_only_share_with_group_members', 'no', 'yes'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
+ /** @var IUser|MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');
- $this->groupManager->expects($this->at(0))
- ->method('getUserGroupIds')
- ->with($this->equalTo($currentUser))
- ->willReturn(['group1', 'group2', 'group3']);
-
$user1 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(0))
- ->method('get')
- ->with('user1')
- ->willReturn($user1);
- $this->groupManager->expects($this->at(1))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user1))
- ->willReturn(['group1']);
$user2 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(1))
- ->method('get')
- ->with('user2')
- ->willReturn($user2);
- $this->groupManager->expects($this->at(2))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user2))
- ->willReturn(['group2', 'group3']);
$user3 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(2))
- ->method('get')
- ->with('user3')
- ->willReturn($user3);
- $this->groupManager->expects($this->at(3))
+
+ $this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
- ->with($this->equalTo($user3))
- ->willReturn(['group8', 'group9']);
+ ->withConsecutive(
+ [$this->equalTo($currentUser)],
+ [$this->equalTo($user1)],
+ [$this->equalTo($user2)],
+ [$this->equalTo($user3)]
+ )
+ ->willReturnOnConsecutiveCalls(
+ ['group1', 'group2', 'group3'],
+ ['group1'],
+ ['group2', 'group3'],
+ ['group8', 'group9']
+ );
+
+ $this->userManager->expects($this->exactly(3))
+ ->method('get')
+ ->withConsecutive(
+ ['user1'],
+ ['user2'],
+ ['user3']
+ )
+ ->willReturnOnConsecutiveCalls($user1, $user2, $user3);
$this->contactsManager->expects($this->once())
->method('search')
['core', 'shareapi_only_share_with_group_members', 'no', 'yes'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
+ /** @var IUser|MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');
- $this->groupManager->expects($this->at(0))
- ->method('getUserGroupIds')
- ->with($this->equalTo($currentUser))
- ->willReturn(['group1', 'group2', 'group3']);
-
$user1 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(0))
- ->method('get')
- ->with('user1')
- ->willReturn($user1);
- $this->groupManager->expects($this->at(1))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user1))
- ->willReturn(['group1']);
$user2 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(1))
- ->method('get')
- ->with('user2')
- ->willReturn($user2);
- $this->groupManager->expects($this->at(2))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user2))
- ->willReturn(['group2', 'group3']);
$user3 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(2))
- ->method('get')
- ->with('user3')
- ->willReturn($user3);
- $this->groupManager->expects($this->at(3))
+
+ $this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
- ->with($this->equalTo($user3))
- ->willReturn(['group8', 'group9']);
+ ->withConsecutive(
+ [$this->equalTo($currentUser)],
+ [$this->equalTo($user1)],
+ [$this->equalTo($user2)],
+ [$this->equalTo($user3)]
+ )
+ ->willReturnOnConsecutiveCalls(
+ ['group1', 'group2', 'group3'],
+ ['group1'],
+ ['group2', 'group3'],
+ ['group8', 'group9']
+ );
+
+ $this->userManager->expects($this->exactly(3))
+ ->method('get')
+ ->withConsecutive(
+ ['user1'],
+ ['user2'],
+ ['user3']
+ )
+ ->willReturn($user1, $user2, $user3);
$this->contactsManager->expects($this->once())
->method('search')
['core', 'shareapi_only_share_with_group_members', 'no', 'no'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
+ /** @var IUser|MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');
- $this->groupManager->expects($this->at(0))
+ $this->groupManager->expects($this->once())
->method('getUserGroupIds')
->with($this->equalTo($currentUser))
->willReturn(['group1', 'group2', 'group3']);
['core', 'shareapi_only_share_with_group_members', 'no', 'yes'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
+ /** @var IUser|MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');
- $this->groupManager->expects($this->at(0))
- ->method('getUserGroupIds')
- ->with($this->equalTo($currentUser))
- ->willReturn(['group1', 'group2', 'group3']);
-
$user1 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(0))
- ->method('get')
- ->with('user1')
- ->willReturn($user1);
- $this->groupManager->expects($this->at(1))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user1))
- ->willReturn(['group1']);
$user2 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(1))
- ->method('get')
- ->with('user2')
- ->willReturn($user2);
- $this->groupManager->expects($this->at(2))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user2))
- ->willReturn(['group2', 'group3']);
$user3 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(2))
- ->method('get')
- ->with('user3')
- ->willReturn($user3);
- $this->groupManager->expects($this->at(3))
+
+ $this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
- ->with($this->equalTo($user3))
- ->willReturn(['group8', 'group9']);
+ ->withConsecutive(
+ [$this->equalTo($currentUser)],
+ [$this->equalTo($user1)],
+ [$this->equalTo($user2)],
+ [$this->equalTo($user3)]
+ )
+ ->willReturnOnConsecutiveCalls(
+ ['group1', 'group2', 'group3'],
+ ['group1'],
+ ['group2', 'group3'],
+ ['group8', 'group9']
+ );
+
+ $this->userManager->expects($this->exactly(3))
+ ->method('get')
+ ->withConsecutive(
+ ['user1'],
+ ['user2'],
+ ['user3']
+ )
+ ->willReturnOnConsecutiveCalls($user1, $user2, $user3);
$this->knownUserService->method('isKnownToUser')
->willReturnMap([
['core', 'shareapi_only_share_with_group_members', 'no', 'no'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
+ /** @var IUser|MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');
- $this->groupManager->expects($this->at(0))
- ->method('getUserGroupIds')
- ->with($this->equalTo($currentUser))
- ->willReturn(['group1', 'group2', 'group3']);
-
$user1 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(0))
+
+ $this->groupManager->expects($this->exactly(2))
+ ->method('getUserGroupIds')
+ ->withConsecutive(
+ [$this->equalTo($currentUser)],
+ [$this->equalTo($user1)]
+ )
+ ->willReturnOnConsecutiveCalls(
+ ['group1', 'group2', 'group3'],
+ ['group1']
+ );
+
+ $this->userManager->expects($this->once())
->method('get')
->with('user1')
->willReturn($user1);
- $this->groupManager->expects($this->at(1))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user1))
- ->willReturn(['group1']);
$this->knownUserService->method('isKnownToUser')
->willReturnMap([
['core', 'shareapi_only_share_with_group_members', 'no', 'yes'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
+ /** @var IUser|MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');
- $this->groupManager->expects($this->at(0))
- ->method('getUserGroupIds')
- ->with($this->equalTo($currentUser))
- ->willReturn(['group1', 'group2', 'group3']);
-
$user1 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(0))
- ->method('get')
- ->with('user1')
- ->willReturn($user1);
- $this->groupManager->expects($this->at(1))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user1))
- ->willReturn(['group1']);
$user2 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(1))
- ->method('get')
- ->with('user2')
- ->willReturn($user2);
- $this->groupManager->expects($this->at(2))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user2))
- ->willReturn(['group2', 'group3']);
$user3 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(2))
- ->method('get')
- ->with('user3')
- ->willReturn($user3);
- $this->groupManager->expects($this->at(3))
+
+ $this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
- ->with($this->equalTo($user3))
- ->willReturn(['group8', 'group9']);
+ ->withConsecutive(
+ [$this->equalTo($currentUser)],
+ [$this->equalTo($user1)],
+ [$this->equalTo($user2)],
+ [$this->equalTo($user3)]
+ )
+ ->willReturnOnConsecutiveCalls(
+ ['group1', 'group2', 'group3'],
+ ['group1'],
+ ['group2', 'group3'],
+ ['group8', 'group9']
+ );
+
+ $this->userManager->expects($this->exactly(3))
+ ->method('get')
+ ->withConsecutive(
+ ['user1'],
+ ['user2'],
+ ['user3']
+ )
+ ->willReturnOnConsecutiveCalls($user1, $user2, $user3);
$this->knownUserService->method('isKnownToUser')
->willReturnMap([
['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->any())
->method('search')
['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'no'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->any())
->method('search')
}
public function testFindOneUser() {
- $this->config->expects($this->at(0))->method('getAppValue')
- ->with($this->equalTo('core'), $this->equalTo('shareapi_allow_share_dialog_user_enumeration'), $this->equalTo('yes'))
- ->willReturn('yes');
+ $this->config
+ ->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'],
+ ['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
+ ['core', 'shareapi_exclude_groups', 'no', 'yes'],
+ ['core', 'shareapi_only_share_with_group_members', 'no', 'no'],
+ ]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
->method('search')
}
public function testFindOneEMail() {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
->method('search')
}
public function testFindOneNotSupportedType() {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$entry = $this->contactsStore->findOne($user, 42, 'darren@roner.au');
}
public function testFindOneNoMatches() {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
->method('search')
use Test\TestCase;
class EntryTest extends TestCase {
-
- /** @var Entry */
- private $entry;
+ private Entry $entry;
protected function setUp(): void {
parent::setUp();
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IConfig;
use OCP\IUser;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ManagerTest extends TestCase {
- /** @var ContactsStore|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var ContactsStore|MockObject */
private $contactsStore;
- /** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IAppManager|MockObject */
private $appManager;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IConfig|MockObject */
private $config;
- /** @var ActionProviderStore|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var ActionProviderStore|MockObject */
private $actionProviderStore;
- /** @var Manager */
- private $manager;
+ private Manager $manager;
protected function setUp(): void {
parent::setUp();
$this->manager = new Manager($this->contactsStore, $this->actionProviderStore, $this->appManager, $this->config);
}
- private function generateTestEntries() {
+ private function generateTestEntries(): array {
$entries = [];
foreach (range('Z', 'A') as $char) {
$entry = $this->createMock(IEntry::class);
$entries = $this->generateTestEntries();
$provider = $this->createMock(IProvider::class);
- $this->config->expects($this->at(0))
+ $this->config->expects($this->exactly(2))
->method('getSystemValueInt')
- ->with('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)
- ->willReturn(25);
- $this->config->expects($this->at(1))
- ->method('getSystemValueInt')
- ->with('sharing.minSearchStringLength', 0)
- ->willReturn(0);
+ ->withConsecutive(
+ ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT],
+ ['sharing.minSearchStringLength', 0]
+ )
+ ->willReturnOnConsecutiveCalls(25, 0);
$this->contactsStore->expects($this->once())
->method('getContacts')
->with($user, $filter)
$entries = $this->generateTestEntries();
$provider = $this->createMock(IProvider::class);
- $this->config->expects($this->at(0))
- ->method('getSystemValueInt')
- ->with('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)
- ->willReturn(3);
- $this->config->expects($this->at(1))
+ $this->config->expects($this->exactly(2))
->method('getSystemValueInt')
- ->with('sharing.minSearchStringLength', 0)
- ->willReturn(0);
+ ->withConsecutive(
+ ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT],
+ ['sharing.minSearchStringLength', 0]
+ )
+ ->willReturnOnConsecutiveCalls(3, 0);
$this->contactsStore->expects($this->once())
->method('getContacts')
->with($user, $filter)
$user = $this->createMock(IUser::class);
$provider = $this->createMock(IProvider::class);
- $this->config->expects($this->at(0))
- ->method('getSystemValueInt')
- ->with('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)
- ->willReturn(3);
- $this->config->expects($this->at(1))
+ $this->config->expects($this->exactly(2))
->method('getSystemValueInt')
- ->with('sharing.minSearchStringLength', 0)
- ->willReturn(4);
+ ->withConsecutive(
+ ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT],
+ ['sharing.minSearchStringLength', 0]
+ )
+ ->willReturnOnConsecutiveCalls(3, 4);
$this->appManager->expects($this->once())
->method('isEnabledForUser')
->with($this->equalTo('contacts'), $user)
use OCP\Contacts\ContactsMenu\IEntry;
use OCP\Contacts\ContactsMenu\ILinkAction;
use OCP\IURLGenerator;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class EMailproviderTest extends TestCase {
- /** @var IActionFactory|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IActionFactory|MockObject */
private $actionFactory;
- /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IURLGenerator|MockObject */
private $urlGenerator;
- /** @var EMailProvider */
- private $provider;
+ private EMailProvider $provider;
protected function setUp(): void {
parent::setUp();
public function testProcessEmptyAddress() {
$entry = $this->createMock(IEntry::class);
- $action = $this->createMock(ILinkAction::class);
$iconUrl = 'https://example.com/img/actions/icon.svg';
$this->urlGenerator->expects($this->once())
->method('imagePath')