diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php index 15b47385d4554..21696a79d7da0 100644 --- a/apps/files_trashbin/tests/StorageTest.php +++ b/apps/files_trashbin/tests/StorageTest.php @@ -31,6 +31,7 @@ */ namespace OCA\Files_Trashbin\Tests; +use OC\EventDispatcher\SymfonyAdapter; use OC\Files\Filesystem; use OC\Files\Storage\Common; use OC\Files\Storage\Local; @@ -607,7 +608,7 @@ public function testShouldMoveToTrash($mountPoint, $path, $userExists, $appDisab $userManager->expects($this->any()) ->method('userExists')->willReturn($userExists); $logger = $this->getMockBuilder(ILogger::class)->getMock(); - $eventDispatcher = $this->createMock(EventDispatcherInterface::class); + $eventDispatcher = $this->createMock(SymfonyAdapter::class); $rootFolder = $this->createMock(IRootFolder::class); $userFolder = $this->createMock(Folder::class); $node = $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock(); diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php index 2b074d24c3913..12028ee47f553 100644 --- a/apps/settings/tests/Controller/CheckSetupControllerTest.php +++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php @@ -38,6 +38,7 @@ use Doctrine\DBAL\Platforms\SqlitePlatform; use OC; use OC\DB\Connection; +use OC\EventDispatcher\SymfonyAdapter; use OC\IntegrityCheck\Checker; use OC\MemoryInfo; use OC\Security\SecureRandom; @@ -137,7 +138,7 @@ protected function setUp(): void { ->willReturnCallback(function ($message, array $replace) { return vsprintf($message, $replace); }); - $this->dispatcher = $this->getMockBuilder(EventDispatcherInterface::class) + $this->dispatcher = $this->getMockBuilder(SymfonyAdapter::class) ->disableOriginalConstructor()->getMock(); $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker') ->disableOriginalConstructor()->getMock(); diff --git a/apps/workflowengine/tests/ManagerTest.php b/apps/workflowengine/tests/ManagerTest.php index 543b4550ca6aa..402e24c1a0f4d 100644 --- a/apps/workflowengine/tests/ManagerTest.php +++ b/apps/workflowengine/tests/ManagerTest.php @@ -26,6 +26,7 @@ */ namespace OCA\WorkflowEngine\Tests; +use OC\EventDispatcher\SymfonyAdapter; use OC\L10N\L10N; use OCA\WorkflowEngine\Entity\File; use OCA\WorkflowEngine\Helper\ScopeContext; @@ -94,7 +95,7 @@ protected function setUp(): void { return vsprintf($text, $parameters); }); - $this->legacyDispatcher = $this->createMock(EventDispatcherInterface::class); + $this->legacyDispatcher = $this->createMock(SymfonyAdapter::class); $this->logger = $this->createMock(ILogger::class); $this->session = $this->createMock(IUserSession::class); $this->dispatcher = $this->createMock(IEventDispatcher::class); @@ -535,8 +536,9 @@ public function testGetEntitiesList() { $this->legacyDispatcher->expects($this->once()) ->method('dispatch') ->with('OCP\WorkflowEngine::registerEntities', $this->anything()) - ->willReturnCallback(function () use ($extraEntity) { + ->willReturnCallback(function ($eventName, $event) use ($extraEntity) { $this->manager->registerEntity($extraEntity); + return $event; }); $entities = $this->manager->getEntitiesList(); diff --git a/lib/private/EventDispatcher/SymfonyAdapter.php b/lib/private/EventDispatcher/SymfonyAdapter.php index 7354d58d4e0bf..2831e7682c971 100644 --- a/lib/private/EventDispatcher/SymfonyAdapter.php +++ b/lib/private/EventDispatcher/SymfonyAdapter.php @@ -113,7 +113,7 @@ public function dispatch($eventName, $event = null): object { // Event with no payload (object) need special handling if ($newEvent === null) { - $this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName); + $this->eventDispatcher->getSymfonyDispatcher()->dispatch(new GenericEvent(), $eventName); return new Event(); } diff --git a/tests/lib/Accounts/AccountManagerTest.php b/tests/lib/Accounts/AccountManagerTest.php index 3a3405f18a09f..785111a10bfde 100644 --- a/tests/lib/Accounts/AccountManagerTest.php +++ b/tests/lib/Accounts/AccountManagerTest.php @@ -26,6 +26,7 @@ use OC\Accounts\Account; use OC\Accounts\AccountManager; +use OC\EventDispatcher\SymfonyAdapter; use OCA\Settings\BackgroundJobs\VerifyUserData; use OCP\Accounts\IAccountManager; use OCP\BackgroundJob\IJobList; @@ -86,7 +87,7 @@ class AccountManagerTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); + $this->eventDispatcher = $this->createMock(SymfonyAdapter::class); $this->connection = \OC::$server->get(IDBConnection::class); $this->config = $this->createMock(IConfig::class); $this->jobList = $this->createMock(IJobList::class); @@ -511,11 +512,12 @@ function ($eventName, $event) use ($user, $newData) { $this->assertInstanceOf(GenericEvent::class, $event); $this->assertSame($user, $event->getSubject()); $this->assertSame($newData, $event->getArguments()); + return $event; } ); } - $this->invokePrivate($accountManager, 'updateUser', [$user, $newData, $oldData]); + self::invokePrivate($accountManager, 'updateUser', [$user, $newData, $oldData]); } public function dataTrueFalse(): array { diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php index 3518ada331436..15b53caf76ce3 100644 --- a/tests/lib/App/AppManagerTest.php +++ b/tests/lib/App/AppManagerTest.php @@ -13,6 +13,7 @@ use OC\App\AppManager; use OC\AppConfig; +use OC\EventDispatcher\SymfonyAdapter; use OCP\App\AppPathNotFoundException; use OCP\App\Events\AppDisableEvent; use OCP\App\Events\AppEnableEvent; @@ -114,7 +115,7 @@ protected function setUp(): void { $this->appConfig = $this->getAppConfig(); $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->cache = $this->createMock(ICache::class); - $this->legacyEventDispatcher = $this->createMock(EventDispatcherInterface::class); + $this->legacyEventDispatcher = $this->createMock(SymfonyAdapter::class); $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $this->logger = $this->createMock(LoggerInterface::class); $this->cacheFactory->expects($this->any()) diff --git a/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php b/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php index 1cd6b614aade7..69bf56ff0af16 100644 --- a/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php @@ -26,12 +26,14 @@ namespace Test\AppFramework\Middleware; use OC\AppFramework\Middleware\AdditionalScriptsMiddleware; +use OC\EventDispatcher\SymfonyAdapter; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\StandaloneTemplateResponse; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\PublicShareController; +use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventDispatcher; use OCP\IUserSession; use PHPUnit\Framework\MockObject\MockObject; @@ -54,7 +56,7 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->legacyDispatcher = $this->createMock(EventDispatcherInterface::class); + $this->legacyDispatcher = $this->createMock(SymfonyAdapter::class); $this->userSession = $this->createMock(IUserSession::class); $this->dispatcher = $this->createMock(IEventDispatcher::class); $this->middleWare = new AdditionalScriptsMiddleware( @@ -93,7 +95,7 @@ public function testStandaloneTemplateResponse() { ->method('dispatch') ->willReturnCallback(function ($eventName) { if ($eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS) { - return; + return new Event(); } $this->fail('Wrong event dispatched'); @@ -118,7 +120,7 @@ public function testTemplateResponseNotLoggedIn() { ->method('dispatch') ->willReturnCallback(function ($eventName) { if ($eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS) { - return; + return new Event(); } $this->fail('Wrong event dispatched'); @@ -147,7 +149,7 @@ public function testTemplateResponseLoggedIn() { if ($eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS || $eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN) { $events[] = $eventName; - return; + return new Event(); } $this->fail('Wrong event dispatched'); diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php index da11b11e53780..7a4a82fc87b4b 100644 --- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php @@ -27,6 +27,7 @@ use OC\Authentication\TwoFactorAuth\Manager; use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor; use OC\Authentication\TwoFactorAuth\ProviderLoader; +use OC\EventDispatcher\SymfonyAdapter; use OCP\Activity\IEvent; use OCP\Activity\IManager; use OCP\AppFramework\Utility\ITimeFactory; @@ -103,7 +104,7 @@ protected function setUp(): void { $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->eventDispatcher = $this->createMock(SymfonyAdapter::class); $this->manager = new Manager( $this->providerLoader, diff --git a/tests/lib/EventDispatcher/SymfonyAdapterTest.php b/tests/lib/EventDispatcher/SymfonyAdapterTest.php index 1b770c94e560f..d5092a95a1472 100644 --- a/tests/lib/EventDispatcher/SymfonyAdapterTest.php +++ b/tests/lib/EventDispatcher/SymfonyAdapterTest.php @@ -32,7 +32,7 @@ use OCP\EventDispatcher\GenericEvent; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\Event as SymfonyEvent; +use Symfony\Contracts\EventDispatcher\Event as SymfonyEvent; use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent as SymfonyGenericEvent; @@ -179,6 +179,7 @@ public function testDispatchEventWithoutPayload(): void { $symfonyDispatcher->expects(self::once()) ->method('dispatch') ->with( + $this->anything(), $eventName ) ->willReturnArgument(0); diff --git a/tests/lib/Group/GroupTest.php b/tests/lib/Group/GroupTest.php index ac648fd7b4bbf..8ee32a5c48e8d 100644 --- a/tests/lib/Group/GroupTest.php +++ b/tests/lib/Group/GroupTest.php @@ -9,6 +9,7 @@ namespace Test\Group; +use OC\EventDispatcher\SymfonyAdapter; use OC\User\User; use OCP\IUser; use PHPUnit\Framework\MockObject\MockObject; @@ -20,7 +21,7 @@ class GroupTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->dispatcher = $this->createMock(SymfonyAdapter::class); } /** diff --git a/tests/lib/Group/ManagerTest.php b/tests/lib/Group/ManagerTest.php index 710d3888d55ab..98042cfc6bba2 100644 --- a/tests/lib/Group/ManagerTest.php +++ b/tests/lib/Group/ManagerTest.php @@ -23,6 +23,7 @@ namespace Test\Group; +use OC\EventDispatcher\SymfonyAdapter; use OC\Group\Database; use OC\User\User; use OC\User\Manager; @@ -52,7 +53,7 @@ protected function setUp(): void { parent::setUp(); $this->userManager = $this->createMock(Manager::class); - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->dispatcher = $this->createMock(SymfonyAdapter::class); $this->logger = $this->createMock(LoggerInterface::class); $this->cache = $this->createMock(ICacheFactory::class); } diff --git a/tests/lib/Preview/GeneratorTest.php b/tests/lib/Preview/GeneratorTest.php index 37fc3935139e0..443aa4c406a49 100644 --- a/tests/lib/Preview/GeneratorTest.php +++ b/tests/lib/Preview/GeneratorTest.php @@ -23,6 +23,7 @@ namespace Test\Preview; +use OC\EventDispatcher\SymfonyAdapter; use OC\Preview\Generator; use OC\Preview\GeneratorHelper; use OCP\EventDispatcher\IEventDispatcher; @@ -68,7 +69,7 @@ protected function setUp(): void { $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->legacyEventDispatcher = $this->createMock(SymfonyAdapter::class); $this->generator = new Generator( $this->config, diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 0e56592e1a524..881a71fc9fcb1 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -21,6 +21,7 @@ namespace Test\Share20; +use OC\EventDispatcher\SymfonyAdapter; use OC\Files\Mount\MoveableMount; use OC\KnownUser\KnownUserService; use OC\Share20\DefaultShareProvider; @@ -120,7 +121,7 @@ protected function setUp(): void { $this->groupManager = $this->createMock(IGroupManager::class); $this->userManager = $this->createMock(IUserManager::class); $this->rootFolder = $this->createMock(IRootFolder::class); - $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); + $this->eventDispatcher = $this->createMock(SymfonyAdapter::class); $this->mailer = $this->createMock(IMailer::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->defaults = $this->createMock(\OC_Defaults::class); @@ -258,7 +259,7 @@ public function testDelete($shareType, $sharedWith) { $this->callBack(function (GenericEvent $e) use ($share) { return $e->getSubject() === $share && $e->getArgument('deletedShares') === [$share]; - })] + })], ); $manager->deleteShare($share); @@ -367,7 +368,7 @@ public function testDeleteNested() { $this->callBack(function (GenericEvent $e) use ($share1, $share2, $share3) { return $e->getSubject() === $share1 && $e->getArgument('deletedShares') === [$share3, $share2, $share1]; - })] + })], ); $manager->deleteShare($share1); @@ -401,7 +402,7 @@ public function testDeleteFromSelf() { 'OCP\Share::postUnshareFromSelf', $this->callBack(function (GenericEvent $e) use ($share) { return $e->getSubject() === $share; - }) + }), ); $manager->deleteFromSelf($share, $recipientId); @@ -550,6 +551,7 @@ public function testVerifyPasswordHook() { $this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event); /** @var ValidatePasswordPolicyEvent $event */ $this->assertSame('password', $event->getPassword()); + return $event; } ); @@ -2525,10 +2527,11 @@ public function testCreateShareHookError() { ->method('dispatch') ->with( $this->equalTo('OCP\Share::preShare'), - $this->isInstanceOf(GenericEvent::class) + $this->isInstanceOf(GenericEvent::class), )->willReturnCallback(function ($name, GenericEvent $e) { $e->setArgument('error', 'I won\'t let you share!'); $e->stopPropagation(); + return $e; } ); diff --git a/tests/lib/SystemTag/SystemTagManagerTest.php b/tests/lib/SystemTag/SystemTagManagerTest.php index e261a68aaf796..1a75c4cdcf603 100644 --- a/tests/lib/SystemTag/SystemTagManagerTest.php +++ b/tests/lib/SystemTag/SystemTagManagerTest.php @@ -10,6 +10,7 @@ namespace Test\SystemTag; +use OC\EventDispatcher\SymfonyAdapter; use OC\SystemTag\SystemTagManager; use OC\SystemTag\SystemTagObjectMapper; use OCP\IDBConnection; @@ -52,8 +53,7 @@ protected function setUp(): void { $this->connection = \OC::$server->getDatabaseConnection(); - $this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface') - ->getMock(); + $this->dispatcher = $this->createMock(SymfonyAdapter::class); $this->groupManager = $this->getMockBuilder(IGroupManager::class)->getMock(); diff --git a/tests/lib/SystemTag/SystemTagObjectMapperTest.php b/tests/lib/SystemTag/SystemTagObjectMapperTest.php index e77709c781fcc..6edcfdea052f7 100644 --- a/tests/lib/SystemTag/SystemTagObjectMapperTest.php +++ b/tests/lib/SystemTag/SystemTagObjectMapperTest.php @@ -10,6 +10,7 @@ namespace Test\SystemTag; +use OC\EventDispatcher\SymfonyAdapter; use OC\SystemTag\SystemTag; use OC\SystemTag\SystemTagManager; use OC\SystemTag\SystemTagObjectMapper; @@ -72,8 +73,7 @@ protected function setUp(): void { $this->tagManager = $this->getMockBuilder('OCP\SystemTag\ISystemTagManager') ->getMock(); - $this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface') - ->getMock(); + $this->dispatcher = $this->createMock(SymfonyAdapter::class); $this->tagMapper = new SystemTagObjectMapper( $this->connection, diff --git a/tests/lib/User/DatabaseTest.php b/tests/lib/User/DatabaseTest.php index 49b691cf9bc4f..327e0b7e45f97 100644 --- a/tests/lib/User/DatabaseTest.php +++ b/tests/lib/User/DatabaseTest.php @@ -22,6 +22,7 @@ namespace Test\User; +use OC\EventDispatcher\SymfonyAdapter; use OC\User\User; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventDispatcher; @@ -130,8 +131,8 @@ public function testSearch() { $user2 = $this->getUser(); $this->backend->createUser($user2, 'pass1'); - $user1Obj = new User($user1, $this->backend, $this->createMock(EventDispatcherInterface::class)); - $user2Obj = new User($user2, $this->backend, $this->createMock(EventDispatcherInterface::class)); + $user1Obj = new User($user1, $this->backend, $this->createMock(SymfonyAdapter::class)); + $user2Obj = new User($user2, $this->backend, $this->createMock(SymfonyAdapter::class)); $emailAddr1 = "$user1@nextcloud.com"; $emailAddr2 = "$user2@nextcloud.com"; diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php index cf6f03a5a0d5f..3c9f3a3498a9b 100644 --- a/tests/lib/User/ManagerTest.php +++ b/tests/lib/User/ManagerTest.php @@ -10,6 +10,7 @@ namespace Test\User; use OC\AllConfig; +use OC\EventDispatcher\SymfonyAdapter; use OC\User\Database; use OC\User\Manager; use OCP\EventDispatcher\IEventDispatcher; @@ -43,7 +44,7 @@ protected function setUp(): void { parent::setUp(); $this->config = $this->createMock(IConfig::class); - $this->oldDispatcher = $this->createMock(EventDispatcherInterface::class); + $this->oldDispatcher = $this->createMock(SymfonyAdapter::class); $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->cache = $this->createMock(ICache::class); diff --git a/tests/lib/User/UserTest.php b/tests/lib/User/UserTest.php index 7f4ca97e18bbc..db6d7ffbe5ab5 100644 --- a/tests/lib/User/UserTest.php +++ b/tests/lib/User/UserTest.php @@ -10,6 +10,7 @@ namespace Test\User; use OC\AllConfig; +use OC\EventDispatcher\SymfonyAdapter; use OC\Files\Mount\ObjectHomeMountProvider; use OC\Hooks\PublicEmitter; use OC\User\User; @@ -38,7 +39,7 @@ class UserTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->dispatcher = $this->createMock(SymfonyAdapter::class); } public function testDisplayName() {