Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/Resource/DirectoryUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

namespace WorkOS\Resource;

use WorkOS\Resource\RoleResponse;

/**
* Class DirectoryUser.
*
* @property RoleResponse|null $role
* @property array<RoleResponse>|null $roles
Comment on lines +9 to +11
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other properties need to be added here but didn't want to conflate this PR.

*/
class DirectoryUser extends BaseWorkOSResource
{
Expand Down Expand Up @@ -36,6 +41,8 @@ class DirectoryUser extends BaseWorkOSResource
"jobTitle",
"state",
"idpId",
"role",
"roles",
"groups",
"directoryId",
"organizationId"
Expand All @@ -53,11 +60,32 @@ class DirectoryUser extends BaseWorkOSResource
"job_title" => "jobTitle",
"state" => "state",
"idp_id" => "idpId",
"role" => "role",
"roles" => "roles",
"groups" => "groups",
"directory_id" => "directoryId",
"organization_id" => "organizationId"
];

public static function constructFromResponse($response)
{
$instance = parent::constructFromResponse($response);

if (isset($response["role"])) {
$instance->values["role"] = new RoleResponse($response["role"]["slug"]);
}

if (isset($response["roles"])) {
$roles = [];
foreach ($response["roles"] as $role) {
$roles[] = new RoleResponse($role["slug"]);
}
$instance->values["roles"] = $roles;
}

return $instance;
}

/**
* @deprecated 4.22.0 Use `email` property instead.
*
Expand Down
21 changes: 21 additions & 0 deletions lib/Resource/OrganizationMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace WorkOS\Resource;

use WorkOS\Resource\RoleResponse;

/**
* Class OrganizationMembership.
*
Expand Down Expand Up @@ -42,4 +44,23 @@ class OrganizationMembership extends BaseWorkOSResource
"created_at" => "createdAt",
"updated_at" => "updatedAt"
];

public static function constructFromResponse($response)
{
$instance = parent::constructFromResponse($response);

if (isset($response["role"])) {
$instance->values["role"] = new RoleResponse($response["role"]["slug"]);
}

if (isset($response["roles"])) {
$roles = [];
foreach ($response["roles"] as $role) {
$roles[] = new RoleResponse($role["slug"]);
}
$instance->values["roles"] = $roles;
}

return $instance;
}
}
11 changes: 11 additions & 0 deletions lib/Resource/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* @property string $connectionType
* @property string $idpId
* @property RoleResponse|null $role
* @property array<RoleResponse>|null $roles
* @property array $groups
* @property array $rawAttributes
*/
Expand All @@ -33,6 +34,7 @@ class Profile extends BaseWorkOSResource
"connectionType",
"idpId",
"role",
"roles",
"groups",
"customAttributes",
"rawAttributes"
Expand All @@ -48,6 +50,7 @@ class Profile extends BaseWorkOSResource
"connection_type" => "connectionType",
"idp_id" => "idpId",
"role" => "role",
"roles" => "roles",
"groups" => "groups",
"custom_attributes" => "customAttributes",
"raw_attributes" => "rawAttributes"
Expand All @@ -61,6 +64,14 @@ public static function constructFromResponse($response)
$instance->values["role"] = new RoleResponse($response["role"]["slug"]);
}

if (isset($response["roles"])) {
$roles = [];
foreach ($response["roles"] as $role) {
$roles[] = new RoleResponse($role["slug"]);
}
$instance->values["roles"] = $roles;
}

return $instance;
}
}
33 changes: 31 additions & 2 deletions tests/WorkOS/DirectorySyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace WorkOS;

use PHPUnit\Framework\TestCase;
use WorkOS\Resource\RoleResponse;

class DirectorySyncTest extends TestCase
{
Expand Down Expand Up @@ -143,7 +144,7 @@ public function testGetUser()
$user = $this->ds->getUser($directoryUser);
$userFixture = $this->userFixture();

$this->assertSame($userFixture, $user->toArray());
$this->assertEquals($userFixture, $user->toArray());
}

public function testGetUserPrimaryEmail()
Expand Down Expand Up @@ -214,7 +215,7 @@ public function testListUsers()
$user = $this->userFixture();

list($before, $after, $users) = $this->ds->listUsers();
$this->assertSame($user, $users[0]->toArray());
$this->assertEquals($user, $users[0]->toArray());
}

public function testDeleteDirectory()
Expand Down Expand Up @@ -397,6 +398,14 @@ private function usersResponseFixture()
"custom_attributes" => [
"fullName" => "Yoon Seri"
],
"role" => [
"slug" => "admin"
],
"roles" => [
[
"slug" => "admin"
]
],
"id" => "directory_usr_id"
]
]
Expand Down Expand Up @@ -453,6 +462,14 @@ private function userResponseFixture()
"custom_attributes" => [
"fullName" => "Yoon Seri"
],
"role" => [
"slug" => "admin"
],
"roles" => [
[
"slug" => "admin"
]
],
"id" => "directory_usr_id"
]);
}
Expand Down Expand Up @@ -501,6 +518,14 @@ private function userResponseFixtureNoEmail()
"custom_attributes" => [
"fullName" => "Yoon Seri"
],
"role" => [
"slug" => "admin"
],
"roles" => [
[
"slug" => "admin"
]
],
"id" => "directory_usr_id"
]);
}
Expand Down Expand Up @@ -553,6 +578,10 @@ private function userFixture()
"jobTitle" => "Software Engineer",
"state" => "active",
"idpId" => null,
"role" => new RoleResponse("admin"),
"roles" => [
new RoleResponse("admin"),
],
"groups" => null,
"directoryId" => "dir_123",
"organizationId" => "org_123",
Expand Down
12 changes: 11 additions & 1 deletion tests/WorkOS/SSOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,14 @@ private function profileAndTokenResponseFixture()
"connection_id" => "conn_01EMH8WAK20T42N2NBMNBCYHAG",
"connection_type" => "GoogleOAuth",
"idp_id" => "randomalphanum",
"role" => new RoleResponse("admin"),
"role" => [
"slug" => "admin"
],
"roles" => [
[
"slug" => "admin"
]
],
"groups" => array("Admins", "Developers"),
"custom_attributes" => array("license" => "professional"),
"raw_attributes" => array(
Expand All @@ -251,6 +258,9 @@ private function profileFixture()
"connectionType" => "GoogleOAuth",
"idpId" => "randomalphanum",
"role" => new RoleResponse("admin"),
"roles" => [
new RoleResponse("admin"),
],
"groups" => array("Admins", "Developers"),
"customAttributes" => array("license" => "professional"),
"rawAttributes" => array(
Expand Down
29 changes: 13 additions & 16 deletions tests/WorkOS/UserManagementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use WorkOS\Resource\RoleResponse;

class UserManagementTest extends TestCase
{
Expand Down Expand Up @@ -914,7 +915,7 @@ public function testCreateOrganizationMembership()

$response = $this->userManagement->createOrganizationMembership($userId, $orgId, $roleSlug);

$this->assertSame($organizationMembership, $response->toArray());
$this->assertEquals($organizationMembership, $response->toArray());
}

public function testCreateOrganizationMembershipWithRoleSlugs()
Expand Down Expand Up @@ -945,7 +946,7 @@ public function testCreateOrganizationMembershipWithRoleSlugs()

$response = $this->userManagement->createOrganizationMembership($userId, $orgId, null, $roleSlugs);

$this->assertSame($organizationMembership, $response->toArray());
$this->assertEquals($organizationMembership, $response->toArray());
}

public function testGetOrganizationMembership()
Expand All @@ -968,7 +969,7 @@ public function testGetOrganizationMembership()

$response = $this->userManagement->getOrganizationMembership($organizationMembershipId);

$this->assertSame($organizationMembership, $response->toArray());
$this->assertEquals($organizationMembership, $response->toArray());
}

public function testListOrganizationMemberships()
Expand Down Expand Up @@ -1002,7 +1003,7 @@ public function testListOrganizationMemberships()

list($before, $after, $organizationMemberships) = $this->userManagement->listOrganizationMemberships($userId, $orgId);

$this->assertSame($organizationMembership, $organizationMemberships[0]->toArray());
$this->assertEquals($organizationMembership, $organizationMemberships[0]->toArray());
}

public function testListOrganizationMembershipsWithStatuses()
Expand Down Expand Up @@ -1037,7 +1038,7 @@ public function testListOrganizationMembershipsWithStatuses()

list($before, $after, $organizationMemberships) = $this->userManagement->listOrganizationMemberships($userId, $orgId, $statuses);

$this->assertSame($organizationMembership, $organizationMemberships[0]->toArray());
$this->assertEquals($organizationMembership, $organizationMemberships[0]->toArray());
}

public function testListOrganizationMembershipsWithStatus()
Expand Down Expand Up @@ -1072,7 +1073,7 @@ public function testListOrganizationMembershipsWithStatus()

list($before, $after, $organizationMemberships) = $this->userManagement->listOrganizationMemberships($userId, $orgId, $statuses);

$this->assertSame($organizationMembership, $organizationMemberships[0]->toArray());
$this->assertEquals($organizationMembership, $organizationMemberships[0]->toArray());
}

public function testDeleteOrganizationMembership()
Expand Down Expand Up @@ -1113,7 +1114,7 @@ public function testUpdateOrganizationMembership()
);

$response = $this->userManagement->updateOrganizationMembership($organizationMembershipId, $roleSlug);
$this->assertSame($this->organizationMembershipFixture(), $response->toArray());
$this->assertEquals($this->organizationMembershipFixture(), $response->toArray());
}

public function testUpdateOrganizationMembershipWithRoleSlugs()
Expand All @@ -1134,7 +1135,7 @@ public function testUpdateOrganizationMembershipWithRoleSlugs()
);

$response = $this->userManagement->updateOrganizationMembership($organizationMembershipId, null, $roleSlugs);
$this->assertSame($this->organizationMembershipFixture(), $response->toArray());
$this->assertEquals($this->organizationMembershipFixture(), $response->toArray());
}


Expand All @@ -1158,7 +1159,7 @@ public function testDeactivateOrganizationMembership()

$response = $this->userManagement->deactivateOrganizationMembership($organizationMembershipId);

$this->assertSame(array_merge($organizationMembership, array("status" => "inactive")), $response->toArray());
$this->assertEquals(array_merge($organizationMembership, array("status" => "inactive")), $response->toArray());
}

public function testReactivateOrganizationMembership()
Expand All @@ -1181,7 +1182,7 @@ public function testReactivateOrganizationMembership()

$response = $this->userManagement->reactivateOrganizationMembership($organizationMembershipId);

$this->assertSame($organizationMembership, $response->toArray());
$this->assertEquals($organizationMembership, $response->toArray());
}

public function testSendInvitation()
Expand Down Expand Up @@ -1610,13 +1611,9 @@ private function organizationMembershipFixture()
"id" => "om_01E4ZCR3C56J083X43JQXF3JK5",
"userId" => "user_01H7X1M4TZJN5N4HG4XXMA1234",
"organizationId" => "org_01EHQMYV6MBK39QC5PZXHY59C3",
"role" => [
"slug" => "admin",
],
"role" => new RoleResponse("admin"),
"roles" => [
[
"slug" => "admin",
],
new RoleResponse("admin"),
],
"status" => "active",
"createdAt" => "2021-06-25T19:07:33.155Z",
Expand Down