Browse Source

Merge pull request #39571 from nextcloud/bugfix/noid/move-lib-to-IEventDispatcher

Move lib/ events to IEventDispatcher where possible
pull/39595/head
Joas Schilling 2 years ago
committed by GitHub
parent
commit
6b7221756c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      apps/dav/lib/Connector/Sabre/Auth.php
  2. 10
      lib/private/App/AppManager.php
  3. 35
      lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php
  4. 15
      lib/private/Authentication/TwoFactorAuth/Manager.php
  5. 38
      lib/private/Files/Node/HookConnector.php
  6. 10
      lib/private/Preview/Generator.php
  7. 5
      lib/private/PreviewManager.php
  8. 3
      lib/private/Server.php
  9. 50
      lib/private/Share20/LegacyHooks.php
  10. 4
      lib/private/Share20/Manager.php
  11. 5
      lib/private/SystemTag/ManagerFactory.php
  12. 28
      lib/private/SystemTag/SystemTagManager.php
  13. 27
      lib/private/SystemTag/SystemTagObjectMapper.php
  14. 4
      lib/private/User/User.php
  15. 9
      lib/public/AppFramework/Http/TemplateResponse.php
  16. 11
      lib/public/Authentication/TwoFactorAuth/IProvider.php
  17. 6
      lib/public/IPreview.php
  18. 16
      tests/lib/App/AppManagerTest.php
  19. 41
      tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php
  20. 1
      tests/lib/AppTest.php
  21. 15
      tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
  22. 18
      tests/lib/Files/Node/HookConnectorTest.php
  23. 79
      tests/lib/Preview/GeneratorTest.php
  24. 6
      tests/lib/Share20/LegacyHooksTest.php
  25. 4
      tests/lib/Share20/ManagerTest.php
  26. 10
      tests/lib/SystemTag/SystemTagManagerTest.php
  27. 11
      tests/lib/SystemTag/SystemTagObjectMapperTest.php

1
apps/dav/lib/Connector/Sabre/Auth.php

@ -37,7 +37,6 @@ use Exception;
use OC\Authentication\Exceptions\PasswordLoginForbiddenException;
use OC\Authentication\TwoFactorAuth\Manager;
use OC\Security\Bruteforce\Throttler;
use OC\User\LoginException;
use OC\User\Session;
use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden;
use OCA\DAV\Connector\Sabre\Exception\TooManyRequests;

10
lib/private/App/AppManager.php

@ -59,7 +59,6 @@ use OCP\IUser;
use OCP\IUserSession;
use OCP\Settings\IManager as ISettingsManager;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class AppManager implements IAppManager {
/**
@ -79,7 +78,6 @@ class AppManager implements IAppManager {
private AppConfig $appConfig;
private IGroupManager $groupManager;
private ICacheFactory $memCacheFactory;
private EventDispatcherInterface $legacyDispatcher;
private IEventDispatcher $dispatcher;
private LoggerInterface $logger;
@ -110,7 +108,6 @@ class AppManager implements IAppManager {
AppConfig $appConfig,
IGroupManager $groupManager,
ICacheFactory $memCacheFactory,
EventDispatcherInterface $legacyDispatcher,
IEventDispatcher $dispatcher,
LoggerInterface $logger) {
$this->userSession = $userSession;
@ -118,7 +115,6 @@ class AppManager implements IAppManager {
$this->appConfig = $appConfig;
$this->groupManager = $groupManager;
$this->memCacheFactory = $memCacheFactory;
$this->legacyDispatcher = $legacyDispatcher;
$this->dispatcher = $dispatcher;
$this->logger = $logger;
}
@ -543,7 +539,7 @@ class AppManager implements IAppManager {
$this->installedAppsCache[$appId] = 'yes';
$this->appConfig->setValue($appId, 'enabled', 'yes');
$this->dispatcher->dispatchTyped(new AppEnableEvent($appId));
$this->legacyDispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent(
$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent(
ManagerEvent::EVENT_APP_ENABLE, $appId
));
$this->clearAppsCache();
@ -597,7 +593,7 @@ class AppManager implements IAppManager {
$this->installedAppsCache[$appId] = json_encode($groupIds);
$this->appConfig->setValue($appId, 'enabled', json_encode($groupIds));
$this->dispatcher->dispatchTyped(new AppEnableEvent($appId, $groupIds));
$this->legacyDispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent(
$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent(
ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups
));
$this->clearAppsCache();
@ -633,7 +629,7 @@ class AppManager implements IAppManager {
}
$this->dispatcher->dispatchTyped(new AppDisableEvent($appId));
$this->legacyDispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent(
$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent(
ManagerEvent::EVENT_APP_DISABLE, $appId
));
$this->clearAppsCache();

35
lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php

@ -32,44 +32,19 @@ use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\StandaloneTemplateResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\PublicShareController;
use OCP\EventDispatcher\GenericEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class AdditionalScriptsMiddleware extends Middleware {
/** @var EventDispatcherInterface */
private $legacyDispatcher;
/** @var IUserSession */
private $userSession;
/** @var IEventDispatcher */
private $dispatcher;
public function __construct(EventDispatcherInterface $legacyDispatcher, IUserSession $userSession, IEventDispatcher $dispatcher) {
$this->legacyDispatcher = $legacyDispatcher;
$this->userSession = $userSession;
$this->dispatcher = $dispatcher;
public function __construct(
private IUserSession $userSession,
private IEventDispatcher $dispatcher,
) {
}
public function afterController($controller, $methodName, Response $response): Response {
if ($response instanceof TemplateResponse) {
if (!$controller instanceof PublicShareController) {
/*
* The old event was not dispatched on the public share controller as there was
* OCA\Files_Sharing::loadAdditionalScripts for that. This is kept for compatibility reasons
* only for the old event as this is now also included in BeforeTemplateRenderedEvent
*/
$this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, new GenericEvent());
}
if (!($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn()) {
$this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN, new GenericEvent());
$isLoggedIn = true;
} else {
$isLoggedIn = false;
}
$isLoggedIn = !($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn();
$this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn, $response));
}

15
lib/private/Authentication/TwoFactorAuth/Manager.php

@ -46,8 +46,6 @@ use OCP\ISession;
use OCP\IUser;
use OCP\Session\Exceptions\SessionNotAvailableException;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use function array_diff;
use function array_filter;
@ -87,9 +85,6 @@ class Manager {
/** @var IEventDispatcher */
private $dispatcher;
/** @var EventDispatcherInterface */
private $legacyDispatcher;
/** @psalm-var array<string, bool> */
private $userIsTwoFactorAuthenticated = [];
@ -102,8 +97,7 @@ class Manager {
LoggerInterface $logger,
TokenProvider $tokenProvider,
ITimeFactory $timeFactory,
IEventDispatcher $eventDispatcher,
EventDispatcherInterface $legacyDispatcher) {
IEventDispatcher $eventDispatcher) {
$this->providerLoader = $providerLoader;
$this->providerRegistry = $providerRegistry;
$this->mandatoryTwoFactor = $mandatoryTwoFactor;
@ -114,7 +108,6 @@ class Manager {
$this->tokenProvider = $tokenProvider;
$this->timeFactory = $timeFactory;
$this->dispatcher = $eventDispatcher;
$this->legacyDispatcher = $legacyDispatcher;
}
/**
@ -284,9 +277,6 @@ class Manager {
$tokenId = $token->getId();
$this->config->deleteUserValue($user->getUID(), 'login_token_2fa', (string)$tokenId);
$dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]);
$this->legacyDispatcher->dispatch(IProvider::EVENT_SUCCESS, $dispatchEvent);
$this->dispatcher->dispatchTyped(new TwoFactorProviderForUserEnabled($user, $provider));
$this->dispatcher->dispatchTyped(new TwoFactorProviderChallengePassed($user, $provider));
@ -294,9 +284,6 @@ class Manager {
'provider' => $provider->getDisplayName(),
]);
} else {
$dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]);
$this->legacyDispatcher->dispatch(IProvider::EVENT_FAILED, $dispatchEvent);
$this->dispatcher->dispatchTyped(new TwoFactorProviderForUserDisabled($user, $provider));
$this->dispatcher->dispatchTyped(new TwoFactorProviderChallengeFailed($user, $provider));

38
lib/private/Files/Node/HookConnector.php

@ -46,7 +46,6 @@ use OCP\Files\Events\Node\NodeWrittenEvent;
use OCP\Files\FileInfo;
use OCP\Files\IRootFolder;
use OCP\Util;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class HookConnector {
/** @var IRootFolder */
@ -58,26 +57,15 @@ class HookConnector {
/** @var FileInfo[] */
private $deleteMetaCache = [];
/** @var EventDispatcherInterface */
private $legacyDispatcher;
/** @var IEventDispatcher */
private $dispatcher;
/**
* HookConnector constructor.
*
* @param Root $root
* @param View $view
*/
public function __construct(
IRootFolder $root,
View $view,
EventDispatcherInterface $legacyDispatcher,
IEventDispatcher $dispatcher) {
$this->root = $root;
$this->view = $view;
$this->legacyDispatcher = $legacyDispatcher;
$this->dispatcher = $dispatcher;
}
@ -106,7 +94,7 @@ class HookConnector {
public function write($arguments) {
$node = $this->getNodeForPath($arguments['path']);
$this->root->emit('\OC\Files', 'preWrite', [$node]);
$this->legacyDispatcher->dispatch('\OCP\Files::preWrite', new GenericEvent($node));
$this->dispatcher->dispatch('\OCP\Files::preWrite', new GenericEvent($node));
$event = new BeforeNodeWrittenEvent($node);
$this->dispatcher->dispatchTyped($event);
@ -115,7 +103,7 @@ class HookConnector {
public function postWrite($arguments) {
$node = $this->getNodeForPath($arguments['path']);
$this->root->emit('\OC\Files', 'postWrite', [$node]);
$this->legacyDispatcher->dispatch('\OCP\Files::postWrite', new GenericEvent($node));
$this->dispatcher->dispatch('\OCP\Files::postWrite', new GenericEvent($node));
$event = new NodeWrittenEvent($node);
$this->dispatcher->dispatchTyped($event);
@ -124,7 +112,7 @@ class HookConnector {
public function create($arguments) {
$node = $this->getNodeForPath($arguments['path']);
$this->root->emit('\OC\Files', 'preCreate', [$node]);
$this->legacyDispatcher->dispatch('\OCP\Files::preCreate', new GenericEvent($node));
$this->dispatcher->dispatch('\OCP\Files::preCreate', new GenericEvent($node));
$event = new BeforeNodeCreatedEvent($node);
$this->dispatcher->dispatchTyped($event);
@ -133,7 +121,7 @@ class HookConnector {
public function postCreate($arguments) {
$node = $this->getNodeForPath($arguments['path']);
$this->root->emit('\OC\Files', 'postCreate', [$node]);
$this->legacyDispatcher->dispatch('\OCP\Files::postCreate', new GenericEvent($node));
$this->dispatcher->dispatch('\OCP\Files::postCreate', new GenericEvent($node));
$event = new NodeCreatedEvent($node);
$this->dispatcher->dispatchTyped($event);
@ -143,7 +131,7 @@ class HookConnector {
$node = $this->getNodeForPath($arguments['path']);
$this->deleteMetaCache[$node->getPath()] = $node->getFileInfo();
$this->root->emit('\OC\Files', 'preDelete', [$node]);
$this->legacyDispatcher->dispatch('\OCP\Files::preDelete', new GenericEvent($node));
$this->dispatcher->dispatch('\OCP\Files::preDelete', new GenericEvent($node));
$event = new BeforeNodeDeletedEvent($node);
$this->dispatcher->dispatchTyped($event);
@ -153,7 +141,7 @@ class HookConnector {
$node = $this->getNodeForPath($arguments['path']);
unset($this->deleteMetaCache[$node->getPath()]);
$this->root->emit('\OC\Files', 'postDelete', [$node]);
$this->legacyDispatcher->dispatch('\OCP\Files::postDelete', new GenericEvent($node));
$this->dispatcher->dispatch('\OCP\Files::postDelete', new GenericEvent($node));
$event = new NodeDeletedEvent($node);
$this->dispatcher->dispatchTyped($event);
@ -162,7 +150,7 @@ class HookConnector {
public function touch($arguments) {
$node = $this->getNodeForPath($arguments['path']);
$this->root->emit('\OC\Files', 'preTouch', [$node]);
$this->legacyDispatcher->dispatch('\OCP\Files::preTouch', new GenericEvent($node));
$this->dispatcher->dispatch('\OCP\Files::preTouch', new GenericEvent($node));
$event = new BeforeNodeTouchedEvent($node);
$this->dispatcher->dispatchTyped($event);
@ -171,7 +159,7 @@ class HookConnector {
public function postTouch($arguments) {
$node = $this->getNodeForPath($arguments['path']);
$this->root->emit('\OC\Files', 'postTouch', [$node]);
$this->legacyDispatcher->dispatch('\OCP\Files::postTouch', new GenericEvent($node));
$this->dispatcher->dispatch('\OCP\Files::postTouch', new GenericEvent($node));
$event = new NodeTouchedEvent($node);
$this->dispatcher->dispatchTyped($event);
@ -181,7 +169,7 @@ class HookConnector {
$source = $this->getNodeForPath($arguments['oldpath']);
$target = $this->getNodeForPath($arguments['newpath']);
$this->root->emit('\OC\Files', 'preRename', [$source, $target]);
$this->legacyDispatcher->dispatch('\OCP\Files::preRename', new GenericEvent([$source, $target]));
$this->dispatcher->dispatch('\OCP\Files::preRename', new GenericEvent([$source, $target]));
$event = new BeforeNodeRenamedEvent($source, $target);
$this->dispatcher->dispatchTyped($event);
@ -191,7 +179,7 @@ class HookConnector {
$source = $this->getNodeForPath($arguments['oldpath']);
$target = $this->getNodeForPath($arguments['newpath']);
$this->root->emit('\OC\Files', 'postRename', [$source, $target]);
$this->legacyDispatcher->dispatch('\OCP\Files::postRename', new GenericEvent([$source, $target]));
$this->dispatcher->dispatch('\OCP\Files::postRename', new GenericEvent([$source, $target]));
$event = new NodeRenamedEvent($source, $target);
$this->dispatcher->dispatchTyped($event);
@ -201,7 +189,7 @@ class HookConnector {
$source = $this->getNodeForPath($arguments['oldpath']);
$target = $this->getNodeForPath($arguments['newpath']);
$this->root->emit('\OC\Files', 'preCopy', [$source, $target]);
$this->legacyDispatcher->dispatch('\OCP\Files::preCopy', new GenericEvent([$source, $target]));
$this->dispatcher->dispatch('\OCP\Files::preCopy', new GenericEvent([$source, $target]));
$event = new BeforeNodeCopiedEvent($source, $target);
$this->dispatcher->dispatchTyped($event);
@ -211,7 +199,7 @@ class HookConnector {
$source = $this->getNodeForPath($arguments['oldpath']);
$target = $this->getNodeForPath($arguments['newpath']);
$this->root->emit('\OC\Files', 'postCopy', [$source, $target]);
$this->legacyDispatcher->dispatch('\OCP\Files::postCopy', new GenericEvent([$source, $target]));
$this->dispatcher->dispatch('\OCP\Files::postCopy', new GenericEvent([$source, $target]));
$event = new NodeCopiedEvent($source, $target);
$this->dispatcher->dispatchTyped($event);
@ -220,7 +208,7 @@ class HookConnector {
public function read($arguments) {
$node = $this->getNodeForPath($arguments['path']);
$this->root->emit('\OC\Files', 'read', [$node]);
$this->legacyDispatcher->dispatch('\OCP\Files::read', new GenericEvent([$node]));
$this->dispatcher->dispatch('\OCP\Files::read', new GenericEvent([$node]));
$event = new BeforeNodeReadEvent($node);
$this->dispatcher->dispatchTyped($event);

10
lib/private/Preview/Generator.php

@ -44,8 +44,6 @@ use OCP\IStreamImage;
use OCP\Preview\BeforePreviewFetchedEvent;
use OCP\Preview\IProviderV2;
use OCP\Preview\IVersionedPreviewFile;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class Generator {
public const SEMAPHORE_ID_ALL = 0x0a11;
@ -59,8 +57,6 @@ class Generator {
private $appData;
/** @var GeneratorHelper */
private $helper;
/** @var EventDispatcherInterface */
private $legacyEventDispatcher;
/** @var IEventDispatcher */
private $eventDispatcher;
@ -69,14 +65,12 @@ class Generator {
IPreview $previewManager,
IAppData $appData,
GeneratorHelper $helper,
EventDispatcherInterface $legacyEventDispatcher,
IEventDispatcher $eventDispatcher
) {
$this->config = $config;
$this->previewManager = $previewManager;
$this->appData = $appData;
$this->helper = $helper;
$this->legacyEventDispatcher = $legacyEventDispatcher;
$this->eventDispatcher = $eventDispatcher;
}
@ -104,10 +98,6 @@ class Generator {
'mode' => $mode,
];
$this->legacyEventDispatcher->dispatch(
IPreview::EVENT,
new GenericEvent($file, $specification)
);
$this->eventDispatcher->dispatchTyped(new BeforePreviewFetchedEvent(
$file,
$width,

5
lib/private/PreviewManager.php

@ -46,7 +46,6 @@ use OCP\IConfig;
use OCP\IPreview;
use OCP\IServerContainer;
use OCP\Preview\IProviderV2;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use function array_key_exists;
class PreviewManager implements IPreview {
@ -54,7 +53,6 @@ class PreviewManager implements IPreview {
protected IRootFolder $rootFolder;
protected IAppData $appData;
protected IEventDispatcher $eventDispatcher;
protected EventDispatcherInterface $legacyEventDispatcher;
private ?Generator $generator = null;
private GeneratorHelper $helper;
protected bool $providerListDirty = false;
@ -81,7 +79,6 @@ class PreviewManager implements IPreview {
IRootFolder $rootFolder,
IAppData $appData,
IEventDispatcher $eventDispatcher,
EventDispatcherInterface $legacyEventDispatcher,
GeneratorHelper $helper,
?string $userId,
Coordinator $bootstrapCoordinator,
@ -93,7 +90,6 @@ class PreviewManager implements IPreview {
$this->rootFolder = $rootFolder;
$this->appData = $appData;
$this->eventDispatcher = $eventDispatcher;
$this->legacyEventDispatcher = $legacyEventDispatcher;
$this->helper = $helper;
$this->userId = $userId;
$this->bootstrapCoordinator = $bootstrapCoordinator;
@ -161,7 +157,6 @@ class PreviewManager implements IPreview {
$this->rootFolder,
$this->config
),
$this->legacyEventDispatcher,
$this->eventDispatcher
);
}

3
lib/private/Server.php

@ -340,7 +340,6 @@ class Server extends ServerContainer implements IServerContainer {
$c->get(SystemConfig::class)
),
$c->get(IEventDispatcher::class),
$c->get(SymfonyAdapter::class),
$c->get(GeneratorHelper::class),
$c->get(ISession::class)->get('user_id'),
$c->get(Coordinator::class),
@ -466,7 +465,6 @@ class Server extends ServerContainer implements IServerContainer {
return new HookConnector(
$c->get(IRootFolder::class),
new View(),
$c->get(\OC\EventDispatcher\SymfonyAdapter::class),
$c->get(IEventDispatcher::class)
);
});
@ -940,7 +938,6 @@ class Server extends ServerContainer implements IServerContainer {
$c->get(\OC\AppConfig::class),
$c->get(IGroupManager::class),
$c->get(ICacheFactory::class),
$c->get(SymfonyAdapter::class),
$c->get(IEventDispatcher::class),
$c->get(LoggerInterface::class)
);

50
lib/private/Share20/LegacyHooks.php

@ -26,34 +26,46 @@
*/
namespace OC\Share20;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
use OCP\Share;
use OCP\Share\IShare;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class LegacyHooks {
/** @var EventDispatcherInterface */
/** @var IEventDispatcher */
private $eventDispatcher;
/**
* LegacyHooks constructor.
*
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(EventDispatcherInterface $eventDispatcher) {
public function __construct(IEventDispatcher $eventDispatcher) {
$this->eventDispatcher = $eventDispatcher;
$this->eventDispatcher->addListener('OCP\Share::preUnshare', [$this, 'preUnshare']);
$this->eventDispatcher->addListener('OCP\Share::postUnshare', [$this, 'postUnshare']);
$this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', [$this, 'postUnshareFromSelf']);
$this->eventDispatcher->addListener('OCP\Share::preShare', [$this, 'preShare']);
$this->eventDispatcher->addListener('OCP\Share::postShare', [$this, 'postShare']);
$this->eventDispatcher->addListener('OCP\Share::preUnshare', function ($event) {
if ($event instanceof GenericEvent) {
$this->preUnshare($event);
}
});
$this->eventDispatcher->addListener('OCP\Share::postUnshare', function ($event) {
if ($event instanceof GenericEvent) {
$this->postUnshare($event);
}
});
$this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', function ($event) {
if ($event instanceof GenericEvent) {
$this->postUnshareFromSelf($event);
}
});
$this->eventDispatcher->addListener('OCP\Share::preShare', function ($event) {
if ($event instanceof GenericEvent) {
$this->preShare($event);
}
});
$this->eventDispatcher->addListener('OCP\Share::postShare', function ($event) {
if ($event instanceof GenericEvent) {
$this->postShare($event);
}
});
}
/**
* @param GenericEvent $e
*/
public function preUnshare(GenericEvent $e) {
/** @var IShare $share */
$share = $e->getSubject();
@ -62,9 +74,6 @@ class LegacyHooks {
\OC_Hook::emit(Share::class, 'pre_unshare', $formatted);
}
/**
* @param GenericEvent $e
*/
public function postUnshare(GenericEvent $e) {
/** @var IShare $share */
$share = $e->getSubject();
@ -83,9 +92,6 @@ class LegacyHooks {
\OC_Hook::emit(Share::class, 'post_unshare', $formatted);
}
/**
* @param GenericEvent $e
*/
public function postUnshareFromSelf(GenericEvent $e) {
/** @var IShare $share */
$share = $e->getSubject();

4
lib/private/Share20/Manager.php

@ -157,7 +157,7 @@ class Manager implements IManager {
$this->sharingDisabledForUsersCache = new CappedMemoryCache();
// The constructor of LegacyHooks registers the listeners of share events
// do not remove if those are not properly migrated
$this->legacyHooks = new LegacyHooks($this->legacyDispatcher);
$this->legacyHooks = new LegacyHooks($dispatcher);
$this->mailer = $mailer;
$this->urlGenerator = $urlGenerator;
$this->defaults = $defaults;
@ -194,7 +194,7 @@ class Manager implements IManager {
// Let others verify the password
try {
$this->legacyDispatcher->dispatch(new ValidatePasswordPolicyEvent($password));
$this->dispatcher->dispatchTyped(new ValidatePasswordPolicyEvent($password));
} catch (HintException $e) {
throw new \Exception($e->getHint());
}

5
lib/private/SystemTag/ManagerFactory.php

@ -26,6 +26,7 @@ declare(strict_types=1);
*/
namespace OC\SystemTag;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IServerContainer;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagManagerFactory;
@ -64,7 +65,7 @@ class ManagerFactory implements ISystemTagManagerFactory {
return new SystemTagManager(
$this->serverContainer->getDatabaseConnection(),
$this->serverContainer->getGroupManager(),
$this->serverContainer->getEventDispatcher()
$this->serverContainer->get(IEventDispatcher::class),
);
}
@ -79,7 +80,7 @@ class ManagerFactory implements ISystemTagManagerFactory {
return new SystemTagObjectMapper(
$this->serverContainer->getDatabaseConnection(),
$this->getManager(),
$this->serverContainer->getEventDispatcher()
$this->serverContainer->get(IEventDispatcher::class),
);
}
}

28
lib/private/SystemTag/SystemTagManager.php

@ -31,6 +31,7 @@ namespace OC\SystemTag;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IUser;
@ -39,7 +40,6 @@ use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ManagerEvent;
use OCP\SystemTag\TagAlreadyExistsException;
use OCP\SystemTag\TagNotFoundException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Manager class for system tags
@ -48,15 +48,6 @@ class SystemTagManager implements ISystemTagManager {
public const TAG_TABLE = 'systemtag';
public const TAG_GROUP_TABLE = 'systemtag_group';
/** @var IDBConnection */
protected $connection;
/** @var EventDispatcherInterface */
protected $dispatcher;
/** @var IGroupManager */
protected $groupManager;
/**
* Prepared query for selecting tags directly
*
@ -64,22 +55,11 @@ class SystemTagManager implements ISystemTagManager {
*/
private $selectTagQuery;
/**
* Constructor.
*
* @param IDBConnection $connection database connection
* @param IGroupManager $groupManager
* @param EventDispatcherInterface $dispatcher
*/
public function __construct(
IDBConnection $connection,
IGroupManager $groupManager,
EventDispatcherInterface $dispatcher
protected IDBConnection $connection,
protected IGroupManager $groupManager,
protected IEventDispatcher $dispatcher,
) {
$this->connection = $connection;
$this->groupManager = $groupManager;
$this->dispatcher = $dispatcher;
$query = $this->connection->getQueryBuilder();
$this->selectTagQuery = $query->select('*')
->from(self::TAG_TABLE)

27
lib/private/SystemTag/SystemTagObjectMapper.php

@ -29,37 +29,22 @@ namespace OC\SystemTag;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
use OCP\SystemTag\ISystemTag;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagObjectMapper;
use OCP\SystemTag\MapperEvent;
use OCP\SystemTag\TagNotFoundException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class SystemTagObjectMapper implements ISystemTagObjectMapper {
public const RELATION_TABLE = 'systemtag_object_mapping';
/** @var ISystemTagManager */
protected $tagManager;
/** @var IDBConnection */
protected $connection;
/** @var EventDispatcherInterface */
protected $dispatcher;
/**
* Constructor.
*
* @param IDBConnection $connection database connection
* @param ISystemTagManager $tagManager system tag manager
* @param EventDispatcherInterface $dispatcher
*/
public function __construct(IDBConnection $connection, ISystemTagManager $tagManager, EventDispatcherInterface $dispatcher) {
$this->connection = $connection;
$this->tagManager = $tagManager;
$this->dispatcher = $dispatcher;
public function __construct(
protected IDBConnection $connection,
protected ISystemTagManager $tagManager,
protected IEventDispatcher $dispatcher,
) {
}
/**

4
lib/private/User/User.php

@ -271,8 +271,6 @@ class User implements IUser {
* @return bool
*/
public function delete() {
/** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
$this->legacyDispatcher->dispatch(IUser::class . '::preDelete', new GenericEvent($this));
if ($this->emitter) {
/** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
$this->emitter->emit('\OC\User', 'preDelete', [$this]);
@ -310,8 +308,6 @@ class User implements IUser {
$accountManager = \OCP\Server::get(AccountManager::class);
$accountManager->deleteUser($this);
/** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
$this->legacyDispatcher->dispatch(IUser::class . '::postDelete', new GenericEvent($this));
if ($this->emitter) {
/** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
$this->emitter->emit('\OC\User', 'postDelete', [$this]);

9
lib/public/AppFramework/Http/TemplateResponse.php

@ -65,15 +65,6 @@ class TemplateResponse extends Response {
*/
public const RENDER_AS_PUBLIC = 'public';
/**
* @deprecated 20.0.0 use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent
*/
public const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts';
/**
* @deprecated 20.0.0 use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent
*/
public const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class . '::loadAdditionalScriptsLoggedIn';
/**
* name of the template
* @var string

11
lib/public/Authentication/TwoFactorAuth/IProvider.php

@ -32,17 +32,6 @@ use OCP\Template;
* @since 9.1.0
*/
interface IProvider {
/**
* @since 14.0.0
* @deprecated 22.0.0
*/
public const EVENT_SUCCESS = self::class . '::success';
/**
* @deprecated 22.0.0
*/
public const EVENT_FAILED = self::class . '::failed';
/**
* Get unique identifier of this 2FA provider
*

6
lib/public/IPreview.php

@ -38,12 +38,6 @@ use OCP\Files\SimpleFS\ISimpleFile;
* @since 6.0.0
*/
interface IPreview {
/**
* @since 9.2.0
* @deprecated 22.0.0
*/
public const EVENT = self::class . ':' . 'PreviewRequested';
public const MODE_FILL = 'fill';
public const MODE_COVER = 'cover';

16
tests/lib/App/AppManagerTest.php

@ -27,7 +27,6 @@ use OCP\IUser;
use OCP\IUserSession;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
/**
@ -93,9 +92,6 @@ class AppManagerTest extends TestCase {
/** @var ICacheFactory|MockObject */
protected $cacheFactory;
/** @var EventDispatcherInterface|MockObject */
protected $legacyEventDispatcher;
/** @var IEventDispatcher|MockObject */
protected $eventDispatcher;
@ -114,7 +110,6 @@ class AppManagerTest extends TestCase {
$this->appConfig = $this->getAppConfig();
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->cache = $this->createMock(ICache::class);
$this->legacyEventDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->cacheFactory->expects($this->any())
@ -127,7 +122,6 @@ class AppManagerTest extends TestCase {
$this->appConfig,
$this->groupManager,
$this->cacheFactory,
$this->legacyEventDispatcher,
$this->eventDispatcher,
$this->logger
);
@ -176,7 +170,7 @@ class AppManagerTest extends TestCase {
/** @var AppManager|MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class)
->setConstructorArgs([
$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger
$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger
])
->setMethods([
'getAppPath',
@ -224,7 +218,7 @@ class AppManagerTest extends TestCase {
/** @var AppManager|MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class)
->setConstructorArgs([
$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger
$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger
])
->setMethods([
'getAppPath',
@ -280,7 +274,7 @@ class AppManagerTest extends TestCase {
/** @var AppManager|MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class)
->setConstructorArgs([
$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger
$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger
])
->setMethods([
'getAppPath',
@ -476,7 +470,7 @@ class AppManagerTest extends TestCase {
public function testGetAppsNeedingUpgrade() {
/** @var AppManager|MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class)
->setConstructorArgs([$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger])
->setConstructorArgs([$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger])
->setMethods(['getAppInfo'])
->getMock();
@ -527,7 +521,7 @@ class AppManagerTest extends TestCase {
public function testGetIncompatibleApps() {
/** @var AppManager|MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class)
->setConstructorArgs([$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger])
->setConstructorArgs([$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger])
->setMethods(['getAppInfo'])
->getMock();

41
tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php

@ -35,11 +35,8 @@ use OCP\AppFramework\PublicShareController;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUserSession;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
/** @var EventDispatcherInterface|MockObject */
private $legacyDispatcher;
/** @var IUserSession|MockObject */
private $userSession;
@ -54,11 +51,9 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
$this->legacyDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->middleWare = new AdditionalScriptsMiddleware(
$this->legacyDispatcher,
$this->userSession,
$this->dispatcher
);
@ -67,8 +62,6 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
}
public function testNoTemplateResponse() {
$this->legacyDispatcher->expects($this->never())
->method($this->anything());
$this->userSession->expects($this->never())
->method($this->anything());
$this->dispatcher->expects($this->never())
@ -78,8 +71,6 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
}
public function testPublicShareController() {
$this->legacyDispatcher->expects($this->never())
->method($this->anything());
$this->userSession->expects($this->never())
->method($this->anything());
$this->dispatcher->expects($this->never())
@ -89,15 +80,6 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
}
public function testStandaloneTemplateResponse() {
$this->legacyDispatcher->expects($this->once())
->method('dispatch')
->willReturnCallback(function ($eventName) {
if ($eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS) {
return;
}
$this->fail('Wrong event dispatched');
});
$this->userSession->expects($this->never())
->method($this->anything());
$this->dispatcher->expects($this->once())
@ -114,15 +96,6 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
}
public function testTemplateResponseNotLoggedIn() {
$this->legacyDispatcher->expects($this->once())
->method('dispatch')
->willReturnCallback(function ($eventName) {
if ($eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS) {
return;
}
$this->fail('Wrong event dispatched');
});
$this->userSession->method('isLoggedIn')
->willReturn(false);
$this->dispatcher->expects($this->once())
@ -141,17 +114,6 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
public function testTemplateResponseLoggedIn() {
$events = [];
$this->legacyDispatcher->expects($this->exactly(2))
->method('dispatch')
->willReturnCallback(function ($eventName) use (&$events) {
if ($eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS ||
$eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN) {
$events[] = $eventName;
return;
}
$this->fail('Wrong event dispatched');
});
$this->userSession->method('isLoggedIn')
->willReturn(true);
$this->dispatcher->expects($this->once())
@ -165,8 +127,5 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
});
$this->middleWare->afterController($this->controller, 'myMethod', $this->createMock(TemplateResponse::class));
$this->assertContains(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, $events);
$this->assertContains(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN, $events);
}
}

1
tests/lib/AppTest.php

@ -560,7 +560,6 @@ class AppTest extends \Test\TestCase {
$appConfig,
\OC::$server->getGroupManager(),
\OC::$server->getMemCacheFactory(),
\OC::$server->getEventDispatcher(),
\OC::$server->get(IEventDispatcher::class),
\OC::$server->get(LoggerInterface::class)
));

15
tests/lib/Authentication/TwoFactorAuth/ManagerTest.php

@ -40,7 +40,6 @@ use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use function reset;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
class ManagerTest extends TestCase {
@ -84,10 +83,7 @@ class ManagerTest extends TestCase {
private $timeFactory;
/** @var IEventDispatcher|MockObject */
private $newDispatcher;
/** @var EventDispatcherInterface|MockObject */
private $eventDispatcher;
private $dispatcher;
protected function setUp(): void {
parent::setUp();
@ -102,8 +98,7 @@ class ManagerTest extends TestCase {
$this->logger = $this->createMock(LoggerInterface::class);
$this->tokenProvider = $this->createMock(TokenProvider::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->newDispatcher = $this->createMock(IEventDispatcher::class);
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->manager = new Manager(
$this->providerLoader,
@ -115,8 +110,7 @@ class ManagerTest extends TestCase {
$this->logger,
$this->tokenProvider,
$this->timeFactory,
$this->newDispatcher,
$this->eventDispatcher
$this->dispatcher,
);
$this->fakeProvider = $this->createMock(IProvider::class);
@ -530,8 +524,7 @@ class ManagerTest extends TestCase {
$this->logger,
$this->tokenProvider,
$this->timeFactory,
$this->newDispatcher,
$this->eventDispatcher
$this->dispatcher,
])
->setMethods(['loadTwoFactorApp', 'isTwoFactorAuthenticated'])// Do not actually load the apps
->getMock();

18
tests/lib/Files/Node/HookConnectorTest.php

@ -31,9 +31,7 @@ use OCP\Files\Events\Node\NodeTouchedEvent;
use OCP\Files\Events\Node\NodeWrittenEvent;
use OCP\Files\Node;
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;
use Test\Traits\MountProviderTrait;
@ -50,9 +48,6 @@ class HookConnectorTest extends TestCase {
use UserTrait;
use MountProviderTrait;
/** @var EventDispatcherInterface|MockObject */
protected $legacyDispatcher;
/** @var IEventDispatcher */
protected $eventDispatcher;
@ -82,7 +77,6 @@ class HookConnectorTest extends TestCase {
$this->createMock(IUserManager::class),
$this->createMock(IEventDispatcher::class)
);
$this->legacyDispatcher = \OC::$server->getEventDispatcher();
$this->eventDispatcher = \OC::$server->query(IEventDispatcher::class);
}
@ -149,7 +143,7 @@ class HookConnectorTest extends TestCase {
* @dataProvider viewToNodeProvider
*/
public function testViewToNode(callable $operation, $expectedHook, $expectedLegacyEvent, $expectedEvent) {
$connector = new HookConnector($this->root, $this->view, $this->legacyDispatcher, $this->eventDispatcher);
$connector = new HookConnector($this->root, $this->view, $this->eventDispatcher);
$connector->viewToNode();
$hookCalled = false;
/** @var Node $hookNode */
@ -163,7 +157,7 @@ class HookConnectorTest extends TestCase {
$dispatcherCalled = false;
/** @var Node $dispatcherNode */
$dispatcherNode = null;
$this->legacyDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherCalled, &$dispatcherNode) {
$this->eventDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherCalled, &$dispatcherNode) {
/** @var GenericEvent|APIGenericEvent $event */
$dispatcherCalled = true;
$dispatcherNode = $event->getSubject();
@ -218,7 +212,7 @@ class HookConnectorTest extends TestCase {
* @dataProvider viewToNodeProviderCopyRename
*/
public function testViewToNodeCopyRename(callable $operation, $expectedHook, $expectedLegacyEvent, $expectedEvent) {
$connector = new HookConnector($this->root, $this->view, $this->legacyDispatcher, $this->eventDispatcher);
$connector = new HookConnector($this->root, $this->view, $this->eventDispatcher);
$connector->viewToNode();
$hookCalled = false;
/** @var Node $hookSourceNode */
@ -237,7 +231,7 @@ class HookConnectorTest extends TestCase {
$dispatcherSourceNode = null;
/** @var Node $dispatcherTargetNode */
$dispatcherTargetNode = null;
$this->legacyDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherSourceNode, &$dispatcherTargetNode, &$dispatcherCalled) {
$this->eventDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherSourceNode, &$dispatcherTargetNode, &$dispatcherCalled) {
/** @var GenericEvent|APIGenericEvent $event */
$dispatcherCalled = true;
[$dispatcherSourceNode, $dispatcherTargetNode] = $event->getSubject();
@ -273,7 +267,7 @@ class HookConnectorTest extends TestCase {
}
public function testPostDeleteMeta() {
$connector = new HookConnector($this->root, $this->view, $this->legacyDispatcher, $this->eventDispatcher);
$connector = new HookConnector($this->root, $this->view, $this->eventDispatcher);
$connector->viewToNode();
$hookCalled = false;
/** @var Node $hookNode */
@ -287,7 +281,7 @@ class HookConnectorTest extends TestCase {
$dispatcherCalled = false;
/** @var Node $dispatcherNode */
$dispatcherNode = null;
$this->legacyDispatcher->addListener('\OCP\Files::postDelete', function ($event) use (&$dispatcherCalled, &$dispatcherNode) {
$this->eventDispatcher->addListener('\OCP\Files::postDelete', function ($event) use (&$dispatcherCalled, &$dispatcherNode) {
/** @var GenericEvent|APIGenericEvent $event */
$dispatcherCalled = true;
$dispatcherNode = $event->getSubject();

79
tests/lib/Preview/GeneratorTest.php

@ -35,8 +35,6 @@ use OCP\IConfig;
use OCP\IPreview;
use OCP\Preview\BeforePreviewFetchedEvent;
use OCP\Preview\IProviderV2;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class GeneratorTest extends \Test\TestCase {
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
@ -54,9 +52,6 @@ class GeneratorTest extends \Test\TestCase {
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
private $eventDispatcher;
/** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */
private $legacyEventDispatcher;
/** @var Generator */
private $generator;
@ -68,14 +63,12 @@ class GeneratorTest extends \Test\TestCase {
$this->appData = $this->createMock(IAppData::class);
$this->helper = $this->createMock(GeneratorHelper::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->legacyEventDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->generator = new Generator(
$this->config,
$this->previewManager,
$this->appData,
$this->helper,
$this->legacyEventDispatcher,
$this->eventDispatcher
);
}
@ -112,17 +105,6 @@ class GeneratorTest extends \Test\TestCase {
$previewFolder->method('getDirectoryListing')
->willReturn([$maxPreview, $previewFile]);
$this->legacyEventDispatcher->expects($this->once())
->method('dispatch')
->with(
$this->equalTo(IPreview::EVENT),
$this->callback(function (GenericEvent $event) use ($file) {
return $event->getSubject() === $file &&
$event->getArgument('width') === 100 &&
$event->getArgument('height') === 100;
})
);
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped')
->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL));
@ -251,17 +233,6 @@ class GeneratorTest extends \Test\TestCase {
->method('putContent')
->with('my resized data');
$this->legacyEventDispatcher->expects($this->once())
->method('dispatch')
->with(
$this->equalTo(IPreview::EVENT),
$this->callback(function (GenericEvent $event) use ($file) {
return $event->getSubject() === $file &&
$event->getArgument('width') === 100 &&
$event->getArgument('height') === 100;
})
);
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped')
->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL));
@ -301,19 +272,6 @@ class GeneratorTest extends \Test\TestCase {
->with($this->equalTo('1024-512-crop.png'))
->willThrowException(new NotFoundException());
$this->legacyEventDispatcher->expects($this->once())
->method('dispatch')
->with(
$this->equalTo(IPreview::EVENT),
$this->callback(function (GenericEvent $event) use ($file) {
return $event->getSubject() === $file &&
$event->getArgument('width') === 1024 &&
$event->getArgument('height') === 512 &&
$event->getArgument('crop') === true &&
$event->getArgument('mode') === IPreview::MODE_COVER;
})
);
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped')
->with(new BeforePreviewFetchedEvent($file, 1024, 512, true, IPreview::MODE_COVER));
@ -351,19 +309,6 @@ class GeneratorTest extends \Test\TestCase {
$this->previewManager->expects($this->never())
->method('isMimeSupported');
$this->legacyEventDispatcher->expects($this->once())
->method('dispatch')
->with(
$this->equalTo(IPreview::EVENT),
$this->callback(function (GenericEvent $event) use ($file) {
return $event->getSubject() === $file &&
$event->getArgument('width') === 1024 &&
$event->getArgument('height') === 512 &&
$event->getArgument('crop') === true &&
$event->getArgument('mode') === IPreview::MODE_COVER;
})
);
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped')
->with(new BeforePreviewFetchedEvent($file, 1024, 512, true, IPreview::MODE_COVER));
@ -392,17 +337,6 @@ class GeneratorTest extends \Test\TestCase {
$this->previewManager->method('getProviders')
->willReturn([]);
$this->legacyEventDispatcher->expects($this->once())
->method('dispatch')
->with(
$this->equalTo(IPreview::EVENT),
$this->callback(function (GenericEvent $event) use ($file) {
return $event->getSubject() === $file &&
$event->getArgument('width') === 100 &&
$event->getArgument('height') === 100;
})
);
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped')
->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL));
@ -528,19 +462,6 @@ class GeneratorTest extends \Test\TestCase {
->with($this->equalTo($filename))
->willReturn($preview);
$this->legacyEventDispatcher->expects($this->once())
->method('dispatch')
->with(
$this->equalTo(IPreview::EVENT),
$this->callback(function (GenericEvent $event) use ($file, $reqX, $reqY, $crop, $mode) {
return $event->getSubject() === $file &&
$event->getArgument('width') === $reqX &&
$event->getArgument('height') === $reqY &&
$event->getArgument('crop') === $crop &&
$event->getArgument('mode') === $mode;
})
);
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped')
->with(new BeforePreviewFetchedEvent($file, $reqX, $reqY, $crop, $mode));

6
tests/lib/Share20/LegacyHooksTest.php

@ -27,12 +27,12 @@ use OC\EventDispatcher\SymfonyAdapter;
use OC\Share20\LegacyHooks;
use OC\Share20\Manager;
use OCP\Constants;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\File;
use OCP\IServerContainer;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent;
use Test\TestCase;
@ -40,7 +40,7 @@ class LegacyHooksTest extends TestCase {
/** @var LegacyHooks */
private $hooks;
/** @var EventDispatcher */
/** @var IEventDispatcher */
private $eventDispatcher;
/** @var Manager */
@ -53,7 +53,7 @@ class LegacyHooksTest extends TestCase {
$logger = $this->createMock(LoggerInterface::class);
$eventDispatcher = new \OC\EventDispatcher\EventDispatcher($symfonyDispatcher, \OC::$server->get(IServerContainer::class), $logger);
$this->eventDispatcher = new SymfonyAdapter($eventDispatcher, $logger);
$this->hooks = new LegacyHooks($this->eventDispatcher);
$this->hooks = new LegacyHooks($eventDispatcher);
$this->manager = \OC::$server->getShareManager();
}

4
tests/lib/Share20/ManagerTest.php

@ -545,7 +545,7 @@ class ManagerTest extends \Test\TestCase {
['core', 'shareapi_enforce_links_password', 'no', 'no'],
]);
$this->eventDispatcher->expects($this->once())->method('dispatch')
$this->dispatcher->expects($this->once())->method('dispatchTyped')
->willReturnCallback(function (Event $event) {
$this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event);
/** @var ValidatePasswordPolicyEvent $event */
@ -567,7 +567,7 @@ class ManagerTest extends \Test\TestCase {
['core', 'shareapi_enforce_links_password', 'no', 'no'],
]);
$this->eventDispatcher->expects($this->once())->method('dispatch')
$this->dispatcher->expects($this->once())->method('dispatchTyped')
->willReturnCallback(function (Event $event) {
$this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event);
/** @var ValidatePasswordPolicyEvent $event */

10
tests/lib/SystemTag/SystemTagManagerTest.php

@ -12,12 +12,12 @@ namespace Test\SystemTag;
use OC\SystemTag\SystemTagManager;
use OC\SystemTag\SystemTagObjectMapper;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\SystemTag\ISystemTag;
use OCP\SystemTag\ISystemTagManager;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
/**
@ -43,7 +43,7 @@ class SystemTagManagerTest extends TestCase {
private $groupManager;
/**
* @var EventDispatcherInterface
* @var IEventDispatcher
*/
private $dispatcher;
@ -52,10 +52,8 @@ class SystemTagManagerTest extends TestCase {
$this->connection = \OC::$server->getDatabaseConnection();
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')
->getMock();
$this->groupManager = $this->getMockBuilder(IGroupManager::class)->getMock();
$this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->tagManager = new SystemTagManager(
$this->connection,

11
tests/lib/SystemTag/SystemTagObjectMapperTest.php

@ -13,12 +13,12 @@ namespace Test\SystemTag;
use OC\SystemTag\SystemTag;
use OC\SystemTag\SystemTagManager;
use OC\SystemTag\SystemTagObjectMapper;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
use OCP\SystemTag\ISystemTag;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagObjectMapper;
use OCP\SystemTag\TagNotFoundException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
/**
@ -44,7 +44,7 @@ class SystemTagObjectMapperTest extends TestCase {
private $connection;
/**
* @var EventDispatcherInterface
* @var IEventDispatcher
*/
private $dispatcher;
@ -69,11 +69,8 @@ class SystemTagObjectMapperTest extends TestCase {
$this->connection = \OC::$server->getDatabaseConnection();
$this->pruneTagsTables();
$this->tagManager = $this->getMockBuilder('OCP\SystemTag\ISystemTagManager')
->getMock();
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')
->getMock();
$this->tagManager = $this->createMock(ISystemTagManager::class);
$this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->tagMapper = new SystemTagObjectMapper(
$this->connection,

Loading…
Cancel
Save