Skip to content

Commit 4b59401

Browse files
committed
chore: add unit tests for Groups::byPath and Groups::members
1 parent a87e3d8 commit 4b59401

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

src/Resource/Groups.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public function byPath(string $realm, string $path = ''): Group
3737
[
3838
'realm' => $realm,
3939
'path' => $path,
40-
]
41-
)
40+
],
41+
),
4242
);
4343
}
4444

@@ -67,8 +67,8 @@ public function members(string $realm, string $groupId, ?Criteria $criteria = nu
6767
'realm' => $realm,
6868
'groupId' => $groupId,
6969
],
70-
$criteria
71-
)
70+
$criteria,
71+
),
7272
);
7373
}
7474

tests/Integration/Resource/GroupsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function testCreateChildGroup(): void
7979
static::assertSame($childGroupName, $childGroup->getName());
8080

8181
// get child group by path
82-
$pathGroup = $groups->byPath('master', $importedGroupName.'/'.$childGroupName);
82+
$pathGroup = $groups->byPath('master', $importedGroupName . '/' . $childGroupName);
8383
static::assertInstanceOf(Group::class, $pathGroup);
8484
static::assertSame($childGroup->getId(), $pathGroup->getId());
8585
}

tests/Unit/Resource/GroupsTest.php

+54
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
namespace Fschmtt\Keycloak\Test\Unit\Resource;
66

77
use Fschmtt\Keycloak\Collection\GroupCollection;
8+
use Fschmtt\Keycloak\Collection\UserCollection;
89
use Fschmtt\Keycloak\Http\Command;
910
use Fschmtt\Keycloak\Http\CommandExecutor;
1011
use Fschmtt\Keycloak\Http\Method;
1112
use Fschmtt\Keycloak\Http\Query;
1213
use Fschmtt\Keycloak\Http\QueryExecutor;
1314
use Fschmtt\Keycloak\Representation\Group;
15+
use Fschmtt\Keycloak\Representation\User;
1416
use Fschmtt\Keycloak\Resource\Groups;
1517
use PHPUnit\Framework\Attributes\CoversClass;
1618
use PHPUnit\Framework\TestCase;
@@ -214,4 +216,56 @@ public function testDeleteGroup(): void
214216

215217
$groups->delete('realm-with-groups', $group->getId());
216218
}
219+
220+
public function testByPath(): void
221+
{
222+
$query = new Query(
223+
'/admin/realms/{realm}/group-by-path/{path}',
224+
Group::class,
225+
[
226+
'realm' => 'realm-with-groups',
227+
'path' => 'path/to/group',
228+
],
229+
);
230+
231+
$queryExecutor = $this->createMock(QueryExecutor::class);
232+
$queryExecutor->expects(static::once())
233+
->method('executeQuery')
234+
->with($query)
235+
->willReturn(new Group(id: 'group-1'));
236+
237+
$groups = new Groups(
238+
$this->createMock(CommandExecutor::class),
239+
$queryExecutor,
240+
);
241+
242+
$group = $groups->byPath('realm-with-groups', 'path/to/group');
243+
static::assertSame('group-1', $group->getId());
244+
}
245+
246+
public function testMembers(): void
247+
{
248+
$query = new Query(
249+
'/admin/realms/{realm}/groups/{groupId}/members',
250+
UserCollection::class,
251+
[
252+
'realm' => 'realm-with-groups',
253+
'groupId' => 'group-1',
254+
],
255+
);
256+
257+
$queryExecutor = $this->createMock(QueryExecutor::class);
258+
$queryExecutor->expects(static::once())
259+
->method('executeQuery')
260+
->with($query)
261+
->willReturn(new UserCollection([new User(id: 'user-1')]));
262+
263+
$groups = new Groups(
264+
$this->createMock(CommandExecutor::class),
265+
$queryExecutor,
266+
);
267+
268+
$members = $groups->members('realm-with-groups', 'group-1');
269+
static::assertCount(1, $members);
270+
}
217271
}

0 commit comments

Comments
 (0)