]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix unit test - optimize code
authorThomas Müller <thomas.mueller@tmit.eu>
Mon, 11 Jan 2016 19:04:33 +0000 (20:04 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Mon, 18 Jan 2016 21:14:30 +0000 (22:14 +0100)
apps/dav/lib/connector/sabre/principal.php
apps/dav/tests/unit/connector/sabre/principal.php

index 583deb3a175beaf977cb984d4ce79eda97a1fca2..5f02d1271dff5c6c8985e934f7256f7ddb0a5ec6 100644 (file)
@@ -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;
        }
+
 }
index c98a7e5699cb72cdbc5ceb1ab5ca1cdfacf77f54..d6bc7cd405f2a86fbefb92b65a39ba0e86032d16 100644 (file)
@@ -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',