From: Thomas Müller Date: Mon, 11 Jan 2016 19:04:33 +0000 (+0100) Subject: Fix unit test - optimize code X-Git-Tag: v9.0beta1~249^2~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=992ccc899a325360f6da703c490ca608a00a78d5;p=nextcloud-server.git Fix unit test - optimize code --- 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',