Skip to content

Commit be83f58

Browse files
committed
Resolved conflicts due to missing changes upstream.
Take particular note of the changes to $roleSlugs. There was a mismatch between the phpdoc, tests, and api docs. This commit went with the array due to both the test and api doc specifying the array type. The php doc was updated to reflect the array change.
1 parent 9d27f92 commit be83f58

File tree

2 files changed

+87
-18
lines changed

2 files changed

+87
-18
lines changed

lib/UserManagement.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,13 @@ public function deleteUser($userId)
222222
* @param string $userId User ID
223223
* @param string $organizationId Organization ID
224224
* @param string|null $roleSlug Role Slug
225-
* @param string|null $roleSlugs Role Slugs
225+
* @param array|null $roleSlugs Role Slugs
226226
*
227227
* @throws Exception\WorkOSException
228228
*
229229
* @return Resource\OrganizationMembership
230230
*/
231-
public function createOrganizationMembership($userId, $organizationId, ?string $roleSlug = null, ?string $roleSlugs = null)
231+
public function createOrganizationMembership($userId, $organizationId, ?string $roleSlug = null, ?array $roleSlugs = null)
232232
{
233233
$path = "user_management/organization_memberships";
234234

@@ -309,13 +309,13 @@ public function deleteOrganizationMembership($organizationMembershipId)
309309
*
310310
* @param string $organizationMembershipId Organization Membership ID
311311
* @param string|null $role_slug The unique slug of the role to grant to this membership.
312-
* @param string|null $role_slugs The unique slugs of the roles to grant to this membership.
312+
* @param array|null $role_slugs The unique slugs of the roles to grant to this membership.
313313
*
314314
* @throws Exception\WorkOSException
315315
*
316316
* @return Resource\OrganizationMembership
317317
*/
318-
public function updateOrganizationMembership($organizationMembershipId, ?string $roleSlug = null, ?string $roleSlugs = null)
318+
public function updateOrganizationMembership($organizationMembershipId, ?string $roleSlug = null, ?array $roleSlugs = null)
319319
{
320320
$path = "user_management/organization_memberships/{$organizationMembershipId}";
321321

tests/WorkOS/UserManagementTest.php

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,35 @@ public function testCreateOrganizationMembershipWithRoleSlugs()
10391039
$this->assertSame($organizationMembership, $response->toArray());
10401040
}
10411041

1042+
public function testCreateOrganizationMembershipWithNullRoleParams()
1043+
{
1044+
$userId = "user_01H7X1M4TZJN5N4HG4XXMA1234";
1045+
$orgId = "org_01EHQMYV6MBK39QC5PZXHY59C3";
1046+
$path = "user_management/organization_memberships";
1047+
1048+
$result = $this->organizationMembershipResponseFixture();
1049+
1050+
// When both roleSlug and roleSlugs are null, neither should be in params
1051+
$params = [
1052+
"organization_id" => $orgId,
1053+
"user_id" => $userId,
1054+
];
1055+
1056+
$this->mockRequest(
1057+
Client::METHOD_POST,
1058+
$path,
1059+
null,
1060+
$params,
1061+
true,
1062+
$result
1063+
);
1064+
1065+
$organizationMembership = $this->organizationMembershipFixture();
1066+
1067+
$response = $this->userManagement->createOrganizationMembership($userId, $orgId, null, null);
1068+
$this->assertSame($organizationMembership, $response->toArray());
1069+
}
1070+
10421071
public function testGetOrganizationMembership()
10431072
{
10441073
$organizationMembershipId = "om_01E4ZCR3C56J083X43JQXF3JK5";
@@ -1207,16 +1236,10 @@ public function testUpdateOrganizationMembership()
12071236
$this->assertSame($this->organizationMembershipFixture(), $response->toArray());
12081237
}
12091238

1210-
<<<<<<< HEAD
12111239
public function testUpdateOrganizationMembershipWithRoleSlugs()
12121240
{
12131241
$organizationMembershipId = "om_01E4ZCR3C56J083X43JQXF3JK5";
12141242
$roleSlugs = ["admin"];
1215-
=======
1216-
public function testUpdateOrganizationMembershipWithNullRoleSlug()
1217-
{
1218-
$organizationMembershipId = "om_01E4ZCR3C56J083X43JQXF3JK5";
1219-
>>>>>>> 560a945 (Fix PHP 8.4 deprecation: Add explicit nullable type hints)
12201243
$path = "user_management/organization_memberships/{$organizationMembershipId}";
12211244

12221245
$result = $this->organizationMembershipResponseFixture();
@@ -1225,27 +1248,36 @@ public function testUpdateOrganizationMembershipWithNullRoleSlug()
12251248
Client::METHOD_PUT,
12261249
$path,
12271250
null,
1228-
<<<<<<< HEAD
12291251
["role_slugs" => $roleSlugs],
1230-
=======
1231-
["role_slug" => null],
1232-
>>>>>>> 560a945 (Fix PHP 8.4 deprecation: Add explicit nullable type hints)
12331252
true,
12341253
$result
12351254
);
12361255

1237-
<<<<<<< HEAD
12381256
$response = $this->userManagement->updateOrganizationMembership($organizationMembershipId, null, $roleSlugs);
12391257
$this->assertSame($this->organizationMembershipFixture(), $response->toArray());
12401258
}
12411259

1260+
public function testUpdateOrganizationMembershipWithNullRoleParams()
1261+
{
1262+
$organizationMembershipId = "om_01E4ZCR3C56J083X43JQXF3JK5";
1263+
$path = "user_management/organization_memberships/{$organizationMembershipId}";
1264+
1265+
$result = $this->organizationMembershipResponseFixture();
1266+
1267+
// When both roleSlug and roleSlugs are null, params should be empty array
1268+
$this->mockRequest(
1269+
Client::METHOD_PUT,
1270+
$path,
1271+
null,
1272+
[],
1273+
true,
1274+
$result
1275+
);
12421276

1243-
=======
1244-
$response = $this->userManagement->updateOrganizationMembership($organizationMembershipId, null);
1277+
$response = $this->userManagement->updateOrganizationMembership($organizationMembershipId, null, null);
12451278
$this->assertSame($this->organizationMembershipFixture(), $response->toArray());
12461279
}
12471280

1248-
>>>>>>> 560a945 (Fix PHP 8.4 deprecation: Add explicit nullable type hints)
12491281
public function testDeactivateOrganizationMembership()
12501282
{
12511283
$organizationMembershipId = "om_01E4ZCR3C56J083X43JQXF3JK5";
@@ -1328,6 +1360,43 @@ public function testSendInvitation()
13281360
$this->assertSame($response->toArray(), $expected);
13291361
}
13301362

1363+
public function testSendInvitationWithNullOptionalParams()
1364+
{
1365+
$path = "user_management/invitations";
1366+
1367+
$result = $this->invitationResponseFixture();
1368+
1369+
// The implementation includes null values in params
1370+
$params = [
1371+
"email" => "[email protected]",
1372+
"organization_id" => null,
1373+
"expires_in_days" => null,
1374+
"inviter_user_id" => null,
1375+
"role_slug" => null
1376+
];
1377+
1378+
$this->mockRequest(
1379+
Client::METHOD_POST,
1380+
$path,
1381+
null,
1382+
$params,
1383+
true,
1384+
$result
1385+
);
1386+
1387+
$response = $this->userManagement->sendInvitation(
1388+
1389+
null,
1390+
null,
1391+
null,
1392+
null
1393+
);
1394+
1395+
$expected = $this->invitationFixture();
1396+
1397+
$this->assertSame($response->toArray(), $expected);
1398+
}
1399+
13311400
public function testGetInvitation()
13321401
{
13331402
$invitationId = "invitation_01E4ZCR3C56J083X43JQXF3JK5";

0 commit comments

Comments
 (0)