Skip to content

Commit 10fdcfa

Browse files
committed
fix(tests): Fix checking legacy events in tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent f32b6e8 commit 10fdcfa

File tree

18 files changed

+50
-32
lines changed

18 files changed

+50
-32
lines changed

apps/files_trashbin/tests/StorageTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
*/
3232
namespace OCA\Files_Trashbin\Tests;
3333

34+
use OC\EventDispatcher\SymfonyAdapter;
3435
use OC\Files\Filesystem;
3536
use OC\Files\Storage\Common;
3637
use OC\Files\Storage\Local;
@@ -607,7 +608,7 @@ public function testShouldMoveToTrash($mountPoint, $path, $userExists, $appDisab
607608
$userManager->expects($this->any())
608609
->method('userExists')->willReturn($userExists);
609610
$logger = $this->getMockBuilder(ILogger::class)->getMock();
610-
$eventDispatcher = $this->createMock(EventDispatcherInterface::class);
611+
$eventDispatcher = $this->createMock(SymfonyAdapter::class);
611612
$rootFolder = $this->createMock(IRootFolder::class);
612613
$userFolder = $this->createMock(Folder::class);
613614
$node = $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock();

apps/settings/tests/Controller/CheckSetupControllerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use Doctrine\DBAL\Platforms\SqlitePlatform;
3939
use OC;
4040
use OC\DB\Connection;
41+
use OC\EventDispatcher\SymfonyAdapter;
4142
use OC\IntegrityCheck\Checker;
4243
use OC\MemoryInfo;
4344
use OC\Security\SecureRandom;
@@ -137,7 +138,7 @@ protected function setUp(): void {
137138
->willReturnCallback(function ($message, array $replace) {
138139
return vsprintf($message, $replace);
139140
});
140-
$this->dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)
141+
$this->dispatcher = $this->getMockBuilder(SymfonyAdapter::class)
141142
->disableOriginalConstructor()->getMock();
142143
$this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
143144
->disableOriginalConstructor()->getMock();

apps/workflowengine/tests/ManagerTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727
namespace OCA\WorkflowEngine\Tests;
2828

29+
use OC\EventDispatcher\SymfonyAdapter;
2930
use OC\L10N\L10N;
3031
use OCA\WorkflowEngine\Entity\File;
3132
use OCA\WorkflowEngine\Helper\ScopeContext;
@@ -94,7 +95,7 @@ protected function setUp(): void {
9495
return vsprintf($text, $parameters);
9596
});
9697

97-
$this->legacyDispatcher = $this->createMock(EventDispatcherInterface::class);
98+
$this->legacyDispatcher = $this->createMock(SymfonyAdapter::class);
9899
$this->logger = $this->createMock(ILogger::class);
99100
$this->session = $this->createMock(IUserSession::class);
100101
$this->dispatcher = $this->createMock(IEventDispatcher::class);
@@ -535,8 +536,9 @@ public function testGetEntitiesList() {
535536
$this->legacyDispatcher->expects($this->once())
536537
->method('dispatch')
537538
->with('OCP\WorkflowEngine::registerEntities', $this->anything())
538-
->willReturnCallback(function () use ($extraEntity) {
539+
->willReturnCallback(function ($eventName, $event) use ($extraEntity) {
539540
$this->manager->registerEntity($extraEntity);
541+
return $event;
540542
});
541543

542544
$entities = $this->manager->getEntitiesList();

tests/lib/Accounts/AccountManagerTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
use OC\Accounts\Account;
2828
use OC\Accounts\AccountManager;
29+
use OC\EventDispatcher\SymfonyAdapter;
2930
use OCA\Settings\BackgroundJobs\VerifyUserData;
3031
use OCP\Accounts\IAccountManager;
3132
use OCP\BackgroundJob\IJobList;
@@ -86,7 +87,7 @@ class AccountManagerTest extends TestCase {
8687

8788
protected function setUp(): void {
8889
parent::setUp();
89-
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
90+
$this->eventDispatcher = $this->createMock(SymfonyAdapter::class);
9091
$this->connection = \OC::$server->get(IDBConnection::class);
9192
$this->config = $this->createMock(IConfig::class);
9293
$this->jobList = $this->createMock(IJobList::class);
@@ -511,11 +512,12 @@ function ($eventName, $event) use ($user, $newData) {
511512
$this->assertInstanceOf(GenericEvent::class, $event);
512513
$this->assertSame($user, $event->getSubject());
513514
$this->assertSame($newData, $event->getArguments());
515+
return $event;
514516
}
515517
);
516518
}
517519

518-
$this->invokePrivate($accountManager, 'updateUser', [$user, $newData, $oldData]);
520+
self::invokePrivate($accountManager, 'updateUser', [$user, $newData, $oldData]);
519521
}
520522

521523
public function dataTrueFalse(): array {

tests/lib/App/AppManagerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use OC\App\AppManager;
1515
use OC\AppConfig;
16+
use OC\EventDispatcher\SymfonyAdapter;
1617
use OCP\App\AppPathNotFoundException;
1718
use OCP\App\Events\AppDisableEvent;
1819
use OCP\App\Events\AppEnableEvent;
@@ -114,7 +115,7 @@ protected function setUp(): void {
114115
$this->appConfig = $this->getAppConfig();
115116
$this->cacheFactory = $this->createMock(ICacheFactory::class);
116117
$this->cache = $this->createMock(ICache::class);
117-
$this->legacyEventDispatcher = $this->createMock(EventDispatcherInterface::class);
118+
$this->legacyEventDispatcher = $this->createMock(SymfonyAdapter::class);
118119
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
119120
$this->logger = $this->createMock(LoggerInterface::class);
120121
$this->cacheFactory->expects($this->any())

tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@
2626
namespace Test\AppFramework\Middleware;
2727

2828
use OC\AppFramework\Middleware\AdditionalScriptsMiddleware;
29+
use OC\EventDispatcher\SymfonyAdapter;
2930
use OCP\AppFramework\Controller;
3031
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
3132
use OCP\AppFramework\Http\Response;
3233
use OCP\AppFramework\Http\StandaloneTemplateResponse;
3334
use OCP\AppFramework\Http\TemplateResponse;
3435
use OCP\AppFramework\PublicShareController;
36+
use OCP\EventDispatcher\Event;
3537
use OCP\EventDispatcher\IEventDispatcher;
3638
use OCP\IUserSession;
3739
use PHPUnit\Framework\MockObject\MockObject;
@@ -54,7 +56,7 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
5456
protected function setUp(): void {
5557
parent::setUp();
5658

57-
$this->legacyDispatcher = $this->createMock(EventDispatcherInterface::class);
59+
$this->legacyDispatcher = $this->createMock(SymfonyAdapter::class);
5860
$this->userSession = $this->createMock(IUserSession::class);
5961
$this->dispatcher = $this->createMock(IEventDispatcher::class);
6062
$this->middleWare = new AdditionalScriptsMiddleware(
@@ -93,7 +95,7 @@ public function testStandaloneTemplateResponse() {
9395
->method('dispatch')
9496
->willReturnCallback(function ($eventName) {
9597
if ($eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS) {
96-
return;
98+
return new Event();
9799
}
98100

99101
$this->fail('Wrong event dispatched');
@@ -118,7 +120,7 @@ public function testTemplateResponseNotLoggedIn() {
118120
->method('dispatch')
119121
->willReturnCallback(function ($eventName) {
120122
if ($eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS) {
121-
return;
123+
return new Event();
122124
}
123125

124126
$this->fail('Wrong event dispatched');
@@ -147,7 +149,7 @@ public function testTemplateResponseLoggedIn() {
147149
if ($eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS ||
148150
$eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN) {
149151
$events[] = $eventName;
150-
return;
152+
return new Event();
151153
}
152154

153155
$this->fail('Wrong event dispatched');

tests/lib/Authentication/TwoFactorAuth/ManagerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use OC\Authentication\TwoFactorAuth\Manager;
2828
use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
2929
use OC\Authentication\TwoFactorAuth\ProviderLoader;
30+
use OC\EventDispatcher\SymfonyAdapter;
3031
use OCP\Activity\IEvent;
3132
use OCP\Activity\IManager;
3233
use OCP\AppFramework\Utility\ITimeFactory;
@@ -103,7 +104,7 @@ protected function setUp(): void {
103104
$this->tokenProvider = $this->createMock(TokenProvider::class);
104105
$this->timeFactory = $this->createMock(ITimeFactory::class);
105106
$this->newDispatcher = $this->createMock(IEventDispatcher::class);
106-
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
107+
$this->eventDispatcher = $this->createMock(SymfonyAdapter::class);
107108

108109
$this->manager = new Manager(
109110
$this->providerLoader,

tests/lib/EventDispatcher/SymfonyAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
use OCP\EventDispatcher\GenericEvent;
3333
use PHPUnit\Framework\MockObject\MockObject;
3434
use Psr\Log\LoggerInterface;
35-
use Symfony\Component\EventDispatcher\Event as SymfonyEvent;
35+
use Symfony\Contracts\EventDispatcher\Event as SymfonyEvent;
3636
use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher;
3737
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
3838
use Symfony\Component\EventDispatcher\GenericEvent as SymfonyGenericEvent;

tests/lib/Files/Config/UserMountCacheTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Test\Files\Config;
1010

1111
use OC\DB\QueryBuilder\Literal;
12+
use OC\EventDispatcher\SymfonyAdapter;
1213
use OC\Files\Mount\MountPoint;
1314
use OC\Files\Storage\Storage;
1415
use OCP\Cache\CappedMemoryCache;
@@ -21,7 +22,6 @@
2122
use OCP\IDBConnection;
2223
use OCP\IUserManager;
2324
use Psr\Log\LoggerInterface;
24-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2525
use Test\TestCase;
2626
use Test\Util\User\Dummy;
2727

@@ -62,7 +62,7 @@ protected function setUp(): void {
6262
->expects($this->any())
6363
->method('getAppValue')
6464
->willReturnArgument(2);
65-
$this->userManager = new Manager($config, $this->createMock(EventDispatcherInterface::class), $this->createMock(ICacheFactory::class), $this->createMock(IEventDispatcher::class));
65+
$this->userManager = new Manager($config, $this->createMock(SymfonyAdapter::class), $this->createMock(ICacheFactory::class), $this->createMock(IEventDispatcher::class));
6666
$userBackend = new Dummy();
6767
$userBackend->createUser('u1', '');
6868
$userBackend->createUser('u2', '');

tests/lib/Group/GroupTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Test\Group;
1111

12+
use OC\EventDispatcher\SymfonyAdapter;
1213
use OC\User\User;
1314
use OCP\IUser;
1415
use PHPUnit\Framework\MockObject\MockObject;
@@ -20,7 +21,7 @@ class GroupTest extends \Test\TestCase {
2021

2122
protected function setUp(): void {
2223
parent::setUp();
23-
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
24+
$this->dispatcher = $this->createMock(SymfonyAdapter::class);
2425
}
2526

2627
/**

0 commit comments

Comments
 (0)