Skip to content

Commit d60c4af

Browse files
committed
Adjust code and add unit tests
1 parent f634799 commit d60c4af

File tree

4 files changed

+555
-2
lines changed

4 files changed

+555
-2
lines changed

Diff for: lib/UserSyncLDAPBackend.php

+18-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@ public function __construct(User_Proxy $userProxy) {
4040
$this->userProxy = $userProxy;
4141
}
4242

43+
/**
44+
* Get the pointer's position. This method isn't part of the interface and
45+
* it's expected to be used only for testing
46+
*/
47+
public function getPointer() {
48+
return $this->pointer;
49+
}
50+
51+
/**
52+
* Get the cached user data. This method isn't part of the interface and
53+
* it's expected to be used only for testing
54+
*/
55+
public function getCachedUserData() {
56+
return $this->cachedUserData;
57+
}
58+
4359
/**
4460
* @inheritDoc
4561
*/
@@ -97,7 +113,7 @@ public function getNextUser(): ?SyncingUser {
97113
$email = $userEntry->getEMailAddress();
98114
$home = $userEntry->getHome();
99115
$searchTerms = $userEntry->getSearchTerms();
100-
} catch (\Exception $e) {
116+
} catch (\Exception $ex) {
101117
throw new SyncBackendUserFailedException("Can't sync user with dn {$userEntry->getDN()}", 1, $ex);
102118
}
103119

@@ -141,7 +157,7 @@ public function getSyncingUser(string $id): ?SyncingUser {
141157
$email = $userEntry->getEMailAddress();
142158
$home = $userEntry->getHome();
143159
$searchTerms = $userEntry->getSearchTerms();
144-
} catch (\Exception $e) {
160+
} catch (\Exception $ex) {
145161
throw new SyncBackendUserFailedException("Can't sync user with dn {$userEntry->getDN()}", 1, $ex);
146162
}
147163

Diff for: tests/unit/User/ManagerTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,17 @@ public function testGetUsersSearchEmptyResult() {
330330
$this->assertCount(0, $result);
331331
}
332332

333+
public function testGetLdapUsers() {
334+
$this->prepareForGetUsers();
335+
$result = $this->manager->getLdapUsers('');
336+
$expected = [
337+
[ 'dn' => ['cn=alice,dc=foobar,dc=bar'] ],
338+
[ 'dn' => ['cn=bob,dc=foobar,dc=bar'] ],
339+
[ 'dn' => ['cn=carol,dc=foobar,dc=bar'] ],
340+
];
341+
$this->assertEquals($expected, $result);
342+
}
343+
333344
public function testGetUserEntryByDn() {
334345
$this->access->expects($this->once())
335346
->method('executeRead')

0 commit comments

Comments
 (0)