summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests/Group_LDAPTest.php
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2020-03-25 22:21:27 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-03-25 22:21:27 +0100
commit2ee65f177e4f7e09ad2287f14d564e7068d322fb (patch)
tree39075e87ea7927e20e8956824cb7c49bf626b178 /apps/user_ldap/tests/Group_LDAPTest.php
parent3cf321fdfc4235a87015a9af2f59c63220016c65 (diff)
downloadnextcloud-server-2ee65f177e4f7e09ad2287f14d564e7068d322fb.tar.gz
nextcloud-server-2ee65f177e4f7e09ad2287f14d564e7068d322fb.zip
Use the shorter phpunit syntax for mocked return values
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/user_ldap/tests/Group_LDAPTest.php')
-rw-r--r--apps/user_ldap/tests/Group_LDAPTest.php116
1 files changed, 58 insertions, 58 deletions
diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php
index 7ea4cb463d9..5fdc3c5862c 100644
--- a/apps/user_ldap/tests/Group_LDAPTest.php
+++ b/apps/user_ldap/tests/Group_LDAPTest.php
@@ -70,7 +70,7 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->any())
->method('getConnection')
- ->will($this->returnValue($connector));
+ ->willReturn($connector);
return $access;
}
@@ -87,12 +87,12 @@ class Group_LDAPTest extends TestCase {
$access->connection->expects($this->any())
->method('__get')
- ->will($this->returnCallback(function($name) {
+ ->willReturnCallback(function($name) {
if($name === 'ldapDynamicGroupMemberURL') {
return '';
}
return 1;
- }));
+ });
}
public function testCountEmptySearchString() {
@@ -104,7 +104,7 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->any())
->method('groupname2dn')
- ->will($this->returnValue($groupDN));
+ ->willReturn($groupDN);
$access->expects($this->any())
->method('readAttribute')
@@ -123,7 +123,7 @@ class Group_LDAPTest extends TestCase {
// for primary groups
$access->expects($this->once())
->method('countUsers')
- ->will($this->returnValue(2));
+ ->willReturn(2);
$groupBackend = new GroupLDAP($access, $pluginManager);
$users = $groupBackend->countUsersInGroup('group');
@@ -139,15 +139,15 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->any())
->method('groupname2dn')
- ->will($this->returnValue('cn=group,dc=foo,dc=bar'));
+ ->willReturn('cn=group,dc=foo,dc=bar');
$access->expects($this->any())
->method('fetchListOfUsers')
- ->will($this->returnValue([]));
+ ->willReturn([]);
$access->expects($this->any())
->method('readAttribute')
- ->will($this->returnCallback(function($name) {
+ ->willReturnCallback(function($name) {
//the search operation will call readAttribute, thus we need
//to anaylze the "dn". All other times we just need to return
//something that is neither null or false, but once an array
@@ -157,13 +157,13 @@ class Group_LDAPTest extends TestCase {
return strpos($name, '3');
}
return ['u11', 'u22', 'u33', 'u34'];
- }));
+ });
$access->expects($this->any())
->method('dn2username')
- ->will($this->returnCallback(function() {
+ ->willReturnCallback(function() {
return 'foobar' . \OC::$server->getSecureRandom()->generate(7);
- }));
+ });
$groupBackend = new GroupLDAP($access,$pluginManager);
$users = $groupBackend->countUsersInGroup('group', '3');
@@ -205,12 +205,12 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->once())
->method('searchGroups')
- ->will($this->returnValue([['dn' => ['cn=foo,dc=barfoo,dc=bar']]]));
+ ->willReturn([['dn' => ['cn=foo,dc=barfoo,dc=bar']]]);
$access->expects($this->once())
->method('dn2groupname')
->with('cn=foo,dc=barfoo,dc=bar')
- ->will($this->returnValue('MyGroup'));
+ ->willReturn('MyGroup');
$groupBackend = new GroupLDAP($access, $pluginManager);
@@ -229,7 +229,7 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->once())
->method('searchGroups')
- ->will($this->returnValue(array()));
+ ->willReturn(array());
$access->expects($this->never())
->method('dn2groupname');
@@ -251,11 +251,11 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->once())
->method('searchGroups')
- ->will($this->returnValue([['dn' => ['cn=foo,dc=barfoo,dc=bar']]]));
+ ->willReturn([['dn' => ['cn=foo,dc=barfoo,dc=bar']]]);
$access->expects($this->once())
->method('dn2groupname')
- ->will($this->returnValue(false));
+ ->willReturn(false);
$groupBackend = new GroupLDAP($access, $pluginManager);
@@ -276,7 +276,7 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->once())
->method('readAttribute')
->with($dn, $attr)
- ->will($this->returnValue(array('3117')));
+ ->willReturn(array('3117'));
$groupBackend = new GroupLDAP($access, $pluginManager);
@@ -297,7 +297,7 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->once())
->method('readAttribute')
->with($dn, $attr)
- ->will($this->returnValue(false));
+ ->willReturn(false);
$groupBackend = new GroupLDAP($access, $pluginManager);
@@ -317,16 +317,16 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->once())
->method('getSID')
->with($userDN)
- ->will($this->returnValue('S-1-5-21-249921958-728525901-1594176202'));
+ ->willReturn('S-1-5-21-249921958-728525901-1594176202');
$access->expects($this->once())
->method('searchGroups')
- ->will($this->returnValue([['dn' => ['cn=foo,dc=barfoo,dc=bar']]]));
+ ->willReturn([['dn' => ['cn=foo,dc=barfoo,dc=bar']]]);
$access->expects($this->once())
->method('dn2groupname')
->with('cn=foo,dc=barfoo,dc=bar')
- ->will($this->returnValue('MyGroup'));
+ ->willReturn('MyGroup');
$groupBackend = new GroupLDAP($access, $pluginManager);
@@ -346,7 +346,7 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->once())
->method('getSID')
->with($userDN)
- ->will($this->returnValue(false));
+ ->willReturn(false);
$access->expects($this->never())
->method('searchGroups');
@@ -372,11 +372,11 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->once())
->method('getSID')
->with($userDN)
- ->will($this->returnValue('S-1-5-21-249921958-728525901-1594176202'));
+ ->willReturn('S-1-5-21-249921958-728525901-1594176202');
$access->expects($this->once())
->method('searchGroups')
- ->will($this->returnValue(array()));
+ ->willReturn(array());
$access->expects($this->never())
->method('dn2groupname');
@@ -399,15 +399,15 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->once())
->method('getSID')
->with($userDN)
- ->will($this->returnValue('S-1-5-21-249921958-728525901-1594176202'));
+ ->willReturn('S-1-5-21-249921958-728525901-1594176202');
$access->expects($this->once())
->method('searchGroups')
- ->will($this->returnValue([['dn' => ['cn=foo,dc=barfoo,dc=bar']]]));
+ ->willReturn([['dn' => ['cn=foo,dc=barfoo,dc=bar']]]);
$access->expects($this->once())
->method('dn2groupname')
- ->will($this->returnValue(false));
+ ->willReturn(false);
$groupBackend = new GroupLDAP($access, $pluginManager);
@@ -430,7 +430,7 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->once())
->method('readAttribute')
->with($dn, $attr)
- ->will($this->returnValue(array('3117')));
+ ->willReturn(array('3117'));
$groupBackend = new GroupLDAP($access, $pluginManager);
@@ -453,7 +453,7 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->once())
->method('readAttribute')
->with($dn, $attr)
- ->will($this->returnValue(false));
+ ->willReturn(false);
$groupBackend = new GroupLDAP($access, $pluginManager);
@@ -479,7 +479,7 @@ class Group_LDAPTest extends TestCase {
$access->connection->expects($this->once())
->method('getFromCache')
->with($cacheKey)
- ->will($this->returnValue(true));
+ ->willReturn(true);
$access->expects($this->never())
->method('username2dn');
@@ -496,7 +496,7 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->once())
->method('nextcloudGroupNames')
- ->will($this->returnValue(array('group1', 'group2')));
+ ->willReturn(array('group1', 'group2'));
$groupBackend = new GroupLDAP($access, $pluginManager);
$groups = $groupBackend->getGroups('', 2, 2);
@@ -516,20 +516,20 @@ class Group_LDAPTest extends TestCase {
$access->connection->expects($this->any())
->method('getFromCache')
- ->will($this->returnValue(null));
+ ->willReturn(null);
$access->expects($this->any())
->method('readAttribute')
- ->will($this->returnCallback(function($dn, $attr) {
+ ->willReturnCallback(function($dn, $attr) {
if($attr === 'primaryGroupToken') {
return array(1337);
} else if($attr === 'gidNumber') {
return [4211];
}
return array();
- }));
+ });
$access->expects($this->any())
->method('groupname2dn')
- ->will($this->returnValue('cn=foobar,dc=foo,dc=bar'));
+ ->willReturn('cn=foobar,dc=foo,dc=bar');
$access->expects($this->exactly(2))
->method('nextcloudUserNames')
->willReturnOnConsecutiveCalls(['lisa', 'bart', 'kira', 'brad'], ['walle', 'dino', 'xenia']);
@@ -553,21 +553,21 @@ class Group_LDAPTest extends TestCase {
$access->connection->expects($this->any())
->method('getFromCache')
- ->will($this->returnValue(null));
+ ->willReturn(null);
$access->expects($this->any())
->method('readAttribute')
- ->will($this->returnCallback(function($dn, $attr) {
+ ->willReturnCallback(function($dn, $attr) {
if($attr === 'primaryGroupToken') {
return array(1337);
}
return array();
- }));
+ });
$access->expects($this->any())
->method('groupname2dn')
- ->will($this->returnValue('cn=foobar,dc=foo,dc=bar'));
+ ->willReturn('cn=foobar,dc=foo,dc=bar');
$access->expects($this->once())
->method('nextcloudUserNames')
- ->will($this->returnValue(array('lisa', 'bart', 'kira', 'brad')));
+ ->willReturn(array('lisa', 'bart', 'kira', 'brad'));
$access->userManager = $this->createMock(Manager::class);
$groupBackend = new GroupLDAP($access, $pluginManager);
@@ -588,24 +588,24 @@ class Group_LDAPTest extends TestCase {
$access->connection->expects($this->any())
->method('getFromCache')
- ->will($this->returnValue(null));
+ ->willReturn(null);
$access->expects($this->any())
->method('readAttribute')
- ->will($this->returnCallback(function($dn, $attr) {
+ ->willReturnCallback(function($dn, $attr) {
if($attr === 'primaryGroupToken') {
return array(1337);
}
return array();
- }));
+ });
$access->expects($this->any())
->method('groupname2dn')
- ->will($this->returnValue('cn=foobar,dc=foo,dc=bar'));
+ ->willReturn('cn=foobar,dc=foo,dc=bar');
$access->expects($this->once())
->method('countUsers')
- ->will($this->returnValue(4));
+ ->willReturn(4);
$groupBackend = new GroupLDAP($access, $pluginManager);
$users = $groupBackend->countUsersInGroup('foobar');
@@ -626,7 +626,7 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->any())
->method('username2dn')
- ->will($this->returnValue($dn));
+ ->willReturn($dn);
$access->expects($this->exactly(3))
->method('readAttribute')
@@ -634,11 +634,11 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->exactly(2))
->method('dn2groupname')
- ->will($this->returnArgument(0));
+ ->willReturnArgument(0);
$access->expects($this->exactly(1))
->method('groupsMatchFilter')
- ->will($this->returnArgument(0));
+ ->willReturnArgument(0);
$groupBackend = new GroupLDAP($access, $pluginManager);
$groups = $groupBackend->getUserGroups('userX');
@@ -653,14 +653,14 @@ class Group_LDAPTest extends TestCase {
$access->connection = $this->createMock(Connection::class);
$access->connection->expects($this->any())
->method('__get')
- ->will($this->returnCallback(function($name) {
+ ->willReturnCallback(function($name) {
if($name === 'useMemberOfToDetectMembership') {
return 0;
} else if($name === 'ldapDynamicGroupMemberURL') {
return '';
}
return 1;
- }));
+ });
$dn = 'cn=userX,dc=foobar';
@@ -669,13 +669,13 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->once())
->method('username2dn')
- ->will($this->returnValue($dn));
+ ->willReturn($dn);
$access->expects($this->never())
->method('readAttribute')
->with($dn, 'memberOf');
$access->expects($this->once())
->method('nextcloudGroupNames')
- ->will($this->returnValue([]));
+ ->willReturn([]);
$access->expects($this->any())
->method('groupsMatchFilter')
->willReturnArgument(0);
@@ -691,7 +691,7 @@ class Group_LDAPTest extends TestCase {
$access->connection = $this->createMock(Connection::class);
$access->connection->expects($this->any())
->method('__get')
- ->will($this->returnCallback(function($name) {
+ ->willReturnCallback(function($name) {
switch($name) {
case 'useMemberOfToDetectMembership':
return 0;
@@ -703,7 +703,7 @@ class Group_LDAPTest extends TestCase {
return 'member';
}
return 1;
- }));
+ });
$dn = 'cn=userX,dc=foobar';
@@ -712,7 +712,7 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->exactly(2))
->method('username2dn')
- ->will($this->returnValue($dn));
+ ->willReturn($dn);
$access->expects($this->never())
->method('readAttribute')
@@ -730,10 +730,10 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->once())
->method('nextcloudGroupNames')
->with([$group1, $group2])
- ->will($this->returnValue(['group1', 'group2']));
+ ->willReturn(['group1', 'group2']);
$access->expects($this->once())
->method('fetchListOfGroups')
- ->will($this->returnValue([$group1, $group2]));
+ ->willReturn([$group1, $group2]);
$access->expects($this->any())
->method('groupsMatchFilter')
->willReturnArgument(0);
@@ -816,7 +816,7 @@ class Group_LDAPTest extends TestCase {
$access = $this->getAccessMock();
$access->expects($this->any())
->method('getGroupMapper')
- ->will($this->returnValue($mapper));
+ ->willReturn($mapper);
$access->connection = $this->createMock(Connection::class);