diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-11 20:04:33 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-18 22:14:30 +0100 |
commit | 992ccc899a325360f6da703c490ca608a00a78d5 (patch) | |
tree | d665ca90d55ec69719e5e34e2e343b2c0c0e0102 | |
parent | 8b8edc1f5dbe27cbeaf9935aa175037fdf6d0c1c (diff) | |
download | nextcloud-server-992ccc899a325360f6da703c490ca608a00a78d5.tar.gz nextcloud-server-992ccc899a325360f6da703c490ca608a00a78d5.zip |
Fix unit test - optimize code
-rw-r--r-- | apps/dav/lib/connector/sabre/principal.php | 6 | ||||
-rw-r--r-- | apps/dav/tests/unit/connector/sabre/principal.php | 16 |
2 files changed, 11 insertions, 11 deletions
diff --git a/apps/dav/lib/connector/sabre/principal.php b/apps/dav/lib/connector/sabre/principal.php index 583deb3a175..5f02d1271df 100644 --- a/apps/dav/lib/connector/sabre/principal.php +++ b/apps/dav/lib/connector/sabre/principal.php @@ -133,12 +133,11 @@ class Principal implements BackendInterface { list($prefix, $name) = URLUtil::splitPath($principal); if ($prefix === 'principals/users') { - $principal = $this->getPrincipalByPath($principal); - if (!$principal) { + $user = $this->userManager->get($name); + if (!$user) { throw new Exception('Principal not found'); } - $user = $this->userManager->get($name); $groups = $this->groupManager->getUserGroups($user); $groups = array_map(function($group) { /** @var IGroup $group */ @@ -212,4 +211,5 @@ class Principal implements BackendInterface { } return $principal; } + } diff --git a/apps/dav/tests/unit/connector/sabre/principal.php b/apps/dav/tests/unit/connector/sabre/principal.php index c98a7e5699c..d6bc7cd405f 100644 --- a/apps/dav/tests/unit/connector/sabre/principal.php +++ b/apps/dav/tests/unit/connector/sabre/principal.php @@ -26,13 +26,14 @@ namespace OCA\DAV\Tests\Unit\Connector\Sabre; use OCP\IGroupManager; use \Sabre\DAV\PropPatch; use OCP\IUserManager; +use Test\TestCase; -class Principal extends \Test\TestCase { - /** @var IUserManager */ +class Principal extends TestCase { + /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */ private $userManager; /** @var \OCA\DAV\Connector\Sabre\Principal */ private $connector; - /** @var IGroupManager */ + /** @var IGroupManager | \PHPUnit_Framework_MockObject_MockObject */ private $groupManager; public function setUp() { @@ -201,15 +202,14 @@ class Principal extends \Test\TestCase { public function testGetGroupMembership() { $fooUser = $this->getMockBuilder('\OC\User\User') ->disableOriginalConstructor()->getMock(); - $fooUser - ->expects($this->exactly(1)) - ->method('getUID') - ->will($this->returnValue('foo')); $this->userManager ->expects($this->once()) ->method('get') ->with('foo') - ->will($this->returnValue($fooUser)); + ->willReturn($fooUser); + $this->groupManager + ->method('getUserGroups') + ->willReturn([]); $expectedResponse = [ 'principals/users/foo/calendar-proxy-read', |