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
29 changes: 9 additions & 20 deletions lib/RBAC.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,33 +183,22 @@ public function createEnvironmentRole(
/**
* List Environment Roles.
*
* @param int $limit Maximum number of records to return
* @param null|string $before Role ID to look before
* @param null|string $after Role ID to look after
* @param null|string $order The order in which to paginate records
*
* @throws Exception\WorkOSException
*
* @return Resource\PaginatedResource
* @return Resource\Role[]
*/
public function listEnvironmentRoles(
int $limit = self::DEFAULT_PAGE_SIZE,
?string $before = null,
?string $after = null,
?string $order = null
) {
public function listEnvironmentRoles()
{
$path = "authorization/roles";

$params = [
"limit" => $limit,
"before" => $before,
"after" => $after,
"order" => $order,
];
$response = Client::request(Client::METHOD_GET, $path, null, null, true);

$response = Client::request(Client::METHOD_GET, $path, null, $params, true);
$roles = [];
foreach ($response["data"] as $responseData) {
\array_push($roles, Resource\Role::constructFromResponse($responseData));
}

return Resource\PaginatedResource::constructFromResponse($response, Resource\Role::class, 'roles');
return $roles;
}

/**
Expand Down
17 changes: 3 additions & 14 deletions tests/WorkOS/RBACTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,19 @@ public function testListEnvironmentRoles()

$result = $this->rolesListResponseFixture();

$params = [
"limit" => RBAC::DEFAULT_PAGE_SIZE,
"before" => null,
"after" => null,
"order" => null,
];

$this->mockRequest(
Client::METHOD_GET,
$path,
null,
$params,
null,
true,
$result
);

$role = $this->roleFixture();

$response = $this->rbac->listEnvironmentRoles();
$this->assertSame($role, $response->roles[0]->toArray());
$roles = $this->rbac->listEnvironmentRoles();
$this->assertSame($role, $roles[0]->toArray());
}

public function testGetEnvironmentRole()
Expand Down Expand Up @@ -552,10 +545,6 @@ private function rolesListResponseFixture()
"created_at" => "2024-01-01T00:00:00.000Z",
"updated_at" => "2024-01-01T00:00:00.000Z"
]
],
"list_metadata" => [
"before" => null,
"after" => null
]
]);
}
Expand Down