Skip to content

Commit b6894cd

Browse files
authored
Merge pull request #152 from fschmtt/update-roles-endpoint
feat: add Roles::update endpoint
2 parents d43dbbe + d9545ff commit b6894cd

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/Resource/Roles.php

+15
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,19 @@ public function delete(string $realm, string $roleName): void
6868
),
6969
);
7070
}
71+
72+
public function update(string $realm, Role $role): void
73+
{
74+
$this->commandExecutor->executeCommand(
75+
new Command(
76+
'/admin/realms/{realm}/roles/{roleName}',
77+
Method::PUT,
78+
[
79+
'realm' => $realm,
80+
'roleName' => $role->getName(),
81+
],
82+
$role,
83+
),
84+
);
85+
}
7186
}

tests/Integration/Resource/RolesTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class RolesTest extends TestCase
1414
{
1515
use IntegrationTestBehaviour;
1616

17-
public function testCreateRetrieveDeleteRole(): void
17+
public function testCreateRetrieveUpdateDeleteRole(): void
1818
{
1919
$resource = $this->getKeycloak()->roles();
2020

@@ -41,6 +41,9 @@ public function testCreateRetrieveDeleteRole(): void
4141
$role = $resource->get('master', 'test-role');
4242
static::assertSame('test-role', $role->getName());
4343

44+
// Update (created) role
45+
$resource->update('master', $role->withDescription('updated-test-role-description'));
46+
4447
// Delete (created) role
4548
$resource->delete('master', 'test-role');
4649

tests/Unit/Resource/RolesTest.php

+30
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,34 @@ public function testDeleteRole(): void
134134

135135
$roles->delete('test-realm', $deletedRoleName);
136136
}
137+
138+
public function testUpdateRole(): void
139+
{
140+
$updatedRole = new Role(name: 'updated-role');
141+
$updatedRoleName = $updatedRole->getName();
142+
143+
static::assertIsString($updatedRoleName);
144+
145+
$command = new Command(
146+
'/admin/realms/{realm}/roles/{roleName}',
147+
Method::PUT,
148+
[
149+
'realm' => 'test-realm',
150+
'roleName' => $updatedRoleName,
151+
],
152+
$updatedRole,
153+
);
154+
155+
$commandExecutor = $this->createMock(CommandExecutor::class);
156+
$commandExecutor->expects(static::once())
157+
->method('executeCommand')
158+
->with($command);
159+
160+
$roles = new Roles(
161+
$commandExecutor,
162+
$this->createMock(QueryExecutor::class),
163+
);
164+
165+
$roles->update('test-realm', $updatedRole);
166+
}
137167
}

0 commit comments

Comments
 (0)