summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests/User_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/User_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/User_LDAPTest.php')
-rw-r--r--apps/user_ldap/tests/User_LDAPTest.php140
1 files changed, 70 insertions, 70 deletions
diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php
index e4a105b2bd6..f3052b19327 100644
--- a/apps/user_ldap/tests/User_LDAPTest.php
+++ b/apps/user_ldap/tests/User_LDAPTest.php
@@ -107,7 +107,7 @@ class User_LDAPTest extends TestCase {
private function prepareMockForUserExists() {
$this->access->expects($this->any())
->method('username2dn')
- ->will($this->returnCallback(function($uid) {
+ ->willReturnCallback(function($uid) {
switch ($uid) {
case 'gunslinger':
return 'dnOfRoland,dc=test';
@@ -124,7 +124,7 @@ class User_LDAPTest extends TestCase {
default:
return false;
}
- }));
+ });
$this->access->method('fetchUsersByLoginName')
->willReturn([]);
@@ -138,29 +138,29 @@ class User_LDAPTest extends TestCase {
private function prepareAccessForCheckPassword($noDisplayName = false) {
$this->connection->expects($this->any())
->method('__get')
- ->will($this->returnCallback(function($name) {
+ ->willReturnCallback(function($name) {
if($name === 'ldapLoginFilter') {
return '%uid';
}
return null;
- }));
+ });
$this->access->expects($this->any())
->method('fetchListOfUsers')
- ->will($this->returnCallback(function($filter) {
+ ->willReturnCallback(function($filter) {
if($filter === 'roland') {
return array(array('dn' => ['dnOfRoland,dc=test']));
}
return array();
- }));
+ });
$this->access->expects($this->any())
->method('fetchUsersByLoginName')
- ->will($this->returnCallback(function($uid) {
+ ->willReturnCallback(function($uid) {
if($uid === 'roland') {
return array(array('dn' => ['dnOfRoland,dc=test']));
}
return array();
- }));
+ });
$retVal = 'gunslinger';
if($noDisplayName === true) {
@@ -169,19 +169,19 @@ class User_LDAPTest extends TestCase {
$this->access->expects($this->any())
->method('dn2username')
->with($this->equalTo('dnOfRoland,dc=test'))
- ->will($this->returnValue($retVal));
+ ->willReturn($retVal);
$this->access->expects($this->any())
->method('stringResemblesDN')
->with($this->equalTo('dnOfRoland,dc=test'))
- ->will($this->returnValue(true));
+ ->willReturn(true);
$this->access->expects($this->any())
->method('areCredentialsValid')
- ->will($this->returnCallback(function($dn, $pwd) {
+ ->willReturnCallback(function($dn, $pwd) {
if($pwd === 'dt19') {
return true;
}
return false;
- }));
+ });
}
public function testCheckPasswordUidReturn() {
@@ -297,10 +297,10 @@ class User_LDAPTest extends TestCase {
$mapping = $this->createMock(UserMapping::class);
$mapping->expects($this->once())
->method('unmap')
- ->will($this->returnValue(true));
+ ->willReturn(true);
$this->access->expects($this->once())
->method('getUserMapper')
- ->will($this->returnValue($mapping));
+ ->willReturn($mapping);
$this->connection->expects($this->any())
->method('getConnectionResource')
->willReturn('this is an ldap link');
@@ -362,22 +362,22 @@ class User_LDAPTest extends TestCase {
private function prepareAccessForGetUsers() {
$this->access->expects($this->once())
->method('escapeFilterPart')
- ->will($this->returnCallback(function($search) {
+ ->willReturnCallback(function($search) {
return $search;
- }));
+ });
$this->access->expects($this->any())
->method('getFilterPartForUserSearch')
- ->will($this->returnCallback(function($search) {
+ ->willReturnCallback(function($search) {
return $search;
- }));
+ });
$this->access->expects($this->any())
->method('combineFilterWithAnd')
- ->will($this->returnCallback(function($param) {
+ ->willReturnCallback(function($param) {
return $param[2];
- }));
+ });
$this->access->expects($this->any())
->method('fetchListOfUsers')
- ->will($this->returnCallback(function($search, $a, $l, $o) {
+ ->willReturnCallback(function($search, $a, $l, $o) {
$users = array('gunslinger', 'newyorker', 'ladyofshadows');
if(empty($search)) {
$result = $users;
@@ -393,10 +393,10 @@ class User_LDAPTest extends TestCase {
$result = array_slice($result, $o, $l);
}
return $result;
- }));
+ });
$this->access->expects($this->any())
->method('nextcloudUserNames')
- ->will($this->returnArgument(0));
+ ->willReturnArgument(0);
$this->access->method('fetchUsersByLoginName')
->willReturn([]);
}
@@ -543,12 +543,12 @@ class User_LDAPTest extends TestCase {
$this->access->expects($this->any())
->method('readAttribute')
- ->will($this->returnCallback(function($dn) {
+ ->willReturnCallback(function($dn) {
if($dn === 'dnOfRoland,dc=test') {
return array();
}
return false;
- }));
+ });
//test for never-existing user
/** @noinspection PhpUnhandledExceptionInspection */
@@ -568,12 +568,12 @@ class User_LDAPTest extends TestCase {
$this->access->expects($this->any())
->method('readAttribute')
- ->will($this->returnCallback(function($dn) {
+ ->willReturnCallback(function($dn) {
if($dn === 'dnOfRoland,dc=test') {
return array();
}
return false;
- }));
+ });
$this->userManager->expects($this->atLeastOnce())
->method('get')
->willReturn($user);
@@ -600,16 +600,16 @@ class User_LDAPTest extends TestCase {
$this->connection->expects($this->any())
->method('__get')
- ->will($this->returnCallback(function($name) {
+ ->willReturnCallback(function($name) {
if($name === 'homeFolderNamingRule') {
return 'attr:testAttribute';
}
return null;
- }));
+ });
$this->access->expects($this->any())
->method('readAttribute')
- ->will($this->returnCallback(function($dn, $attr) {
+ ->willReturnCallback(function($dn, $attr) {
switch ($dn) {
case 'dnOfRoland,dc=test':
if($attr === 'testAttribute') {
@@ -620,7 +620,7 @@ class User_LDAPTest extends TestCase {
default:
return false;
}
- }));
+ });
$user = $this->createMock(User::class);
$user->expects($this->any())
@@ -652,16 +652,16 @@ class User_LDAPTest extends TestCase {
$this->connection->expects($this->any())
->method('__get')
- ->will($this->returnCallback(function($name) {
+ ->willReturnCallback(function($name) {
if($name === 'homeFolderNamingRule') {
return 'attr:testAttribute';
}
return null;
- }));
+ });
$this->access->expects($this->any())
->method('readAttribute')
- ->will($this->returnCallback(function($dn, $attr) {
+ ->willReturnCallback(function($dn, $attr) {
switch ($dn) {
case 'dnOfLadyOfShadows,dc=test':
if($attr === 'testAttribute') {
@@ -672,7 +672,7 @@ class User_LDAPTest extends TestCase {
default:
return false;
}
- }));
+ });
$user = $this->createMock(User::class);
$user->expects($this->any())
@@ -703,20 +703,20 @@ class User_LDAPTest extends TestCase {
$this->connection->expects($this->any())
->method('__get')
- ->will($this->returnCallback(function($name) {
+ ->willReturnCallback(function($name) {
if($name === 'homeFolderNamingRule') {
return 'attr:testAttribute';
}
return null;
- }));
+ });
$this->access->expects($this->any())
->method('readAttribute')
- ->will($this->returnCallback(function($dn, $attr) {
+ ->willReturnCallback(function($dn, $attr) {
switch ($dn) {
default:
return false;
}
- }));
+ });
$this->access->connection->expects($this->any())
->method('getFromCache')
->willReturnCallback(function($key) {
@@ -751,26 +751,26 @@ class User_LDAPTest extends TestCase {
$this->connection->expects($this->any())
->method('__get')
- ->will($this->returnCallback(function($name) {
+ ->willReturnCallback(function($name) {
if($name === 'homeFolderNamingRule') {
return 'attr:testAttribute';
}
return null;
- }));
+ });
$this->access->expects($this->any())
->method('readAttribute')
- ->will($this->returnValue([]));
+ ->willReturn([]);
$userMapper = $this->createMock(UserMapping::class);
$this->access->expects($this->any())
->method('getUserMapper')
- ->will($this->returnValue($userMapper));
+ ->willReturn($userMapper);
$this->config->expects($this->any())
->method('getUserValue')
- ->will($this->returnValue(true));
+ ->willReturn(true);
$offlineUser = $this->createMock(OfflineUser::class);
$offlineUser->expects($this->atLeastOnce())
@@ -797,9 +797,9 @@ class User_LDAPTest extends TestCase {
$this->connection->expects($this->any())
->method('getFromCache')
- ->will($this->returnCallback(function($uid) {
+ ->willReturnCallback(function($uid) {
return true;
- }));
+ });
/** @noinspection PhpUnhandledExceptionInspection */
$this->assertEquals($this->backend->getHome('uid'),'result');
@@ -808,16 +808,16 @@ class User_LDAPTest extends TestCase {
private function prepareAccessForGetDisplayName() {
$this->connection->expects($this->any())
->method('__get')
- ->will($this->returnCallback(function($name) {
+ ->willReturnCallback(function($name) {
if($name === 'ldapUserDisplayName') {
return 'displayname';
}
return null;
- }));
+ });
$this->access->expects($this->any())
->method('readAttribute')
- ->will($this->returnCallback(function($dn, $attr) {
+ ->willReturnCallback(function($dn, $attr) {
switch ($dn) {
case 'dnOfRoland,dc=test':
if($attr === 'displayname') {
@@ -829,7 +829,7 @@ class User_LDAPTest extends TestCase {
default:
return false;
}
- }));
+ });
$this->access->method('fetchUsersByLoginName')
->willReturn([]);
}
@@ -841,9 +841,9 @@ class User_LDAPTest extends TestCase {
$this->connection->expects($this->any())
->method('getConnectionResource')
- ->will($this->returnCallback(function() {
+ ->willReturnCallback(function() {
return true;
- }));
+ });
$user1 = $this->createMock(User::class);
$user1->expects($this->once())
@@ -894,7 +894,7 @@ class User_LDAPTest extends TestCase {
public function testGetDisplayNamePublicAPI() {
$this->access->expects($this->any())
->method('username2dn')
- ->will($this->returnCallback(function($uid) {
+ ->willReturnCallback(function($uid) {
switch ($uid) {
case 'gunslinger':
return 'dnOfRoland,dc=test';
@@ -911,16 +911,16 @@ class User_LDAPTest extends TestCase {
default:
return false;
}
- }));
+ });
$this->prepareAccessForGetDisplayName();
$backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
$this->prepareMockForUserExists();
$this->connection->expects($this->any())
->method('getConnectionResource')
- ->will($this->returnCallback(function() {
+ ->willReturnCallback(function() {
return true;
- }));
+ });
\OC_User::useBackend($backend);
@@ -989,7 +989,7 @@ class User_LDAPTest extends TestCase {
public function testCountUsers() {
$this->access->expects($this->once())
->method('countUsers')
- ->will($this->returnValue(5));
+ ->willReturn(5);
$backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
@@ -1000,7 +1000,7 @@ class User_LDAPTest extends TestCase {
public function testCountUsersFailing() {
$this->access->expects($this->once())
->method('countUsers')
- ->will($this->returnValue(false));
+ ->willReturn(false);
$backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
@@ -1134,7 +1134,7 @@ class User_LDAPTest extends TestCase {
private function prepareAccessForSetPassword($enablePasswordChange = true) {
$this->connection->expects($this->any())
->method('__get')
- ->will($this->returnCallback(function($name) use (&$enablePasswordChange) {
+ ->willReturnCallback(function($name) use (&$enablePasswordChange) {
if($name === 'ldapLoginFilter') {
return '%uid';
}
@@ -1142,48 +1142,48 @@ class User_LDAPTest extends TestCase {
return $enablePasswordChange?1:0;
}
return null;
- }));
+ });
$this->connection->expects($this->any())
->method('getFromCache')
- ->will($this->returnCallback(function($uid) {
+ ->willReturnCallback(function($uid) {
if($uid === 'userExists'.'roland') {
return true;
}
return null;
- }));
+ });
$this->access->expects($this->any())
->method('fetchListOfUsers')
- ->will($this->returnCallback(function($filter) {
+ ->willReturnCallback(function($filter) {
if($filter === 'roland') {
return array(array('dn' => ['dnOfRoland,dc=test']));
}
return array();
- }));
+ });
$this->access->expects($this->any())
->method('fetchUsersByLoginName')
- ->will($this->returnCallback(function($uid) {
+ ->willReturnCallback(function($uid) {
if($uid === 'roland') {
return array(array('dn' => ['dnOfRoland,dc=test']));
}
return array();
- }));
+ });
$this->access->expects($this->any())
->method('dn2username')
->with($this->equalTo('dnOfRoland,dc=test'))
- ->will($this->returnValue('roland'));
+ ->willReturn('roland');
$this->access->expects($this->any())
->method('stringResemblesDN')
->with($this->equalTo('dnOfRoland,dc=test'))
- ->will($this->returnValue(true));
+ ->willReturn(true);
$this->access->expects($this->any())
->method('setPassword')
- ->will($this->returnCallback(function($uid, $password) {
+ ->willReturnCallback(function($uid, $password) {
if(strlen($password) <= 5) {
throw new HintException('Password fails quality checking policy', '', 19);
}
return true;
- }));
+ });
}