Skip to content

Commit

Permalink
test(php): Add more dependencies for UserService and specify MockObje…
Browse files Browse the repository at this point in the history
…ct type
  • Loading branch information
zak39 committed Nov 13, 2024
1 parent 4eb0f3c commit 71bb9bc
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions tests/Unit/Service/UserServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,31 @@

namespace OCA\Workspace\Tests\Unit\Service;

use OCA\Workspace\Service\Group\ConnectedGroupsService;
use OCA\Workspace\Service\Group\ManagersWorkspace;
use OCA\Workspace\Service\UserService;
use OCA\Workspace\Service\WorkspaceService;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use PHPUnit\Framework\MockObject\MockObject;

class UserServiceTest extends TestCase {
private IGroupManager $groupManager;
private IUser $user;
private IUserSession $userSession;
private LoggerInterface $logger;
private WorkspaceService $workspaceService;
private MockObject&IGroupManager $groupManager;
private MockObject&IUser $user;
private MockObject&IUserSession $userSession;
private MockObject&LoggerInterface $logger;
private MockObject&ConnectedGroupsService $connectedGroupService;
private MockObject&IURLGenerator $urlGenerator;

public function setUp(): void {
$this->groupManager = $this->createMock(IGroupManager::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->workspaceService = $this->createMock(WorkspaceService::class);
$this->connectedGroupService = $this->createMock(ConnectedGroupsService::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);

// Sets up the user'session
$this->userSession = $this->createMock(IUserSession::class);
Expand All @@ -55,7 +59,7 @@ public function setUp(): void {
->willReturn($this->user);
}

private function createTestUser($id, $name, $email): IUser {
private function createTestUser($id, $name, $email): MockObject&IUser {
$mockUser = $this->createMock(IUser::class);
$mockUser->expects($this->any())
->method('getUID')
Expand All @@ -69,7 +73,7 @@ private function createTestUser($id, $name, $email): IUser {
return $mockUser;
}

private function createTestGroup($id, $name, $users): IGroup {
private function createTestGroup($id, $name, $users): MockObject&IGroup {
$mockGroup = $this->createMock(IGroup::class);
$mockGroup->expects($this->any())
->method('getGID')
Expand Down Expand Up @@ -103,7 +107,9 @@ public function testIsUserGeneralAdmin(): void {
$userService = new UserService(
$this->groupManager,
$this->userSession,
$this->logger);
$this->logger,
$this->connectedGroupService,
$this->urlGenerator);

// Runs the method to be tested
$result = $userService->isUserGeneralAdmin();
Expand Down Expand Up @@ -131,7 +137,9 @@ public function testIsNotUserGeneralAdmin(): void {
$userService = new UserService(
$this->groupManager,
$this->userSession,
$this->logger);
$this->logger,
$this->connectedGroupService,
$this->urlGenerator);

// Runs the method to be tested
$result = $userService->isUserGeneralAdmin();
Expand Down Expand Up @@ -160,7 +168,9 @@ public function testIsSpaceManager(): void {
$userService = new UserService(
$this->groupManager,
$this->userSession,
$this->logger);
$this->logger,
$this->connectedGroupService,
$this->urlGenerator);

$this->userSession->expects($this->once())
->method('getUser')
Expand Down Expand Up @@ -199,7 +209,9 @@ public function testIsNotSpaceManager(): void {
$userService = new UserService(
$this->groupManager,
$this->userSession,
$this->logger);
$this->logger,
$this->connectedGroupService,
$this->urlGenerator);

// Runs the method to be tested
$result = $userService->isSpaceManager();
Expand Down Expand Up @@ -228,7 +240,9 @@ public function testIsNotSpaceManagerOfSpace(): void {
$userService = new UserService(
$this->groupManager,
$this->userSession,
$this->logger);
$this->logger,
$this->connectedGroupService,
$this->urlGenerator);

// Runs the method to be tested
$result = $userService->isSpaceManagerOfSpace([
Expand Down Expand Up @@ -262,7 +276,9 @@ public function testIsSpaceManagerOfSpace(): void {
$userService = new UserService(
$this->groupManager,
$this->userSession,
$this->logger);
$this->logger,
$this->connectedGroupService,
$this->urlGenerator);

// Runs the method to be tested
$result = $userService->isSpaceManagerOfSpace([
Expand Down

0 comments on commit 71bb9bc

Please sign in to comment.