1515use OCP \Files \IRootFolder ;
1616use OCP \Files \Node ;
1717use OCP \IDBConnection ;
18- use OCP \ITagManager ;
1918use OCP \IUser ;
2019use OCP \IUserManager ;
2120use OCP \IUserSession ;
2221use OCP \Server ;
22+ use PHPUnit \Framework \MockObject \MockObject ;
2323use Psr \Log \LoggerInterface ;
2424
2525/**
2828#[\PHPUnit \Framework \Attributes \Group('DB ' )]
2929class TagsTest extends \Test \TestCase {
3030 protected $ objectType ;
31- /** @var IUser */
32- protected $ user ;
33- /** @var IUserSession */
34- protected $ userSession ;
35- protected $ backupGlobals = false ;
36- /** @var \OC\Tagging\TagMapper */
37- protected $ tagMapper ;
38- /** @var ITagManager */
39- protected $ tagMgr ;
40- protected IRootFolder $ rootFolder ;
31+ protected IUser &MockObject $ user ;
32+ protected IUserSession &MockObject $ userSession ;
33+ protected IUserManager &MockObject $ userManager ;
34+ protected IRootFolder &MockObject $ rootFolder ;
35+
36+ protected TagMapper $ tagMapper ;
37+ protected TagManager $ tagMgr ;
4138
4239 protected function setUp (): void {
4340 parent ::setUp ();
@@ -50,6 +47,11 @@ protected function setUp(): void {
5047 $ this ->user = $ this ->createMock (IUser::class);
5148 $ this ->user ->method ('getUID ' )
5249 ->willReturn ($ userId );
50+ $ this ->userManager = $ this ->createMock (IUserManager::class);
51+ $ this ->userManager
52+ ->expects ($ this ->any ())
53+ ->method ('getExistingUser ' )
54+ ->willReturn ($ this ->user );
5355 $ this ->userSession = $ this ->createMock (IUserSession::class);
5456 $ this ->userSession
5557 ->expects ($ this ->any ())
@@ -70,7 +72,15 @@ protected function setUp(): void {
7072
7173 $ this ->objectType = $ this ->getUniqueID ('type_ ' );
7274 $ this ->tagMapper = new TagMapper (Server::get (IDBConnection::class));
73- $ this ->tagMgr = new TagManager ($ this ->tagMapper , $ this ->userSession , Server::get (IDBConnection::class), Server::get (LoggerInterface::class), Server::get (IEventDispatcher::class), $ this ->rootFolder );
75+ $ this ->tagMgr = new TagManager (
76+ $ this ->tagMapper ,
77+ $ this ->userSession ,
78+ $ this ->userManager ,
79+ Server::get (IDBConnection::class),
80+ Server::get (LoggerInterface::class),
81+ Server::get (IEventDispatcher::class),
82+ $ this ->rootFolder
83+ );
7484 }
7585
7686 protected function tearDown (): void {
@@ -87,7 +97,15 @@ public function testTagManagerWithoutUserReturnsNull(): void {
8797 ->expects ($ this ->any ())
8898 ->method ('getUser ' )
8999 ->willReturn (null );
90- $ this ->tagMgr = new TagManager ($ this ->tagMapper , $ this ->userSession , Server::get (IDBConnection::class), Server::get (LoggerInterface::class), Server::get (IEventDispatcher::class), $ this ->rootFolder );
100+ $ this ->tagMgr = new TagManager (
101+ $ this ->tagMapper ,
102+ $ this ->userSession ,
103+ $ this ->userManager ,
104+ Server::get (IDBConnection::class),
105+ Server::get (LoggerInterface::class),
106+ Server::get (IEventDispatcher::class),
107+ $ this ->rootFolder
108+ );
91109 $ this ->assertNull ($ this ->tagMgr ->load ($ this ->objectType ));
92110 }
93111
0 commit comments