diff options
Diffstat (limited to 'apps/user_ldap/tests/Group_LDAPTest.php')
-rw-r--r-- | apps/user_ldap/tests/Group_LDAPTest.php | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php index 8eabf2d295a..b3b2d68f94b 100644 --- a/apps/user_ldap/tests/Group_LDAPTest.php +++ b/apps/user_ldap/tests/Group_LDAPTest.php @@ -33,8 +33,11 @@ namespace OCA\User_LDAP\Tests; use OCP\GroupInterface; +use OCA\User_LDAP\Access; +use OCA\User_LDAP\Connection; use OCA\User_LDAP\Group_LDAP as GroupLDAP; use OCA\User_LDAP\ILDAPWrapper; +use OCA\User_LDAP\User\Manager; /** * Class GroupLDAPTest @@ -44,6 +47,9 @@ use OCA\User_LDAP\ILDAPWrapper; * @package OCA\User_LDAP\Tests */ class Group_LDAPTest extends \Test\TestCase { + /** + * @return \PHPUnit_Framework_MockObject_MockObject|Access + */ private function getAccessMock() { static $conMethods; static $accMethods; @@ -57,14 +63,8 @@ class Group_LDAPTest extends \Test\TestCase { ->setMethods($conMethods) ->setConstructorArgs([$lw, null, null]) ->getMock(); - $um = $this->getMockBuilder('\OCA\User_LDAP\User\Manager') - ->disableOriginalConstructor() - ->getMock(); - $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig()); - $access = $this->getMockBuilder('\OCA\User_LDAP\Access') - ->setMethods($accMethods) - ->setConstructorArgs([$connector, $lw, $um, $helper]) - ->getMock(); + + $access = $this->createMock(Access::class); $access->expects($this->any()) ->method('getConnection') @@ -76,8 +76,13 @@ class Group_LDAPTest extends \Test\TestCase { private function getPluginManagerMock() { return $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager')->getMock(); } - + + /** + * @param Access|\PHPUnit_Framework_MockObject_MockObject $access + */ private function enableGroups($access) { + $access->connection = $this->createMock(Connection::class); + $access->connection->expects($this->any()) ->method('__get') ->will($this->returnCallback(function($name) { @@ -498,7 +503,6 @@ class Group_LDAPTest extends \Test\TestCase { $access->connection->expects($this->any()) ->method('getFromCache') ->will($this->returnValue(null)); - $access->expects($this->any()) ->method('readAttribute') ->will($this->returnCallback(function($dn, $attr) { @@ -509,14 +513,13 @@ class Group_LDAPTest extends \Test\TestCase { } return array(); })); - $access->expects($this->any()) ->method('groupname2dn') ->will($this->returnValue('cn=foobar,dc=foo,dc=bar')); - $access->expects($this->exactly(2)) ->method('nextcloudUserNames') ->willReturnOnConsecutiveCalls(['lisa', 'bart', 'kira', 'brad'], ['walle', 'dino', 'xenia']); + $access->userManager = $this->createMock(Manager::class); $groupBackend = new GroupLDAP($access, $pluginManager); $users = $groupBackend->usersInGroup('foobar'); @@ -537,7 +540,6 @@ class Group_LDAPTest extends \Test\TestCase { $access->connection->expects($this->any()) ->method('getFromCache') ->will($this->returnValue(null)); - $access->expects($this->any()) ->method('readAttribute') ->will($this->returnCallback(function($dn, $attr) { @@ -546,14 +548,13 @@ class Group_LDAPTest extends \Test\TestCase { } return array(); })); - $access->expects($this->any()) ->method('groupname2dn') ->will($this->returnValue('cn=foobar,dc=foo,dc=bar')); - $access->expects($this->once()) ->method('nextcloudUserNames') ->will($this->returnValue(array('lisa', 'bart', 'kira', 'brad'))); + $access->userManager = $this->createMock(Manager::class); $groupBackend = new GroupLDAP($access, $pluginManager); $users = $groupBackend->usersInGroup('foobar'); @@ -635,6 +636,7 @@ class Group_LDAPTest extends \Test\TestCase { $access = $this->getAccessMock(); $pluginManager = $this->getPluginManagerMock(); + $access->connection = $this->createMock(Connection::class); $access->connection->expects($this->any()) ->method('__get') ->will($this->returnCallback(function($name) { @@ -671,6 +673,7 @@ class Group_LDAPTest extends \Test\TestCase { $access = $this->getAccessMock(); $pluginManager = $this->getPluginManagerMock(); + $access->connection = $this->createMock(Connection::class); $access->connection->expects($this->any()) ->method('__get') ->will($this->returnCallback(function($name) { |