Skip to content

Commit

Permalink
Adjust code and add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jvillafanez committed Nov 22, 2023
1 parent f634799 commit d60c4af
Show file tree
Hide file tree
Showing 4 changed files with 555 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/UserSyncLDAPBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ public function __construct(User_Proxy $userProxy) {
$this->userProxy = $userProxy;
}

/**
* Get the pointer's position. This method isn't part of the interface and
* it's expected to be used only for testing
*/
public function getPointer() {
return $this->pointer;
}

/**
* Get the cached user data. This method isn't part of the interface and
* it's expected to be used only for testing
*/
public function getCachedUserData() {
return $this->cachedUserData;
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -97,7 +113,7 @@ public function getNextUser(): ?SyncingUser {
$email = $userEntry->getEMailAddress();
$home = $userEntry->getHome();
$searchTerms = $userEntry->getSearchTerms();
} catch (\Exception $e) {
} catch (\Exception $ex) {
throw new SyncBackendUserFailedException("Can't sync user with dn {$userEntry->getDN()}", 1, $ex);
}

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

Expand Down
11 changes: 11 additions & 0 deletions tests/unit/User/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,17 @@ public function testGetUsersSearchEmptyResult() {
$this->assertCount(0, $result);
}

public function testGetLdapUsers() {
$this->prepareForGetUsers();
$result = $this->manager->getLdapUsers('');
$expected = [
[ 'dn' => ['cn=alice,dc=foobar,dc=bar'] ],
[ 'dn' => ['cn=bob,dc=foobar,dc=bar'] ],
[ 'dn' => ['cn=carol,dc=foobar,dc=bar'] ],
];
$this->assertEquals($expected, $result);
}

public function testGetUserEntryByDn() {
$this->access->expects($this->once())
->method('executeRead')
Expand Down
Loading

0 comments on commit d60c4af

Please sign in to comment.