From 4ebf001b2ecd8f1cf2fef8faa47aa9a28200b8c9 Mon Sep 17 00:00:00 2001
From: Roeland Jago Douma <roeland@famdouma.nl>
Date: Mon, 11 Jul 2016 16:53:01 +0200
Subject: [PATCH] Improve ManagerTest

* No DB required
* Fixed phpunit 5.4 warnings
---
 tests/lib/Group/GroupTest.php   |   4 +-
 tests/lib/Group/ManagerTest.php | 408 ++++++++++++++++----------------
 2 files changed, 205 insertions(+), 207 deletions(-)

diff --git a/tests/lib/Group/GroupTest.php b/tests/lib/Group/GroupTest.php
index 040a86099a4..fcf6e9d6292 100644
--- a/tests/lib/Group/GroupTest.php
+++ b/tests/lib/Group/GroupTest.php
@@ -15,10 +15,10 @@ class GroupTest extends \Test\TestCase {
 
 	/**
 	 * @param string $uid
-	 * @param $backend
+	 * @param \OC\User\Backend $backend
 	 * @return User
 	 */
-	private function newUser($uid, $backend) {
+	private function newUser($uid, \OC\User\Backend $backend) {
 		$config = $this->getMockBuilder('\OCP\IConfig')
 			->disableOriginalConstructor()
 			->getMock();
diff --git a/tests/lib/Group/ManagerTest.php b/tests/lib/Group/ManagerTest.php
index 907f2b59452..ece99eb569d 100644
--- a/tests/lib/Group/ManagerTest.php
+++ b/tests/lib/Group/ManagerTest.php
@@ -9,24 +9,50 @@
 
 namespace Test\Group;
 
+use OC\User\Manager;
 use OC\User\User;
 
 class ManagerTest extends \Test\TestCase {
+	/** @var Manager */
+	private $userManager;
+
+	public function setUp() {
+		parent::setUp();
+
+		$this->userManager = $this->getMockBuilder('\OC\User\Manager')
+			->disableOriginalConstructor()
+			->getMock();
+	}
+
+	/**
+	 * @param string $uid
+	 * @param \OC\User\Backend $backend
+	 * @return User
+	 */
+	private function newUser($uid, $backend) {
+		$config = $this->getMockBuilder('\OCP\IConfig')
+			->disableOriginalConstructor()
+			->getMock();
+		$urlgenerator = $this->getMockBuilder('\OCP\IURLGenerator')
+			->disableOriginalConstructor()
+			->getMock();
+
+		return new User($uid, $backend, null, $config, $urlgenerator);
+	}
+	
 	public function testGet() {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend->expects($this->any())
 			->method('groupExists')
 			->with('group1')
 			->will($this->returnValue(true));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		$group = $manager->get('group1');
@@ -35,11 +61,7 @@ class ManagerTest extends \Test\TestCase {
 	}
 
 	public function testGetNoBackend() {
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 
 		$this->assertNull($manager->get('group1'));
 	}
@@ -48,17 +70,15 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend->expects($this->once())
 			->method('groupExists')
 			->with('group1')
 			->will($this->returnValue(false));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		$this->assertNull($manager->get('group1'));
@@ -68,11 +88,7 @@ class ManagerTest extends \Test\TestCase {
 		$backend = new \Test\Util\Group\Dummy();
 		$backend->createGroup('group1');
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		$group = $manager->get('group1');
@@ -84,7 +100,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1
 		 */
-		$backend1 = $this->getMock('\OC\Group\Database');
+		$backend1 = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend1->expects($this->any())
 			->method('groupExists')
 			->with('group1')
@@ -93,17 +111,15 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend2
 		 */
-		$backend2 = $this->getMock('\OC\Group\Database');
+		$backend2 = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend2->expects($this->any())
 			->method('groupExists')
 			->with('group1')
 			->will($this->returnValue(true));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend1);
 		$manager->addBackend($backend2);
 
@@ -117,7 +133,9 @@ class ManagerTest extends \Test\TestCase {
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend
 		 */
 		$backendGroupCreated = false;
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend->expects($this->any())
 			->method('groupExists')
 			->with('group1')
@@ -133,11 +151,7 @@ class ManagerTest extends \Test\TestCase {
 				$backendGroupCreated = true;
 			}));;
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		$group = $manager->createGroup('group1');
@@ -148,7 +162,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend->expects($this->any())
 			->method('groupExists')
 			->with('group1')
@@ -156,11 +172,7 @@ class ManagerTest extends \Test\TestCase {
 		$backend->expects($this->never())
 			->method('createGroup');
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		$group = $manager->createGroup('group1');
@@ -171,7 +183,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend->expects($this->once())
 			->method('getGroups')
 			->with('1')
@@ -181,11 +195,7 @@ class ManagerTest extends \Test\TestCase {
 			->with('group1')
 			->will($this->returnValue(true));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		$groups = $manager->search('1');
@@ -198,7 +208,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1
 		 */
-		$backend1 = $this->getMock('\OC\Group\Database');
+		$backend1 = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend1->expects($this->once())
 			->method('getGroups')
 			->with('1')
@@ -210,7 +222,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend2
 		 */
-		$backend2 = $this->getMock('\OC\Group\Database');
+		$backend2 = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend2->expects($this->once())
 			->method('getGroups')
 			->with('1')
@@ -219,11 +233,7 @@ class ManagerTest extends \Test\TestCase {
 			->method('groupExists')
 			->will($this->returnValue(true));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend1);
 		$manager->addBackend($backend2);
 
@@ -239,7 +249,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1
 		 */
-		$backend1 = $this->getMock('\OC\Group\Database');
+		$backend1 = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend1->expects($this->once())
 			->method('getGroups')
 			->with('1', 2, 1)
@@ -251,7 +263,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend2
 		 */
-		$backend2 = $this->getMock('\OC\Group\Database');
+		$backend2 = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend2->expects($this->once())
 			->method('getGroups')
 			->with('1', 2, 1)
@@ -260,11 +274,7 @@ class ManagerTest extends \Test\TestCase {
 			->method('groupExists')
 			->will($this->returnValue(true));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend1);
 		$manager->addBackend($backend2);
 
@@ -280,7 +290,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend->expects($this->once())
 			->method('getUserGroups')
 			->with('user1')
@@ -290,15 +302,13 @@ class ManagerTest extends \Test\TestCase {
 			->with('group1')
 			->will($this->returnValue(true));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$userBackend = $this->getMock('\OC_User_Backend');
-		$manager = new \OC\Group\Manager($userManager);
+		$userBackend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
-		$groups = $manager->getUserGroups(new User('user1', $userBackend));
+		$groups = $manager->getUserGroups($this->newUser('user1', $userBackend));
 		$this->assertEquals(1, count($groups));
 		$group1 = reset($groups);
 		$this->assertEquals('group1', $group1->getGID());
@@ -334,7 +344,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend->expects($this->once())
 			->method('getUserGroups')
 			->with('user1')
@@ -343,12 +355,7 @@ class ManagerTest extends \Test\TestCase {
 			->method('groupExists')
 			->will($this->returnValue(true));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$userBackend = $this->getMock('\OC_User_Backend');
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		$this->assertTrue($manager->isInGroup('user1', 'group1'));
@@ -358,7 +365,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend->expects($this->once())
 			->method('getUserGroups')
 			->with('user1')
@@ -367,12 +376,7 @@ class ManagerTest extends \Test\TestCase {
 			->method('groupExists')
 			->will($this->returnValue(true));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$userBackend = $this->getMock('\OC_User_Backend');
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		$this->assertTrue($manager->isAdmin('user1'));
@@ -382,7 +386,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend->expects($this->once())
 			->method('getUserGroups')
 			->with('user1')
@@ -391,12 +397,7 @@ class ManagerTest extends \Test\TestCase {
 			->method('groupExists')
 			->will($this->returnValue(true));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$userBackend = $this->getMock('\OC_User_Backend');
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		$this->assertFalse($manager->isAdmin('user1'));
@@ -406,7 +407,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1
 		 */
-		$backend1 = $this->getMock('\OC\Group\Database');
+		$backend1 = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend1->expects($this->once())
 			->method('getUserGroups')
 			->with('user1')
@@ -418,7 +421,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend2
 		 */
-		$backend2 = $this->getMock('\OC\Group\Database');
+		$backend2 = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend2->expects($this->once())
 			->method('getUserGroups')
 			->with('user1')
@@ -427,16 +432,14 @@ class ManagerTest extends \Test\TestCase {
 			->method('groupExists')
 			->will($this->returnValue(true));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$userBackend = $this->getMock('\OC_User_Backend');
-		$manager = new \OC\Group\Manager($userManager);
+		$userBackend = $this->getMockBuilder('\OC\User\Backend')
+			->disableOriginalConstructor()
+			->getMock();
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend1);
 		$manager->addBackend($backend2);
 
-		$groups = $manager->getUserGroups(new User('user1', $userBackend));
+		$groups = $manager->getUserGroups($this->newUser('user1', $userBackend));
 		$this->assertEquals(2, count($groups));
 		$group1 = reset($groups);
 		$group2 = next($groups);
@@ -448,7 +451,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend->expects($this->exactly(1))
 			->method('groupExists')
 			->with('testgroup')
@@ -467,37 +472,35 @@ class ManagerTest extends \Test\TestCase {
                                 }
                         }));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$userBackend = $this->getMock('\OC_User_Backend');
+		$userBackend = $this->getMockBuilder('\OC\User\Backend')
+			->disableOriginalConstructor()
+			->getMock();
 
-		$userManager->expects($this->any())
+		$this->userManager->expects($this->any())
 			->method('searchDisplayName')
 			->with('user3')
 			->will($this->returnCallback(function($search, $limit, $offset) use ($userBackend) {
                                 switch($offset) {
-                                        case 0 : return array('user3' => new User('user3', $userBackend),
-                                                        'user33' => new User('user33', $userBackend));
+                                        case 0 : return array('user3' => $this->newUser('user3', $userBackend),
+                                                        'user33' => $this->newUser('user33', $userBackend));
                                         case 2 : return array();
                                 }
                         }));
 
-		$userManager->expects($this->any())
+		$this->userManager->expects($this->any())
 			->method('get')
 			->will($this->returnCallback(function($uid) use ($userBackend) {
 				switch($uid) {
-					case 'user1' : return new User('user1', $userBackend);
-					case 'user2' : return new User('user2', $userBackend);
-					case 'user3' : return new User('user3', $userBackend);
-					case 'user33': return new User('user33', $userBackend);
+					case 'user1' : return $this->newUser('user1', $userBackend);
+					case 'user2' : return $this->newUser('user2', $userBackend);
+					case 'user3' : return $this->newUser('user3', $userBackend);
+					case 'user33': return $this->newUser('user33', $userBackend);
 					default:
 						return null;
 				}
 			}));
 
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		$users = $manager->displayNamesInGroup('testgroup', 'user3');
@@ -512,7 +515,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend->expects($this->exactly(1))
 			->method('groupExists')
 			->with('testgroup')
@@ -532,38 +537,36 @@ class ManagerTest extends \Test\TestCase {
                                 }
                         }));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$userBackend = $this->getMock('\OC_User_Backend');
+		$userBackend = $this->getMockBuilder('\OC\User\Backend')
+			->disableOriginalConstructor()
+			->getMock();
 
-		$userManager->expects($this->any())
+		$this->userManager->expects($this->any())
 			->method('searchDisplayName')
 			->with('user3')
 			->will($this->returnCallback(function($search, $limit, $offset) use ($userBackend) {
                                 switch($offset) {
-                                        case 0 : return array('user3' => new User('user3', $userBackend),
-                                                        'user33' => new User('user33', $userBackend));
-                                        case 2 : return array('user333' => new User('user333', $userBackend));
+                                        case 0 : return array('user3' => $this->newUser('user3', $userBackend),
+                                                        'user33' => $this->newUser('user33', $userBackend));
+                                        case 2 : return array('user333' => $this->newUser('user333', $userBackend));
                                 }
                         }));
 
-		$userManager->expects($this->any())
+		$this->userManager->expects($this->any())
 			->method('get')
 			->will($this->returnCallback(function($uid) use ($userBackend) {
 				switch($uid) {
-					case 'user1' : return new User('user1', $userBackend);
-					case 'user2' : return new User('user2', $userBackend);
-					case 'user3' : return new User('user3', $userBackend);
-					case 'user33': return new User('user33', $userBackend);
-					case 'user333': return new User('user333', $userBackend);
+					case 'user1' : return $this->newUser('user1', $userBackend);
+					case 'user2' : return $this->newUser('user2', $userBackend);
+					case 'user3' : return $this->newUser('user3', $userBackend);
+					case 'user33': return $this->newUser('user33', $userBackend);
+					case 'user333': return $this->newUser('user333', $userBackend);
 					default:
 						return null;
 				}
 			}));
 
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		$users = $manager->displayNamesInGroup('testgroup', 'user3', 1);
@@ -579,7 +582,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend->expects($this->exactly(1))
 			->method('groupExists')
 			->with('testgroup')
@@ -599,41 +604,39 @@ class ManagerTest extends \Test\TestCase {
                                 }
                         }));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$userBackend = $this->getMock('\OC_User_Backend');
+		$userBackend = $this->getMockBuilder('\OC\User\Backend')
+			->disableOriginalConstructor()
+			->getMock();
 
-		$userManager->expects($this->any())
+		$this->userManager->expects($this->any())
 			->method('searchDisplayName')
 			->with('user3')
 			->will($this->returnCallback(function($search, $limit, $offset) use ($userBackend) {
                                 switch($offset) {
                                         case 0 :
 											return array(
-												'user3' => new User('user3', $userBackend),
-                                                'user33' => new User('user33', $userBackend),
-												'user333' => new User('user333', $userBackend)
+												'user3' => $this->newUser('user3', $userBackend),
+                                                'user33' => $this->newUser('user33', $userBackend),
+												'user333' => $this->newUser('user333', $userBackend)
 											);
                                 }
                         }));
 
-		$userManager->expects($this->any())
+		$this->userManager->expects($this->any())
 			->method('get')
 			->will($this->returnCallback(function($uid) use ($userBackend) {
 				switch($uid) {
-					case 'user1' : return new User('user1', $userBackend);
-					case 'user2' : return new User('user2', $userBackend);
-					case 'user3' : return new User('user3', $userBackend);
-					case 'user33': return new User('user33', $userBackend);
-					case 'user333': return new User('user333', $userBackend);
+					case 'user1' : return $this->newUser('user1', $userBackend);
+					case 'user2' : return $this->newUser('user2', $userBackend);
+					case 'user3' : return $this->newUser('user3', $userBackend);
+					case 'user33': return $this->newUser('user33', $userBackend);
+					case 'user333': return $this->newUser('user333', $userBackend);
 					default:
 						return null;
 				}
 			}));
 
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		$users = $manager->displayNamesInGroup('testgroup', 'user3', 1, 1);
@@ -649,7 +652,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend->expects($this->exactly(1))
 			->method('groupExists')
 			->with('testgroup')
@@ -660,26 +665,24 @@ class ManagerTest extends \Test\TestCase {
 			->with('testgroup', '', -1, 0)
 			->will($this->returnValue(array('user2', 'user33')));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$userBackend = $this->getMock('\OC_User_Backend');
+		$userBackend = $this->getMockBuilder('\OC\User\Backend')
+			->disableOriginalConstructor()
+			->getMock();
 
-		$userManager->expects($this->any())
+		$this->userManager->expects($this->any())
 			->method('get')
 			->will($this->returnCallback(function($uid) use ($userBackend) {
 				switch($uid) {
-					case 'user1' : return new User('user1', $userBackend);
-					case 'user2' : return new User('user2', $userBackend);
-					case 'user3' : return new User('user3', $userBackend);
-					case 'user33': return new User('user33', $userBackend);
+					case 'user1' : return $this->newUser('user1', $userBackend);
+					case 'user2' : return $this->newUser('user2', $userBackend);
+					case 'user3' : return $this->newUser('user3', $userBackend);
+					case 'user33': return $this->newUser('user33', $userBackend);
 					default:
 						return null;
 				}
 			}));
 
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		$users = $manager->displayNamesInGroup('testgroup', '');
@@ -694,7 +697,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend->expects($this->exactly(1))
 			->method('groupExists')
 			->with('testgroup')
@@ -704,26 +709,25 @@ class ManagerTest extends \Test\TestCase {
 			->method('usersInGroup')
 			->with('testgroup', '', 1, 0)
 			->will($this->returnValue(array('user2')));
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$userBackend = $this->getMock('\OC_User_Backend');
 
-		$userManager->expects($this->any())
+		$userBackend = $this->getMockBuilder('\OC\User\Backend')
+			->disableOriginalConstructor()
+			->getMock();
+
+		$this->userManager->expects($this->any())
 			->method('get')
 			->will($this->returnCallback(function($uid) use ($userBackend) {
 				switch($uid) {
-					case 'user1' : return new User('user1', $userBackend);
-					case 'user2' : return new User('user2', $userBackend);
-					case 'user3' : return new User('user3', $userBackend);
-					case 'user33': return new User('user33', $userBackend);
+					case 'user1' : return $this->newUser('user1', $userBackend);
+					case 'user2' : return $this->newUser('user2', $userBackend);
+					case 'user3' : return $this->newUser('user3', $userBackend);
+					case 'user33': return $this->newUser('user33', $userBackend);
 					default:
 						return null;
 				}
 			}));
 
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		$users = $manager->displayNamesInGroup('testgroup', '', 1);
@@ -738,7 +742,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend->expects($this->exactly(1))
 			->method('groupExists')
 			->with('testgroup')
@@ -749,26 +755,24 @@ class ManagerTest extends \Test\TestCase {
 			->with('testgroup', '', 1, 1)
 			->will($this->returnValue(array('user33')));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$userBackend = $this->getMock('\OC_User_Backend');
+		$userBackend = $this->getMockBuilder('\OC\User\Backend')
+			->disableOriginalConstructor()
+			->getMock();
 
-		$userManager->expects($this->any())
+		$this->userManager->expects($this->any())
 			->method('get')
 			->will($this->returnCallback(function($uid) use ($userBackend) {
 				switch($uid) {
-					case 'user1' : return new User('user1', $userBackend);
-					case 'user2' : return new User('user2', $userBackend);
-					case 'user3' : return new User('user3', $userBackend);
-					case 'user33': return new User('user33', $userBackend);
+					case 'user1' : return $this->newUser('user1', $userBackend);
+					case 'user2' : return $this->newUser('user2', $userBackend);
+					case 'user3' : return $this->newUser('user3', $userBackend);
+					case 'user33': return $this->newUser('user33', $userBackend);
 					default:
 						return null;
 				}
 			}));
 
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		$users = $manager->displayNamesInGroup('testgroup', '', 1, 1);
@@ -783,7 +787,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$expectedGroups = array();
 		$backend->expects($this->any())
 			->method('getUserGroups')
@@ -799,15 +805,11 @@ class ManagerTest extends \Test\TestCase {
 			->method('implementsActions')
 			->will($this->returnValue(true));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		// prime cache
-		$user1 = new User('user1', null);
+		$user1 = $this->newUser('user1', null);
 		$groups = $manager->getUserGroups($user1);
 		$this->assertEquals(array(), $groups);
 
@@ -827,7 +829,9 @@ class ManagerTest extends \Test\TestCase {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$expectedGroups = array('group1');
 		$backend->expects($this->any())
 			->method('getUserGroups')
@@ -849,15 +853,11 @@ class ManagerTest extends \Test\TestCase {
 			->method('removeFromGroup')
 			->will($this->returnValue(true));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		// prime cache
-		$user1 = new User('user1', null);
+		$user1 = $this->newUser('user1', null);
 		$groups = $manager->getUserGroups($user1);
 		$this->assertEquals(1, count($groups));
 		$group1 = reset($groups);
@@ -870,24 +870,22 @@ class ManagerTest extends \Test\TestCase {
 
 		// check result
 		$groups = $manager->getUserGroups($user1);
-		$this->assertEquals(array(), $groups);
+		$this->assertEquals($expectedGroups, $groups);
 	}
 
 	public function testGetUserIdGroups() {
 		/**
 		 * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend
 		 */
-		$backend = $this->getMock('\OC\Group\Database');
+		$backend = $this->getMockBuilder('\OC\Group\Database')
+			->disableOriginalConstructor()
+			->getMock();
 		$backend->expects($this->any())
 			->method('getUserGroups')
 			->with('user1')
 			->will($this->returnValue(null));
 
-		/**
-		 * @var \OC\User\Manager $userManager
-		 */
-		$userManager = $this->getMock('\OC\User\Manager');
-		$manager = new \OC\Group\Manager($userManager);
+		$manager = new \OC\Group\Manager($this->userManager);
 		$manager->addBackend($backend);
 
 		$groups = $manager->getUserIdGroups('user1');
-- 
GitLab